mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-07 07:16:41 +01:00
debt - getActiveWindowId is electron only
This commit is contained in:
@@ -26,7 +26,8 @@ import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProper
|
||||
import { TelemetryAppenderChannel } from 'vs/platform/telemetry/node/telemetryIpc';
|
||||
import { TelemetryService, ITelemetryServiceConfig } from 'vs/platform/telemetry/common/telemetryService';
|
||||
import { AppInsightsAppender } from 'vs/platform/telemetry/node/appInsightsAppender';
|
||||
import { IWindowsService, ActiveWindowManager } from 'vs/platform/windows/common/windows';
|
||||
import { ActiveWindowManager } from 'vs/platform/windows/node/windows';
|
||||
import { IWindowsService } from 'vs/platform/windows/common/windows';
|
||||
import { WindowsService } from 'vs/platform/windows/electron-browser/windowsService';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
import { app, ipcMain as ipc, systemPreferences, shell, Event, contentTracing, protocol, powerMonitor, IpcMainEvent } from 'electron';
|
||||
import { IProcessEnvironment, isWindows, isMacintosh } from 'vs/base/common/platform';
|
||||
import { WindowsManager } from 'vs/code/electron-main/windows';
|
||||
import { IWindowsService, OpenContext, ActiveWindowManager, IWindowOpenable } from 'vs/platform/windows/common/windows';
|
||||
import { IWindowsService, OpenContext, IWindowOpenable } from 'vs/platform/windows/common/windows';
|
||||
import { ActiveWindowManager } from 'vs/platform/windows/node/windows';
|
||||
import { WindowsChannel } from 'vs/platform/windows/common/windowsIpc';
|
||||
import { LegacyWindowsMainService } from 'vs/platform/windows/electron-main/legacyWindowsMainService';
|
||||
import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
|
||||
|
||||
@@ -12,10 +12,8 @@ import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platf
|
||||
import { IRecentlyOpened, IRecent } from 'vs/platform/history/common/history';
|
||||
import { ExportData } from 'vs/base/common/performance';
|
||||
import { LogLevel } from 'vs/platform/log/common/log';
|
||||
import { DisposableStore, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
|
||||
|
||||
export const IWindowsService = createDecorator<IWindowsService>('windowsService');
|
||||
|
||||
@@ -44,8 +42,6 @@ export interface IWindowsService {
|
||||
clearRecentlyOpened(): Promise<void>;
|
||||
getRecentlyOpened(windowId: number): Promise<IRecentlyOpened>;
|
||||
isFocused(windowId: number): Promise<boolean>;
|
||||
|
||||
getActiveWindowId(): Promise<number | undefined>;
|
||||
}
|
||||
|
||||
export const IWindowService = createDecorator<IWindowService>('windowService');
|
||||
@@ -315,37 +311,3 @@ export interface IRunActionInWindowRequest {
|
||||
export interface IRunKeybindingInWindowRequest {
|
||||
userSettingsLabel: string;
|
||||
}
|
||||
|
||||
export class ActiveWindowManager extends Disposable {
|
||||
|
||||
private readonly disposables = this._register(new DisposableStore());
|
||||
private firstActiveWindowIdPromise: CancelablePromise<number | undefined> | undefined;
|
||||
private activeWindowId: number | undefined;
|
||||
|
||||
constructor(@IWindowsService windowsService: IWindowsService) {
|
||||
super();
|
||||
|
||||
const onActiveWindowChange = Event.latch(Event.any(windowsService.onWindowOpen, windowsService.onWindowFocus));
|
||||
onActiveWindowChange(this.setActiveWindow, this, this.disposables);
|
||||
|
||||
this.firstActiveWindowIdPromise = createCancelablePromise(_ => windowsService.getActiveWindowId());
|
||||
this.firstActiveWindowIdPromise
|
||||
.then(id => this.activeWindowId = typeof this.activeWindowId === 'number' ? this.activeWindowId : id)
|
||||
.finally(this.firstActiveWindowIdPromise = undefined);
|
||||
}
|
||||
|
||||
private setActiveWindow(windowId: number | undefined) {
|
||||
if (this.firstActiveWindowIdPromise) {
|
||||
this.firstActiveWindowIdPromise.cancel();
|
||||
this.firstActiveWindowIdPromise = undefined;
|
||||
}
|
||||
|
||||
this.activeWindowId = windowId;
|
||||
}
|
||||
|
||||
async getActiveClientId(): Promise<string | undefined> {
|
||||
const id = this.firstActiveWindowIdPromise ? (await this.firstActiveWindowIdPromise) : this.activeWindowId;
|
||||
|
||||
return `window:${id}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ export class WindowsChannel implements IServerChannel {
|
||||
case 'getRecentlyOpened': return this.service.getRecentlyOpened(arg);
|
||||
case 'isFocused': return this.service.isFocused(arg);
|
||||
case 'openExtensionDevelopmentHostWindow': return (this.service as any).openExtensionDevelopmentHostWindow(arg[0], arg[1]); // TODO@Isidor move
|
||||
case 'getActiveWindowId': return this.service.getActiveWindowId();
|
||||
}
|
||||
|
||||
throw new Error(`Call not found: ${command}`);
|
||||
|
||||
@@ -57,8 +57,4 @@ export class WindowsService implements IWindowsService {
|
||||
openExtensionDevelopmentHostWindow(args: ParsedArgs, env: IProcessEnvironment): Promise<void> {
|
||||
return this.channel.call('openExtensionDevelopmentHostWindow', [args, env]);
|
||||
}
|
||||
|
||||
getActiveWindowId(): Promise<number | undefined> {
|
||||
return this.channel.call('getActiveWindowId');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IWindowsService, OpenContext } from 'vs/platform/windows/common/windows';
|
||||
@@ -23,10 +23,6 @@ export class LegacyWindowsMainService extends Disposable implements IWindowsServ
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private readonly disposables = this._register(new DisposableStore());
|
||||
|
||||
private _activeWindowId: number | undefined;
|
||||
|
||||
readonly onWindowOpen: Event<number> = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-created', (_, w: BrowserWindow) => w.id), id => !!this.windowsMainService.getWindowById(id));
|
||||
readonly onWindowBlur: Event<number> = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-blur', (_, w: BrowserWindow) => w.id), id => !!this.windowsMainService.getWindowById(id));
|
||||
readonly onWindowMaximize: Event<number> = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-maximize', (_, w: BrowserWindow) => w.id), id => !!this.windowsMainService.getWindowById(id));
|
||||
@@ -48,10 +44,6 @@ export class LegacyWindowsMainService extends Disposable implements IWindowsServ
|
||||
super();
|
||||
|
||||
urlService.registerHandler(this);
|
||||
|
||||
// remember last active window id
|
||||
Event.latch(Event.any(this.onWindowOpen, this.onWindowFocus))
|
||||
(id => this._activeWindowId = id, null, this.disposables);
|
||||
}
|
||||
|
||||
async addRecentlyOpened(recents: IRecent[]): Promise<void> {
|
||||
@@ -96,10 +88,6 @@ export class LegacyWindowsMainService extends Disposable implements IWindowsServ
|
||||
}
|
||||
}
|
||||
|
||||
async getActiveWindowId(): Promise<number | undefined> {
|
||||
return this._activeWindowId;
|
||||
}
|
||||
|
||||
async handleURL(uri: URI): Promise<boolean> {
|
||||
|
||||
// Catch file URLs
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { DisposableStore, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
|
||||
import { IWindowsService } from 'vs/platform/windows/common/windows';
|
||||
|
||||
export class ActiveWindowManager extends Disposable {
|
||||
|
||||
private readonly disposables = this._register(new DisposableStore());
|
||||
private firstActiveWindowIdPromise: CancelablePromise<number | undefined> | undefined;
|
||||
|
||||
private activeWindowId: number | undefined;
|
||||
private _activeWindowId: number | undefined;
|
||||
|
||||
constructor(@IWindowsService windowsService: IWindowsService) {
|
||||
super();
|
||||
|
||||
// remember last active window id
|
||||
Event.latch(Event.any(windowsService.onWindowOpen, windowsService.onWindowFocus))(id => this._activeWindowId = id, null, this.disposables);
|
||||
|
||||
const onActiveWindowChange = Event.latch(Event.any(windowsService.onWindowOpen, windowsService.onWindowFocus));
|
||||
onActiveWindowChange(this.setActiveWindow, this, this.disposables);
|
||||
|
||||
this.firstActiveWindowIdPromise = createCancelablePromise(_ => this.getActiveWindowId());
|
||||
this.firstActiveWindowIdPromise
|
||||
.then(id => this.activeWindowId = typeof this.activeWindowId === 'number' ? this.activeWindowId : id)
|
||||
.finally(this.firstActiveWindowIdPromise = undefined);
|
||||
}
|
||||
|
||||
private setActiveWindow(windowId: number | undefined) {
|
||||
if (this.firstActiveWindowIdPromise) {
|
||||
this.firstActiveWindowIdPromise.cancel();
|
||||
this.firstActiveWindowIdPromise = undefined;
|
||||
}
|
||||
|
||||
this.activeWindowId = windowId;
|
||||
}
|
||||
|
||||
async getActiveClientId(): Promise<string | undefined> {
|
||||
const id = this.firstActiveWindowIdPromise ? (await this.firstActiveWindowIdPromise) : this.activeWindowId;
|
||||
|
||||
return `window:${id}`;
|
||||
}
|
||||
|
||||
private async getActiveWindowId(): Promise<number | undefined> {
|
||||
return this._activeWindowId;
|
||||
}
|
||||
}
|
||||
@@ -165,10 +165,6 @@ export class SimpleWindowsService implements IWindowsService {
|
||||
files: []
|
||||
});
|
||||
}
|
||||
|
||||
getActiveWindowId(): Promise<number | undefined> {
|
||||
return Promise.resolve(0);
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IWindowsService, SimpleWindowsService);
|
||||
|
||||
@@ -27,7 +27,7 @@ import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { FalseContext } from 'vs/platform/contextkey/common/contextkeys';
|
||||
import { ShowCurrentReleaseNotesActionId } from 'vs/workbench/contrib/update/common/update';
|
||||
import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows';
|
||||
import { IWindowService } from 'vs/platform/windows/common/windows';
|
||||
import { IProductService } from 'vs/platform/product/common/productService';
|
||||
|
||||
const CONTEXT_UPDATE_STATE = new RawContextKey<string>('updateState', StateType.Uninitialized);
|
||||
@@ -123,11 +123,10 @@ export class ProductContribution implements IWorkbenchContribution {
|
||||
@IOpenerService openerService: IOpenerService,
|
||||
@IConfigurationService configurationService: IConfigurationService,
|
||||
@IWindowService windowService: IWindowService,
|
||||
@IWindowsService windowsService: IWindowsService,
|
||||
@IProductService productService: IProductService
|
||||
) {
|
||||
windowsService.getActiveWindowId().then(async windowId => {
|
||||
if (windowId !== windowService.windowId) {
|
||||
windowService.isFocused().then(async isFocused => {
|
||||
if (!isFocused) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1280,10 +1280,6 @@ export class TestWindowsService implements IWindowsService {
|
||||
files: []
|
||||
});
|
||||
}
|
||||
|
||||
getActiveWindowId(): Promise<number | undefined> {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
export class TestTextResourceConfigurationService implements ITextResourceConfigurationService {
|
||||
|
||||
Reference in New Issue
Block a user