mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 20:13:32 +01:00
debt - lift a few service implementations from platform to workbench
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
export class BrowserClipboardService implements IClipboardService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private _internalResourcesClipboard: URI[] | undefined;
|
||||
|
||||
async writeText(text: string, type?: string): Promise<void> {
|
||||
if (type) {
|
||||
return; // TODO@sbatten
|
||||
}
|
||||
|
||||
return navigator.clipboard.writeText(text);
|
||||
}
|
||||
|
||||
async readText(type?: string): Promise<string> {
|
||||
if (type) {
|
||||
return ''; // TODO@sbatten
|
||||
}
|
||||
|
||||
return navigator.clipboard.readText();
|
||||
}
|
||||
|
||||
readTextSync(): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
readFindText(): string {
|
||||
// @ts-ignore
|
||||
return undefined;
|
||||
}
|
||||
|
||||
writeFindText(text: string): void { }
|
||||
|
||||
writeResources(resources: URI[]): void {
|
||||
this._internalResourcesClipboard = resources;
|
||||
}
|
||||
|
||||
readResources(): URI[] {
|
||||
return this._internalResourcesClipboard || [];
|
||||
}
|
||||
|
||||
hasResources(): boolean {
|
||||
return this._internalResourcesClipboard !== undefined && this._internalResourcesClipboard.length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IClipboardService, BrowserClipboardService, true);
|
||||
@@ -0,0 +1,80 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { clipboard } from 'electron';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { isMacintosh } from 'vs/base/common/platform';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
|
||||
export class NativeClipboardService implements IClipboardService {
|
||||
|
||||
private static FILE_FORMAT = 'code/file-list'; // Clipboard format for files
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
async writeText(text: string, type?: 'selection' | 'clipboard'): Promise<void> {
|
||||
clipboard.writeText(text, type);
|
||||
}
|
||||
|
||||
async readText(type?: 'selection' | 'clipboard'): Promise<string> {
|
||||
return clipboard.readText(type);
|
||||
}
|
||||
|
||||
readTextSync(): string {
|
||||
return clipboard.readText();
|
||||
}
|
||||
|
||||
readFindText(): string {
|
||||
if (isMacintosh) {
|
||||
return clipboard.readFindText();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
writeFindText(text: string): void {
|
||||
if (isMacintosh) {
|
||||
clipboard.writeFindText(text);
|
||||
}
|
||||
}
|
||||
|
||||
writeResources(resources: URI[]): void {
|
||||
if (resources.length) {
|
||||
clipboard.writeBuffer(NativeClipboardService.FILE_FORMAT, this.resourcesToBuffer(resources));
|
||||
}
|
||||
}
|
||||
|
||||
readResources(): URI[] {
|
||||
return this.bufferToResources(clipboard.readBuffer(NativeClipboardService.FILE_FORMAT));
|
||||
}
|
||||
|
||||
hasResources(): boolean {
|
||||
return clipboard.has(NativeClipboardService.FILE_FORMAT);
|
||||
}
|
||||
|
||||
private resourcesToBuffer(resources: URI[]): Buffer {
|
||||
return Buffer.from(resources.map(r => r.toString()).join('\n'));
|
||||
}
|
||||
|
||||
private bufferToResources(buffer: Buffer): URI[] {
|
||||
if (!buffer) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const bufferValue = buffer.toString();
|
||||
if (!bufferValue) {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
return bufferValue.split('\n').map(f => URI.parse(f));
|
||||
} catch (error) {
|
||||
return []; // do not trust clipboard data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IClipboardService, NativeClipboardService, true);
|
||||
@@ -0,0 +1,20 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IIssueService } from 'vs/platform/issue/node/issue';
|
||||
import { IMainProcessService } from 'vs/platform/ipc/electron-browser/mainProcessService';
|
||||
import { createChannelSender } from 'vs/base/parts/ipc/node/ipc';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
|
||||
export class IssueService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
constructor(@IMainProcessService mainProcessService: IMainProcessService) {
|
||||
return createChannelSender<IIssueService>(mainProcessService.getChannel('issue'));
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IIssueService, IssueService, true);
|
||||
@@ -19,4 +19,4 @@ export class LocalizationsService {
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(ILocalizationsService, LocalizationsService);
|
||||
registerSingleton(ILocalizationsService, LocalizationsService, true);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IMenubarService } from 'vs/platform/menubar/node/menubar';
|
||||
import { IMainProcessService } from 'vs/platform/ipc/electron-browser/mainProcessService';
|
||||
import { createChannelSender } from 'vs/base/parts/ipc/node/ipc';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
|
||||
export class MenubarService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
constructor(@IMainProcessService mainProcessService: IMainProcessService) {
|
||||
return createChannelSender<IMenubarService>(mainProcessService.getChannel('menubar'));
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IMenubarService, MenubarService, true);
|
||||
@@ -24,7 +24,7 @@ export interface IUpdateProvider {
|
||||
checkForUpdate(): Promise<IUpdate | null>;
|
||||
}
|
||||
|
||||
export class UpdateService extends Disposable implements IUpdateService {
|
||||
export class BrowserUpdateService extends Disposable implements IUpdateService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
@@ -92,4 +92,4 @@ export class UpdateService extends Disposable implements IUpdateService {
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IUpdateService, UpdateService);
|
||||
registerSingleton(IUpdateService, BrowserUpdateService);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { IUpdateService, State } from 'vs/platform/update/common/update';
|
||||
import { IMainProcessService } from 'vs/platform/ipc/electron-browser/mainProcessService';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
|
||||
export class NativeUpdateService implements IUpdateService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private readonly _onStateChange = new Emitter<State>();
|
||||
readonly onStateChange: Event<State> = this._onStateChange.event;
|
||||
|
||||
private _state: State = State.Uninitialized;
|
||||
get state(): State { return this._state; }
|
||||
|
||||
private channel: IChannel;
|
||||
|
||||
constructor(@IMainProcessService mainProcessService: IMainProcessService) {
|
||||
this.channel = mainProcessService.getChannel('update');
|
||||
|
||||
// always set this._state as the state changes
|
||||
this.onStateChange(state => this._state = state);
|
||||
|
||||
this.channel.call<State>('_getInitialState').then(state => {
|
||||
// fire initial state
|
||||
this._onStateChange.fire(state);
|
||||
|
||||
// fire subsequent states as they come in from remote
|
||||
|
||||
this.channel.listen<State>('onStateChange')(state => this._onStateChange.fire(state));
|
||||
});
|
||||
}
|
||||
|
||||
checkForUpdates(context: any): Promise<void> {
|
||||
return this.channel.call('checkForUpdates', context);
|
||||
}
|
||||
|
||||
downloadUpdate(): Promise<void> {
|
||||
return this.channel.call('downloadUpdate');
|
||||
}
|
||||
|
||||
applyUpdate(): Promise<void> {
|
||||
return this.channel.call('applyUpdate');
|
||||
}
|
||||
|
||||
quitAndInstall(): Promise<void> {
|
||||
return this.channel.call('quitAndInstall');
|
||||
}
|
||||
|
||||
isLatestVersion(): Promise<boolean> {
|
||||
return this.channel.call('isLatestVersion');
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IUpdateService, NativeUpdateService);
|
||||
@@ -57,21 +57,10 @@ import 'vs/workbench/services/lifecycle/electron-browser/lifecycleService';
|
||||
import 'vs/workbench/services/sharedProcess/electron-browser/sharedProcessService';
|
||||
import 'vs/workbench/services/electron/electron-browser/electronService';
|
||||
import 'vs/workbench/services/localizations/electron-browser/localizationsService';
|
||||
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { ClipboardService } from 'vs/platform/clipboard/electron-browser/clipboardService';
|
||||
import { IUpdateService } from 'vs/platform/update/common/update';
|
||||
import { UpdateService } from 'vs/platform/update/electron-browser/updateService';
|
||||
import { IIssueService } from 'vs/platform/issue/node/issue';
|
||||
import { IssueService } from 'vs/platform/issue/electron-browser/issueService';
|
||||
import { IMenubarService } from 'vs/platform/menubar/node/menubar';
|
||||
import { MenubarService } from 'vs/platform/menubar/electron-browser/menubarService';
|
||||
|
||||
registerSingleton(IClipboardService, ClipboardService, true);
|
||||
registerSingleton(IUpdateService, UpdateService);
|
||||
registerSingleton(IIssueService, IssueService);
|
||||
registerSingleton(IMenubarService, MenubarService);
|
||||
import 'vs/workbench/services/clipboard/electron-browser/clipboardService';
|
||||
import 'vs/workbench/services/update/electron-browser/updateService';
|
||||
import 'vs/workbench/services/issue/electron-browser/issueService';
|
||||
import 'vs/workbench/services/menubar/electron-browser/menubarService';
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
@@ -47,10 +47,9 @@ import 'vs/workbench/services/dialogs/browser/fileDialogService';
|
||||
import 'vs/workbench/services/host/browser/browserHostService';
|
||||
import 'vs/workbench/services/request/browser/requestService';
|
||||
import 'vs/workbench/services/lifecycle/browser/lifecycleService';
|
||||
import 'vs/workbench/services/clipboard/browser/clipboardService';
|
||||
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { BrowserClipboardService } from 'vs/platform/clipboard/browser/clipboardService';
|
||||
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
|
||||
import { BrowserAccessibilityService } from 'vs/platform/accessibility/common/accessibilityService';
|
||||
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
|
||||
@@ -70,7 +69,6 @@ import { UserDataSyncService } from 'vs/platform/userDataSync/common/userDataSyn
|
||||
|
||||
registerSingleton(IExtensionManagementService, ExtensionManagementService);
|
||||
registerSingleton(IBackupFileService, BackupFileService);
|
||||
registerSingleton(IClipboardService, BrowserClipboardService, true);
|
||||
registerSingleton(IAccessibilityService, BrowserAccessibilityService, true);
|
||||
registerSingleton(IContextMenuService, ContextMenuService);
|
||||
registerSingleton(ITunnelService, NoOpTunnelService, true);
|
||||
|
||||
Reference in New Issue
Block a user