提交 5ede377c 编写于 作者: B Benjamin Pasero

debt - clean up event names in native host

上级 c21e1b7e
......@@ -663,7 +663,11 @@ export class CodeApplication extends Disposable {
});
// Create a URL handler which forwards to the last active window
const activeWindowManager = new ActiveWindowManager({ onWindowOpen: nativeHostMainService.onWindowOpen, onWindowFocus: nativeHostMainService.onWindowFocus, getActiveWindowId: () => nativeHostMainService.getActiveWindowId(-1) });
const activeWindowManager = new ActiveWindowManager({
onDidOpenWindow: nativeHostMainService.onDidOpenWindow,
onDidFocusWindow: nativeHostMainService.onDidFocusWindow,
getActiveWindowId: () => nativeHostMainService.getActiveWindowId(-1)
});
const activeWindowRouter = new StaticRouter(ctx => activeWindowManager.getActiveClientId().then(id => ctx === id));
const urlHandlerRouter = new URLHandlerRouter(activeWindowRouter);
const urlHandlerChannel = electronIpcServer.getChannel('urlHandler', urlHandlerRouter);
......
......@@ -169,8 +169,8 @@ export class Menubar {
// // Listen to some events from window service to update menu
this.windowsMainService.onWindowsCountChanged(e => this.onWindowsCountChanged(e));
this.nativeHostMainService.onWindowBlur(() => this.onWindowFocusChange());
this.nativeHostMainService.onWindowFocus(() => this.onWindowFocusChange());
this.nativeHostMainService.onDidBlurWindow(() => this.onWindowFocusChange());
this.nativeHostMainService.onDidFocusWindow(() => this.onWindowFocusChange());
}
private get currentEnableMenuBarMnemonics(): boolean {
......
......@@ -37,17 +37,19 @@ export interface ICommonNativeHostService {
readonly windowId: number;
// Events
readonly onWindowOpen: Event<number>;
readonly onDidOpenWindow: Event<number>;
readonly onWindowMaximize: Event<number>;
readonly onWindowUnmaximize: Event<number>;
readonly onDidMaximizeWindow: Event<number>;
readonly onDidUnmaximizeWindow: Event<number>;
readonly onWindowFocus: Event<number>;
readonly onWindowBlur: Event<number>;
readonly onDidFocusWindow: Event<number>;
readonly onDidBlurWindow: Event<number>;
readonly onOSResume: Event<unknown>;
readonly onDidResumeOS: Event<unknown>;
readonly onColorSchemeChange: Event<IColorScheme>;
readonly onDidChangeColorScheme: Event<IColorScheme>;
readonly onDidChangePassword: Event<void>;
// Window
getWindows(): Promise<IOpenedWindow[]>;
......@@ -149,5 +151,4 @@ export interface ICommonNativeHostService {
deletePassword(service: string, account: string): Promise<boolean>;
findPassword(service: string): Promise<string | null>;
findCredentials(service: string): Promise<Array<{ account: string, password: string }>>
readonly onDidChangePassword: Event<void>;
}
......@@ -27,6 +27,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { dirname, join } from 'vs/base/common/path';
import product from 'vs/platform/product/common/product';
import { memoize } from 'vs/base/common/decorators';
import { Disposable } from 'vs/base/common/lifecycle';
export interface INativeHostMainService extends AddFirstParameterToFunctions<ICommonNativeHostService, Promise<unknown> /* only methods, not events */, number | undefined /* window ID */> { }
......@@ -40,7 +41,7 @@ interface ChunkedPassword {
const MAX_PASSWORD_LENGTH = 2500;
const PASSWORD_CHUNK_SIZE = MAX_PASSWORD_LENGTH - 100;
export class NativeHostMainService implements INativeHostMainService {
export class NativeHostMainService extends Disposable implements INativeHostMainService {
declare readonly _serviceBrand: undefined;
......@@ -52,6 +53,8 @@ export class NativeHostMainService implements INativeHostMainService {
@ITelemetryService private readonly telemetryService: ITelemetryService,
@ILogService private readonly logService: ILogService
) {
super();
this.registerListeners();
}
......@@ -59,7 +62,7 @@ export class NativeHostMainService implements INativeHostMainService {
// Color Scheme changes
nativeTheme.on('updated', () => {
this._onColorSchemeChange.fire({
this._onDidChangeColorScheme.fire({
highContrast: nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors,
dark: nativeTheme.shouldUseDarkColors
});
......@@ -75,23 +78,23 @@ export class NativeHostMainService implements INativeHostMainService {
//#region Events
readonly onWindowOpen = Event.map(this.windowsMainService.onWindowOpened, window => window.id);
readonly onDidOpenWindow = Event.map(this.windowsMainService.onWindowOpened, window => window.id);
readonly onWindowMaximize = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-maximize', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
readonly onWindowUnmaximize = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-unmaximize', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
readonly onDidMaximizeWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-maximize', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
readonly onDidUnmaximizeWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-unmaximize', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
readonly onWindowBlur = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-blur', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
readonly onWindowFocus = Event.any(
readonly onDidBlurWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-blur', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
readonly onDidFocusWindow = Event.any(
Event.map(Event.filter(Event.map(this.windowsMainService.onWindowsCountChanged, () => this.windowsMainService.getLastActiveWindow()), window => !!window), window => window!.id),
Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-focus', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId))
);
readonly onOSResume = Event.fromNodeEventEmitter(powerMonitor, 'resume');
readonly onDidResumeOS = Event.fromNodeEventEmitter(powerMonitor, 'resume');
private readonly _onColorSchemeChange = new Emitter<IColorScheme>();
readonly onColorSchemeChange = this._onColorSchemeChange.event;
private readonly _onDidChangeColorScheme = this._register(new Emitter<IColorScheme>());
readonly onDidChangeColorScheme = this._onDidChangeColorScheme.event;
private readonly _onDidChangePassword = new Emitter<void>();
private readonly _onDidChangePassword = this._register(new Emitter<void>());
readonly onDidChangePassword = this._onDidChangePassword.event;
//#endregion
......@@ -688,11 +691,12 @@ export class NativeHostMainService implements INativeHostMainService {
async deletePassword(windowId: number | undefined, service: string, account: string): Promise<boolean> {
const keytar = await import('keytar');
const didDelete = await keytar.deletePassword(service, account);
if (didDelete) {
this._onDidChangePassword.fire();
}
return didDelete;
}
......
......@@ -31,8 +31,8 @@ export class UserDataAutoSyncService extends BaseUserDataAutoSyncService {
super(userDataSyncStoreManagementService, userDataSyncStoreService, userDataSyncResourceEnablementService, userDataSyncService, logService, authTokenService, telemetryService, userDataSyncMachinesService, storageService, environmentService);
this._register(Event.debounce<string, string[]>(Event.any<string>(
Event.map(nativeHostService.onWindowFocus, () => 'windowFocus'),
Event.map(nativeHostService.onWindowOpen, () => 'windowOpen'),
Event.map(nativeHostService.onDidFocusWindow, () => 'windowFocus'),
Event.map(nativeHostService.onDidOpenWindow, () => 'windowOpen'),
), (last, source) => last ? [...last, source] : [source], 1000)(sources => this.triggerSync(sources, true, false)));
}
......
......@@ -14,13 +14,15 @@ export class ActiveWindowManager extends Disposable {
private activeWindowId: number | undefined;
constructor({ onWindowOpen, onWindowFocus, getActiveWindowId }: {
onWindowOpen: Event<number>, onWindowFocus: Event<number>, getActiveWindowId(): Promise<number | undefined>
constructor({ onDidOpenWindow, onDidFocusWindow, getActiveWindowId }: {
onDidOpenWindow: Event<number>,
onDidFocusWindow: Event<number>,
getActiveWindowId(): Promise<number | undefined>
}) {
super();
// remember last active window id upon events
const onActiveWindowChange = Event.latch(Event.any(onWindowOpen, onWindowFocus));
const onActiveWindowChange = Event.latch(Event.any(onDidOpenWindow, onDidFocusWindow));
onActiveWindowChange(this.setActiveWindow, this, this.disposables);
// resolve current active window
......
......@@ -18,7 +18,7 @@ class SleepResumeRepaintMinimap extends Disposable implements IWorkbenchContribu
) {
super();
this._register(nativeHostService.onOSResume(() => {
this._register(nativeHostService.onDidResumeOS(() => {
codeEditorService.listCodeEditors().forEach(editor => editor.render(true));
}));
}
......
......@@ -31,7 +31,7 @@ export class TerminalNativeContribution extends Disposable implements IWorkbench
super();
ipcRenderer.on('vscode:openFiles', (_: unknown, request: INativeOpenFileRequest) => this._onOpenFileRequest(request));
this._register(nativeHostService.onOSResume(() => this._onOsResume()));
this._register(nativeHostService.onDidResumeOS(() => this._onOsResume()));
this._terminalService.setLinuxDistro(linuxDistro);
this._terminalService.setNativeWindowsDelegate({
......
......@@ -261,8 +261,8 @@ export class NativeWindow extends Disposable {
// Detect minimize / maximize
this._register(Event.any(
Event.map(Event.filter(this.nativeHostService.onWindowMaximize, id => id === this.nativeHostService.windowId), () => true),
Event.map(Event.filter(this.nativeHostService.onWindowUnmaximize, id => id === this.nativeHostService.windowId), () => false)
Event.map(Event.filter(this.nativeHostService.onDidMaximizeWindow, id => id === this.nativeHostService.windowId), () => true),
Event.map(Event.filter(this.nativeHostService.onDidUnmaximizeWindow, id => id === this.nativeHostService.windowId), () => false)
)(e => this.onDidChangeMaximized(e)));
this.onDidChangeMaximized(this.environmentService.configuration.maximized ?? false);
......
......@@ -7,17 +7,20 @@ import { ICredentialsService, ICredentialsProvider } from 'vs/workbench/services
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
export class BrowserCredentialsService implements ICredentialsService {
export class BrowserCredentialsService extends Disposable implements ICredentialsService {
declare readonly _serviceBrand: undefined;
private _onDidChangePassword: Emitter<void> = new Emitter();
private _onDidChangePassword = this._register(new Emitter<void>());
readonly onDidChangePassword = this._onDidChangePassword.event;
private credentialsProvider: ICredentialsProvider;
constructor(@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService) {
super();
if (environmentService.options && environmentService.options.credentialsProvider) {
this.credentialsProvider = environmentService.options.credentialsProvider;
} else {
......@@ -31,6 +34,7 @@ export class BrowserCredentialsService implements ICredentialsService {
async setPassword(service: string, account: string, password: string): Promise<void> {
await this.credentialsProvider.setPassword(service, account, password);
this._onDidChangePassword.fire();
}
......
......@@ -7,16 +7,23 @@ import { ICredentialsService } from 'vs/workbench/services/credentials/common/cr
import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
export class KeytarCredentialsService implements ICredentialsService {
export class KeytarCredentialsService extends Disposable implements ICredentialsService {
declare readonly _serviceBrand: undefined;
private _onDidChangePassword: Emitter<void> = new Emitter();
onDidChangePassword = this._onDidChangePassword.event;
private _onDidChangePassword: Emitter<void> = this._register(new Emitter());
readonly onDidChangePassword = this._onDidChangePassword.event;
constructor(@INativeHostService private readonly nativeHostService: INativeHostService) {
this.nativeHostService.onDidChangePassword(event => this._onDidChangePassword.fire(event));
super();
this.registerListeners();
}
private registerListeners(): void {
this._register(this.nativeHostService.onDidChangePassword(event => this._onDidChangePassword.fire(event)));
}
getPassword(service: string, account: string): Promise<string | null> {
......
......@@ -28,8 +28,8 @@ export class NativeHostService extends Disposable implements IHostService {
get onDidChangeFocus(): Event<boolean> { return this._onDidChangeFocus; }
private _onDidChangeFocus: Event<boolean> = Event.latch(Event.any(
Event.map(Event.filter(this.nativeHostService.onWindowFocus, id => id === this.nativeHostService.windowId), () => this.hasFocus),
Event.map(Event.filter(this.nativeHostService.onWindowBlur, id => id === this.nativeHostService.windowId), () => this.hasFocus)
Event.map(Event.filter(this.nativeHostService.onDidFocusWindow, id => id === this.nativeHostService.windowId), () => this.hasFocus),
Event.map(Event.filter(this.nativeHostService.onDidBlurWindow, id => id === this.nativeHostService.windowId), () => this.hasFocus)
));
get hasFocus(): boolean {
......
......@@ -26,7 +26,7 @@ export class NativeHostColorSchemeService extends Disposable implements IHostCol
private registerListeners(): void {
// Color Scheme
this._register(this.nativeHostService.onColorSchemeChange(({ highContrast, dark }) => {
this._register(this.nativeHostService.onDidChangeColorScheme(({ highContrast, dark }) => {
this.dark = dark;
this.highContrast = highContrast;
this._onDidChangeColorScheme.fire();
......
......@@ -160,13 +160,13 @@ export class TestNativeHostService implements INativeHostService {
readonly windowId = -1;
onWindowOpen: Event<number> = Event.None;
onWindowMaximize: Event<number> = Event.None;
onWindowUnmaximize: Event<number> = Event.None;
onWindowFocus: Event<number> = Event.None;
onWindowBlur: Event<number> = Event.None;
onOSResume: Event<unknown> = Event.None;
onColorSchemeChange = Event.None;
onDidOpenWindow: Event<number> = Event.None;
onDidMaximizeWindow: Event<number> = Event.None;
onDidUnmaximizeWindow: Event<number> = Event.None;
onDidFocusWindow: Event<number> = Event.None;
onDidBlurWindow: Event<number> = Event.None;
onDidResumeOS: Event<unknown> = Event.None;
onDidChangeColorScheme = Event.None;
onDidChangePassword = Event.None;
windowCount = Promise.resolve(1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册