Skip to content

Commit

Permalink
log: windows service
Browse files Browse the repository at this point in the history
related to #41680
  • Loading branch information
joaomoreno committed Feb 20, 2018
1 parent 3f0aaa4 commit 56db332
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/vs/platform/windows/electron-main/windowsService.ts
Expand Up @@ -24,6 +24,7 @@ import { ICommandAction } from 'vs/platform/actions/common/actions';
import { Schemas } from 'vs/base/common/network';
import { mnemonicButtonLabel } from 'vs/base/common/labels';
import { isWindows } from 'vs/base/common/platform';
import { ILogService } from '../../log/common/log';

export class WindowsService implements IWindowsService, IDisposable {

Expand All @@ -41,7 +42,8 @@ export class WindowsService implements IWindowsService, IDisposable {
@IEnvironmentService private environmentService: IEnvironmentService,
@IURLService urlService: IURLService,
@ILifecycleService private lifecycleService: ILifecycleService,
@IHistoryMainService private historyService: IHistoryMainService
@IHistoryMainService private historyService: IHistoryMainService,
@ILogService private logService: ILogService
) {
// Catch file URLs
chain(urlService.onOpenURL)
Expand All @@ -57,48 +59,56 @@ export class WindowsService implements IWindowsService, IDisposable {
}

pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
this.logService.trace('windowsService#pickFileFolderAndOpen');
this.windowsMainService.pickFileFolderAndOpen(options);

return TPromise.as(null);
}

pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
this.logService.trace('windowsService#pickFileAndOpen');
this.windowsMainService.pickFileAndOpen(options);

return TPromise.as(null);
}

pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
this.logService.trace('windowsService#pickFolderAndOpen');
this.windowsMainService.pickFolderAndOpen(options);

return TPromise.as(null);
}

pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
this.logService.trace('windowsService#pickWorkspaceAndOpen');
this.windowsMainService.pickWorkspaceAndOpen(options);

return TPromise.as(null);
}

