Skip to content

Commit 91570a0

Browse files
author
Benjamin Pasero
committed
electron - better fix for dialog use
1 parent 6982991 commit 91570a0

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

src/typings/electron.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,7 +2589,7 @@ declare namespace Electron {
25892589
* is passed, the dialog will not block the process. The API call will be
25902590
* asynchronous and the result will be passed via callback(response).
25912591
*/
2592-
showMessageBox(browserWindow: BrowserWindow | null, options: MessageBoxOptions, callback?: (response: number, checkboxChecked: boolean) => void): number;
2592+
showMessageBox(browserWindow: BrowserWindow, options: MessageBoxOptions, callback?: (response: number, checkboxChecked: boolean) => void): number;
25932593
/**
25942594
* Shows a message box, it will block the process until the message box is closed.
25952595
* It returns the index of the clicked button. The browserWindow argument allows
@@ -2610,7 +2610,7 @@ declare namespace Electron {
26102610
* file selector and a directory selector, so if you set properties to ['openFile',
26112611
* 'openDirectory'] on these platforms, a directory selector will be shown.
26122612
*/
2613-
showOpenDialog(browserWindow: BrowserWindow | null, options: OpenDialogOptions, callback?: (filePaths: string[], bookmarks: string[]) => void): string[];
2613+
showOpenDialog(browserWindow: BrowserWindow, options: OpenDialogOptions, callback?: (filePaths: string[], bookmarks: string[]) => void): string[];
26142614
/**
26152615
* The browserWindow argument allows the dialog to attach itself to a parent
26162616
* window, making it modal. The filters specifies an array of file types that can
@@ -2631,7 +2631,7 @@ declare namespace Electron {
26312631
* the API call will be asynchronous and the result will be passed via
26322632
* callback(filename).
26332633
*/
2634-
showSaveDialog(browserWindow: BrowserWindow | null, options: SaveDialogOptions, callback?: (filename: string, bookmark: string) => void): string;
2634+
showSaveDialog(browserWindow: BrowserWindow, options: SaveDialogOptions, callback?: (filename: string, bookmark: string) => void): string;
26352635
/**
26362636
* The browserWindow argument allows the dialog to attach itself to a parent
26372637
* window, making it modal. The filters specifies an array of file types that can

src/vs/code/electron-main/windows.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,9 +1897,15 @@ class Dialogs {
18971897
showMessageBox(options: Electron.MessageBoxOptions, window?: ICodeWindow): Promise<IMessageBoxResult> {
18981898
return this.getDialogQueue(window).queue(() => {
18991899
return new Promise(resolve => {
1900-
dialog.showMessageBox(window ? window.win : null, options, (response: number, checkboxChecked: boolean) => {
1900+
const callback = (response: number, checkboxChecked: boolean) => {
19011901
resolve({ button: response, checkboxChecked });
1902-
});
1902+
};
1903+
1904+
if (window) {
1905+
dialog.showMessageBox(window.win, options, callback);
1906+
} else {
1907+
dialog.showMessageBox(options, callback);
1908+
}
19031909
});
19041910
});
19051911
}
@@ -1916,9 +1922,15 @@ class Dialogs {
19161922

19171923
return this.getDialogQueue(window).queue(() => {
19181924
return new Promise(resolve => {
1919-
dialog.showSaveDialog(window ? window.win : null, options, path => {
1925+
const callback = (path: string) => {
19201926
resolve(normalizePath(path));
1921-
});
1927+
};
1928+
1929+
if (window) {
1930+
dialog.showSaveDialog(window.win, options, callback);
1931+
} else {
1932+
dialog.showSaveDialog(options, callback);
1933+
}
19221934
});
19231935
});
19241936
}
@@ -1948,9 +1960,15 @@ class Dialogs {
19481960

19491961
// Show dialog and wrap as promise
19501962
validatePathPromise.then(() => {
1951-
dialog.showOpenDialog(window ? window.win : null, options, paths => {
1963+
const callback = (paths: string[]) => {
19521964
resolve(normalizePaths(paths));
1953-
});
1965+
};
1966+
1967+
if (window) {
1968+
dialog.showOpenDialog(window.win, options, callback);
1969+
} else {
1970+
dialog.showOpenDialog(options, callback);
1971+
}
19541972
});
19551973
});
19561974
});

0 commit comments

Comments
 (0)