|
1 | 1 | import { injectable } from '@theia/core/shared/inversify';
|
2 |
| -import { isWindows } from '@theia/core/lib/common/os'; |
3 | 2 | import { StopReason } from '@theia/core/lib/electron-common/messaging/electron-messages';
|
4 | 3 | import { TheiaElectronWindow as DefaultTheiaElectronWindow } from '@theia/core/lib/electron-main/theia-electron-window';
|
5 | 4 | import { FileUri } from '@theia/core/lib/node';
|
| 5 | +import URI from '@theia/core/lib/common/uri'; |
6 | 6 |
|
7 | 7 | @injectable()
|
8 | 8 | export class TheiaElectronWindow extends DefaultTheiaElectronWindow {
|
9 | 9 | protected async handleStopRequest(
|
10 | 10 | onSafeCallback: () => unknown,
|
11 | 11 | reason: StopReason
|
12 | 12 | ): Promise<boolean> {
|
13 |
| - // Only confirm close to windows that have loaded our front end. |
14 |
| - let currentUrl = this.window.webContents.getURL(); // this comes from electron, expected to be an URL encoded string. e.g: space will be `%20` |
15 |
| - let frontendUri = FileUri.create( |
| 13 | + // Only confirm close to windows that have loaded our frontend. |
| 14 | + // Both the windows's URL and the FS path of the `index.html` should be converted to the "same" format to be able to compare them. (#11226) |
| 15 | + // Notes: |
| 16 | + // - Windows: file:///C:/path/to/somewhere vs file:///c%3A/path/to/somewhere |
| 17 | + // - macOS: file:///Applications/App%20Name.app/Contents vs /Applications/App Name.app/Contents |
| 18 | + // This URL string comes from electron, we can expect that this is properly encoded URL. For example, a space is `%20` |
| 19 | + const currentUrl = new URI(this.window.webContents.getURL()).toString(); |
| 20 | + // THEIA_FRONTEND_HTML_PATH is an FS path, we have to covert to an encoded URI string. |
| 21 | + const frontendUri = FileUri.create( |
16 | 22 | this.globals.THEIA_FRONTEND_HTML_PATH
|
17 |
| - ).toString(false); // Map the FS path to an URI, ensure the encoding is not skipped, so that a space will be `%20`. |
18 |
| - // Since our resolved frontend HTML path might contain backward slashes on Windows, we normalize everything first. |
19 |
| - if (isWindows) { |
20 |
| - currentUrl = currentUrl.replace(/\\/g, '/'); |
21 |
| - frontendUri = frontendUri.replace(/\\/g, '/'); |
22 |
| - } |
| 23 | + ).toString(); |
23 | 24 | const safeToClose =
|
24 | 25 | !currentUrl.includes(frontendUri) || (await this.checkSafeToStop(reason));
|
25 | 26 | if (safeToClose) {
|
|
0 commit comments