showMessageBox(windowId: number, options: Electron.MessageBoxOptions): TPromise<IMessageBoxResult> {
this.logService.trace('windowsService#showMessageBox', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

return this.windowsMainService.showMessageBox(options, codeWindow);
}

showSaveDialog(windowId: number, options: Electron.SaveDialogOptions): TPromise<string> {
this.logService.trace('windowsService#showSaveDialog', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

return this.windowsMainService.showSaveDialog(options, codeWindow);
}

showOpenDialog(windowId: number, options: Electron.OpenDialogOptions): TPromise<string[]> {
this.logService.trace('windowsService#showOpenDialog', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

return this.windowsMainService.showOpenDialog(options, codeWindow);
}

reloadWindow(windowId: number): TPromise<void> {
this.logService.trace('windowsService#reloadWindow', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -109,6 +119,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

openDevTools(windowId: number): TPromise<void> {
this.logService.trace('windowsService#openDevTools', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -119,6 +130,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

toggleDevTools(windowId: number): TPromise<void> {
this.logService.trace('windowsService#toggleDevTools', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -134,6 +146,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

updateTouchBar(windowId: number, items: ICommandAction[][]): TPromise<void> {
this.logService.trace('windowsService#updateTouchBar', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -144,6 +157,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

closeWorkspace(windowId: number): TPromise<void> {
this.logService.trace('windowsService#closeWorkspace', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -154,6 +168,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
this.logService.trace('windowsService#createAndEnterWorkspace', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -164,6 +179,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

saveAndEnterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
this.logService.trace('windowsService#saveAndEnterWorkspace', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -174,6 +190,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

toggleFullScreen(windowId: number): TPromise<void> {
this.logService.trace('windowsService#toggleFullScreen', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -184,6 +201,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

setRepresentedFilename(windowId: number, fileName: string): TPromise<void> {
this.logService.trace('windowsService#setRepresentedFilename', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -194,24 +212,28 @@ export class WindowsService implements IWindowsService, IDisposable {
}

addRecentlyOpened(files: string[]): TPromise<void> {
this.logService.trace('windowsService#addRecentlyOpened');
this.historyService.addRecentlyOpened(void 0, files);

return TPromise.as(null);
}

removeFromRecentlyOpened(paths: string[]): TPromise<void> {
this.logService.trace('windowsService#removeFromRecentlyOpened');
this.historyService.removeFromRecentlyOpened(paths);

return TPromise.as(null);
}

clearRecentlyOpened(): TPromise<void> {
this.logService.trace('windowsService#clearRecentlyOpened');
this.historyService.clearRecentlyOpened();

return TPromise.as(null);
}

getRecentlyOpened(windowId: number): TPromise<IRecentlyOpened> {
this.logService.trace('windowsService#getRecentlyOpened', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -222,36 +244,42 @@ export class WindowsService implements IWindowsService, IDisposable {
}

showPreviousWindowTab(): TPromise<void> {
this.logService.trace('windowsService#showPreviousWindowTab');
Menu.sendActionToFirstResponder('selectPreviousTab:');

return TPromise.as(void 0);
}

showNextWindowTab(): TPromise<void> {
this.logService.trace('windowsService#showNextWindowTab');
Menu.sendActionToFirstResponder('selectNextTab:');

return TPromise.as(void 0);
}

moveWindowTabToNewWindow(): TPromise<void> {
this.logService.trace('windowsService#moveWindowTabToNewWindow');
Menu.sendActionToFirstResponder('moveTabToNewWindow:');

return TPromise.as(void 0);
}

mergeAllWindowTabs(): TPromise<void> {
this.logService.trace('windowsService#mergeAllWindowTabs');
Menu.sendActionToFirstResponder('mergeAllWindows:');

return TPromise.as(void 0);
}

toggleWindowTabsBar(): TPromise<void> {
this.logService.trace('windowsService#toggleWindowTabsBar');
Menu.sendActionToFirstResponder('toggleTabBar:');

return TPromise.as(void 0);
}

focusWindow(windowId: number): TPromise<void> {
this.logService.trace('windowsService#focusWindow', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -262,6 +290,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

closeWindow(windowId: number): TPromise<void> {
this.logService.trace('windowsService#closeWindow', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -272,6 +301,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

isFocused(windowId: number): TPromise<boolean> {
this.logService.trace('windowsService#isFocused', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -282,6 +312,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

isMaximized(windowId: number): TPromise<boolean> {
this.logService.trace('windowsService#isMaximized', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -292,6 +323,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

maximizeWindow(windowId: number): TPromise<void> {
this.logService.trace('windowsService#maximizeWindow', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -302,6 +334,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

unmaximizeWindow(windowId: number): TPromise<void> {
this.logService.trace('windowsService#unmaximizeWindow', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -312,6 +345,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

onWindowTitleDoubleClick(windowId: number): TPromise<void> {
this.logService.trace('windowsService#onWindowTitleDoubleClick', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -322,6 +356,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

setDocumentEdited(windowId: number, flag: boolean): TPromise<void> {
this.logService.trace('windowsService#setDocumentEdited', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow && codeWindow.win.isDocumentEdited() !== flag) {
Expand All @@ -332,6 +367,7 @@ export class WindowsService implements IWindowsService, IDisposable {
}

openWindow(paths: string[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean }): TPromise<void> {
this.logService.trace('windowsService#openWindow');
if (!paths || !paths.length) {
return TPromise.as(null);
}
Expand All @@ -349,11 +385,13 @@ export class WindowsService implements IWindowsService, IDisposable {
}

openNewWindow(): TPromise<void> {
this.logService.trace('windowsService#openNewWindow');
this.windowsMainService.openNewWindow(OpenContext.API);
return TPromise.as(null);
}

showWindow(windowId: number): TPromise<void> {
this.logService.trace('windowsService#showWindow', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
Expand All @@ -364,13 +402,15 @@ export class WindowsService implements IWindowsService, IDisposable {
}

getWindows(): TPromise<{ id: number; workspace?: IWorkspaceIdentifier; folderPath?: string; title: string; filename?: string; }[]> {
this.logService.trace('windowsService#getWindows');
const windows = this.windowsMainService.getWindows();
const result = windows.map(w => ({ id: w.id, workspace: w.openedWorkspace, openedFolderPath: w.openedFolderPath, title: w.win.getTitle(), filename: w.getRepresentedFilename() }));

return TPromise.as(result);
}

getWindowCount(): TPromise<number> {
this.logService.trace('windowsService#getWindowCount');
return TPromise.as(this.windowsMainService.getWindows().length);
}

Expand All @@ -380,40 +420,48 @@ export class WindowsService implements IWindowsService, IDisposable {
}

showItemInFolder(path: string): TPromise<void> {
this.logService.trace('windowsService#showItemInFolder');
shell.showItemInFolder(path);
return TPromise.as(null);
}

openExternal(url: string): TPromise<boolean> {
this.logService.trace('windowsService#openExternal');
return TPromise.as(shell.openExternal(url));
}

startCrashReporter(config: Electron.CrashReporterStartOptions): TPromise<void> {
this.logService.trace('windowsService#startCrashReporter');
crashReporter.start(config);
return TPromise.as(null);
}

quit(): TPromise<void> {
this.logService.trace('windowsService#quit');
this.windowsMainService.quit();
return TPromise.as(null);
}

relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise<void> {
this.logService.trace('windowsService#relaunch');
this.lifecycleService.relaunch(options);

return TPromise.as(null);
}

whenSharedProcessReady(): TPromise<void> {
this.logService.trace('windowsService#whenSharedProcessReady');
return this.sharedProcess.whenReady();
}

toggleSharedProcess(): TPromise<void> {
this.logService.trace('windowsService#toggleSharedProcess');
this.sharedProcess.toggle();
return TPromise.as(null);
}

openAboutDialog(): TPromise<void> {
this.logService.trace('windowsService#openAboutDialog');
const lastActiveWindow = this.windowsMainService.getFocusedWindow() || this.windowsMainService.getLastActiveWindow();

const detail = nls.localize('aboutDetail',
Expand Down

0 comments on commit 56db332

Please sign in to comment.