-
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save dialog for closing temporary sketch and unsaved files (#893)
* Use normal `OnWillStop` event * Align `CLOSE` command to rest of app * Fixed FS path vs encoded URL comparision when handling stop request. Ref: eclipse-theia/theia#11226 Signed-off-by: Akos Kitta <a.kitta@arduino.cc> * Fixed the translations. Signed-off-by: Akos Kitta <a.kitta@arduino.cc> * Fixed the translations again. Removed `electron` from the `nls-extract`. It does not contain app code. Signed-off-by: Akos Kitta <a.kitta@arduino.cc> * Aligned the stop handler code to Theia. Signed-off-by: Akos Kitta <a.kitta@arduino.cc> Co-authored-by: Akos Kitta <a.kitta@arduino.cc>
- Loading branch information
1 parent
3f472f0
commit bee7830
Showing
7 changed files
with
119 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
arduino-ide-extension/src/electron-main/theia/theia-electron-window.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { injectable } from '@theia/core/shared/inversify'; | ||
import { StopReason } from '@theia/core/lib/electron-common/messaging/electron-messages'; | ||
import { TheiaElectronWindow as DefaultTheiaElectronWindow } from '@theia/core/lib/electron-main/theia-electron-window'; | ||
import { FileUri } from '@theia/core/lib/node'; | ||
import URI from '@theia/core/lib/common/uri'; | ||
|
||
@injectable() | ||
export class TheiaElectronWindow extends DefaultTheiaElectronWindow { | ||
protected async handleStopRequest( | ||
onSafeCallback: () => unknown, | ||
reason: StopReason | ||
): Promise<boolean> { | ||
// Only confirm close to windows that have loaded our frontend. | ||
// 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) | ||
// Notes: | ||
// - Windows: file:///C:/path/to/somewhere vs file:///c%3A/path/to/somewhere | ||
// - macOS: file:///Applications/App%20Name.app/Contents vs /Applications/App Name.app/Contents | ||
// This URL string comes from electron, we can expect that this is properly encoded URL. For example, a space is `%20` | ||
const currentUrl = new URI(this.window.webContents.getURL()).toString(); | ||
// THEIA_FRONTEND_HTML_PATH is an FS path, we have to covert to an encoded URI string. | ||
const frontendUri = FileUri.create( | ||
this.globals.THEIA_FRONTEND_HTML_PATH | ||
).toString(); | ||
const safeToClose = | ||
!currentUrl.includes(frontendUri) || (await this.checkSafeToStop(reason)); | ||
if (safeToClose) { | ||
try { | ||
await onSafeCallback(); | ||
return true; | ||
} catch (e) { | ||
console.warn(`Request ${StopReason[reason]} failed.`, e); | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters