Set platform based on server (#32)
* Set platform based on server Had to refactor a bit to ensure our values get set before VS Code tries to use them. * Pave the way for mnemonics on all platforms * Fix context menus on Mac * Fix a bunch of things on Mac including menu bar * Set keybindings based on client's OS
This commit is contained in:
@@ -3,7 +3,7 @@ import * as environment from "vs/platform/environment/node/environmentService";
|
||||
|
||||
export class EnvironmentService extends environment.EnvironmentService {
|
||||
public get sharedIPCHandle(): string {
|
||||
return paths._paths.socketPath || super.sharedIPCHandle;
|
||||
return paths.getSocketPath() || super.sharedIPCHandle;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
10
packages/vscode/src/fill/labels.ts
Normal file
10
packages/vscode/src/fill/labels.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import * as labels from "vs/base/common/labels";
|
||||
|
||||
// Here we simply disable translation of mnemonics and leave everything as &&.
|
||||
// Since we're in the browser, we can handle all platforms in the same way.
|
||||
const target = labels as typeof labels;
|
||||
target.mnemonicMenuLabel = (label: string, forceDisable?: boolean): string => {
|
||||
return forceDisable ? label.replace(/\(&&\w\)|&&/g, "") : label;
|
||||
};
|
||||
target.mnemonicButtonLabel = (label: string): string => { return label; };
|
||||
target.unmnemonicLabel = (label: string): string => { return label; };
|
||||
@@ -4,7 +4,7 @@ import { TERMINAL_COMMAND_ID } from "vs/workbench/parts/terminal/common/terminal
|
||||
import { ITerminalService } from "vs/workbench/parts/terminal/common/terminal";
|
||||
import * as actions from "vs/workbench/parts/terminal/electron-browser/terminalActions";
|
||||
import * as instance from "vs/workbench/parts/terminal/electron-browser/terminalInstance";
|
||||
import { clipboard } from "@coder/ide";
|
||||
import { client } from "../client";
|
||||
|
||||
const getLabel = (key: string, enabled: boolean): string => {
|
||||
return enabled
|
||||
@@ -18,13 +18,13 @@ export class PasteAction extends Action {
|
||||
public constructor() {
|
||||
super(
|
||||
"editor.action.clipboardPasteAction",
|
||||
getLabel(PasteAction.KEY, clipboard.isEnabled),
|
||||
getLabel(PasteAction.KEY, client.clipboard.isEnabled),
|
||||
undefined,
|
||||
clipboard.isEnabled,
|
||||
async (): Promise<boolean> => clipboard.paste(),
|
||||
client.clipboard.isEnabled,
|
||||
async (): Promise<boolean> => client.clipboard.paste(),
|
||||
);
|
||||
|
||||
clipboard.onPermissionChange((enabled) => {
|
||||
client.clipboard.onPermissionChange((enabled) => {
|
||||
this.label = getLabel(PasteAction.KEY, enabled);
|
||||
this.enabled = enabled;
|
||||
});
|
||||
@@ -36,17 +36,17 @@ class TerminalPasteAction extends Action {
|
||||
|
||||
public static readonly ID = TERMINAL_COMMAND_ID.PASTE;
|
||||
public static readonly LABEL = nls.localize("workbench.action.terminal.paste", "Paste into Active Terminal");
|
||||
public static readonly SHORT_LABEL = getLabel(TerminalPasteAction.KEY, clipboard.isEnabled);
|
||||
public static readonly SHORT_LABEL = getLabel(TerminalPasteAction.KEY, client.clipboard.isEnabled);
|
||||
|
||||
public constructor(
|
||||
id: string, label: string,
|
||||
@ITerminalService private terminalService: ITerminalService,
|
||||
) {
|
||||
super(id, label);
|
||||
clipboard.onPermissionChange((enabled) => {
|
||||
client.clipboard.onPermissionChange((enabled) => {
|
||||
this._setLabel(getLabel(TerminalPasteAction.KEY, enabled));
|
||||
});
|
||||
this._setLabel(getLabel(TerminalPasteAction.KEY, clipboard.isEnabled));
|
||||
this._setLabel(getLabel(TerminalPasteAction.KEY, client.clipboard.isEnabled));
|
||||
}
|
||||
|
||||
public run(): Promise<void> {
|
||||
@@ -63,8 +63,8 @@ class TerminalPasteAction extends Action {
|
||||
class TerminalInstance extends instance.TerminalInstance {
|
||||
public async paste(): Promise<void> {
|
||||
this.focus();
|
||||
if (clipboard.isEnabled) {
|
||||
const text = await clipboard.readText();
|
||||
if (client.clipboard.isEnabled) {
|
||||
const text = await client.clipboard.readText();
|
||||
this.sendText(text, false);
|
||||
} else {
|
||||
document.execCommand("paste");
|
||||
|
||||
@@ -4,6 +4,8 @@ class Paths {
|
||||
private _appData: string | undefined;
|
||||
private _defaultUserData: string | undefined;
|
||||
private _socketPath: string | undefined;
|
||||
private _builtInExtensionsDirectory: string | undefined;
|
||||
private _workingDirectory: string | undefined;
|
||||
|
||||
public get appData(): string {
|
||||
if (typeof this._appData === "undefined") {
|
||||
@@ -29,14 +31,35 @@ class Paths {
|
||||
return this._socketPath;
|
||||
}
|
||||
|
||||
public get builtInExtensionsDirectory(): string {
|
||||
if (!this._builtInExtensionsDirectory) {
|
||||
throw new Error("trying to access builtin extensions directory before it has been set");
|
||||
}
|
||||
|
||||
return this._builtInExtensionsDirectory;
|
||||
}
|
||||
|
||||
public get workingDirectory(): string {
|
||||
if (!this._workingDirectory) {
|
||||
throw new Error("trying to access working directory before it has been set");
|
||||
}
|
||||
|
||||
return this._workingDirectory;
|
||||
}
|
||||
|
||||
public initialize(data: InitData, sharedData: SharedProcessData): void {
|
||||
process.env.VSCODE_LOGS = sharedData.logPath;
|
||||
this._appData = data.dataDirectory;
|
||||
this._defaultUserData = data.dataDirectory;
|
||||
this._socketPath = sharedData.socketPath;
|
||||
this._builtInExtensionsDirectory = data.builtInExtensionsDirectory;
|
||||
this._workingDirectory = data.workingDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
export const _paths = new Paths();
|
||||
export const getAppDataPath = (): string => _paths.appData;
|
||||
export const getDefaultUserDataPath = (): string => _paths.defaultUserData;
|
||||
export const getWorkingDirectory = (): string => _paths.workingDirectory;
|
||||
export const getBuiltInExtensionsDirectory = (): string => _paths.builtInExtensionsDirectory;
|
||||
export const getSocketPath = (): string => _paths.socketPath;
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
import * as os from "os";
|
||||
import * as platform from "vs/base/common/platform";
|
||||
|
||||
// tslint:disable no-any to override const
|
||||
|
||||
// Use en instead of en-US since that's vscode default and it uses
|
||||
// that to determine whether to output aliases which will be redundant.
|
||||
if (platform.locale === "en-US") {
|
||||
// tslint:disable-next-line no-any to override const
|
||||
(platform as any).locale = "en";
|
||||
}
|
||||
if (platform.language === "en-US") {
|
||||
// tslint:disable-next-line no-any to override const
|
||||
(platform as any).language = "en";
|
||||
}
|
||||
|
||||
// Use the server's platform instead of the client's. For example, this affects
|
||||
// how VS Code handles paths (and more) because different platforms give
|
||||
// different results. We'll have to counter for things that shouldn't change,
|
||||
// like keybindings.
|
||||
(platform as any).isLinux = os.platform() === "linux";
|
||||
(platform as any).isWindows = os.platform() === "win32";
|
||||
(platform as any).isMacintosh = os.platform() === "darwin";
|
||||
|
||||
// This is used for keybindings, and in one place to choose between \r\n and \n
|
||||
// (which we change to use platform.isWindows instead).
|
||||
(platform as any).OS = (platform.isMacintosh ? platform.OperatingSystem.Macintosh : (platform.isWindows ? platform.OperatingSystem.Windows : platform.OperatingSystem.Linux));
|
||||
|
||||
@@ -2,13 +2,13 @@ import { readFile, writeFile, mkdir } from "fs";
|
||||
import * as path from "path";
|
||||
import { promisify } from "util";
|
||||
import { IDisposable } from "@coder/disposable";
|
||||
import { logger, field } from "@coder/logger";
|
||||
import { Event } from "vs/base/common/event";
|
||||
import * as workspaceStorage from "vs/base/node/storage";
|
||||
import * as globalStorage from "vs/platform/storage/node/storageIpc";
|
||||
import * as paths from "./paths";
|
||||
import { logger, field } from "@coder/logger";
|
||||
import { client } from "@coder/vscode/src/client";
|
||||
import { IStorageService, WillSaveStateReason } from "vs/platform/storage/common/storage";
|
||||
import * as paths from "./paths";
|
||||
import { workbench } from "../workbench";
|
||||
|
||||
class StorageDatabase implements workspaceStorage.IStorageDatabase {
|
||||
public readonly onDidChangeItemsExternal = Event.None;
|
||||
@@ -80,7 +80,7 @@ class StorageDatabase implements workspaceStorage.IStorageDatabase {
|
||||
|
||||
private triggerFlush(reason: WillSaveStateReason = WillSaveStateReason.NONE): boolean {
|
||||
// tslint:disable-next-line:no-any
|
||||
const storageService = client.serviceCollection.get<IStorageService>(IStorageService) as any;
|
||||
const storageService = workbench.serviceCollection.get<IStorageService>(IStorageService) as any;
|
||||
if (reason === WillSaveStateReason.SHUTDOWN && storageService.close) {
|
||||
storageService.close();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import { IRecentlyOpened } from "vs/platform/history/common/history";
|
||||
import { ISerializableCommandAction } from "vs/platform/actions/common/actions";
|
||||
import { client } from "../client";
|
||||
import { showOpenDialog } from "../dialog";
|
||||
import { workbench } from "../workbench";
|
||||
|
||||
/**
|
||||
* Instead of going to the shared process, we'll directly run these methods on
|
||||
@@ -79,7 +80,7 @@ class WindowsService implements IWindowsService {
|
||||
openDirectory: true,
|
||||
},
|
||||
}).then((path) => {
|
||||
client.workspace = URI.file(path);
|
||||
workbench.workspace = URI.file(path);
|
||||
}).catch((ex) => {
|
||||
//
|
||||
});
|
||||
@@ -150,12 +151,12 @@ class WindowsService implements IWindowsService {
|
||||
|
||||
public enterWorkspace(_windowId: number, _path: URI): Promise<IEnterWorkspaceResult> {
|
||||
if (_path.path.endsWith(".json")) {
|
||||
client.workspace = {
|
||||
workbench.workspace = {
|
||||
id: "Untitled",
|
||||
configPath: _path.path,
|
||||
};
|
||||
} else {
|
||||
client.workspace = _path;
|
||||
workbench.workspace = _path;
|
||||
}
|
||||
|
||||
return undefined!;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ToggleDevToolsAction } from "vs/workbench/electron-browser/actions/deve
|
||||
import { TerminalPasteAction } from "vs/workbench/parts/terminal/electron-browser/terminalActions";
|
||||
import { KEYBINDING_CONTEXT_TERMINAL_FOCUS } from "vs/workbench/parts/terminal/common/terminal";
|
||||
import { KeyCode, KeyMod } from "vs/base/common/keyCodes";
|
||||
import { client } from "../client";
|
||||
import { workbench } from "../workbench";
|
||||
|
||||
// Intercept adding workbench actions so we can skip actions that won't work or
|
||||
// modify actions that need different conditions, keybindings, etc.
|
||||
@@ -32,7 +32,7 @@ registry.registerWorkbenchAction = (descriptor: SyncActionDescriptor, alias: str
|
||||
mac: { primary: 0 },
|
||||
};
|
||||
// tslint:disable-next-line no-any override private
|
||||
(descriptor as any)._keybindingContext = ContextKeyExpr.and(KEYBINDING_CONTEXT_TERMINAL_FOCUS, client.clipboardContextKey);
|
||||
(descriptor as any)._keybindingContext = ContextKeyExpr.and(KEYBINDING_CONTEXT_TERMINAL_FOCUS, workbench.clipboardContextKey);
|
||||
}
|
||||
|
||||
return originalRegister(descriptor, alias, category, when);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ILogService } from "vs/platform/log/common/log";
|
||||
import { IWorkspaceFolderCreationData, IWorkspaceIdentifier, IWorkspacesService } from "vs/platform/workspaces/common/workspaces";
|
||||
import { WorkspacesMainService } from "vs/platform/workspaces/electron-main/workspacesMainService";
|
||||
import * as workspacesIpc from "vs/platform/workspaces/node/workspacesIpc";
|
||||
import { client } from "../client";
|
||||
import { workbench } from "../workbench";
|
||||
|
||||
/**
|
||||
* Instead of going to the shared process, we'll directly run these methods on
|
||||
@@ -16,8 +16,8 @@ class WorkspacesService implements IWorkspacesService {
|
||||
|
||||
public createUntitledWorkspace(folders?: IWorkspaceFolderCreationData[] | undefined): Promise<IWorkspaceIdentifier> {
|
||||
const mainService = new WorkspacesMainService(
|
||||
client.serviceCollection.get<IEnvironmentService>(IEnvironmentService) as IEnvironmentService,
|
||||
client.serviceCollection.get<ILogService>(ILogService) as ILogService,
|
||||
workbench.serviceCollection.get<IEnvironmentService>(IEnvironmentService) as IEnvironmentService,
|
||||
workbench.serviceCollection.get<ILogService>(ILogService) as ILogService,
|
||||
);
|
||||
|
||||
// lib/vscode/src/vs/platform/workspaces/node/workspacesIpc.ts
|
||||
|
||||
Reference in New Issue
Block a user