diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index a4e62a5910..773166668a 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -1616,6 +1616,7 @@ define(function (require, exports, module) { * @private - tracks our closing state if we get called again */ var _windowGoingAway = false; + let exitWaitPromises = []; /** * @private @@ -1634,12 +1635,15 @@ define(function (require, exports, module) { return CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true }) .done(function () { + exitWaitPromises = []; _windowGoingAway = true; // Give everyone a chance to save their state - but don't let any problems block // us from quitting try { - ProjectManager.trigger("beforeAppClose"); + // if someone wats to do any deferred tasks, they should add + // their promise to the wait promises list. + ProjectManager.trigger("beforeAppClose", exitWaitPromises); } catch (ex) { console.error(ex); } @@ -2016,10 +2020,13 @@ define(function (require, exports, module) { _isReloading = true; return CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true }).done(function () { + exitWaitPromises = []; // Give everyone a chance to save their state - but don't let any problems block // us from quitting try { - ProjectManager.trigger("beforeAppClose"); + // if someone wats to do any deferred tasks, they should add + // their promise to the wait promises list. + ProjectManager.trigger("beforeAppClose", exitWaitPromises); } catch (ex) { console.error(ex); } @@ -2037,7 +2044,8 @@ define(function (require, exports, module) { // Defer for a more successful reload - issue #11539 window.setTimeout(function () { - raceAgainstTime(window.PhStore.flushDB()) // wither wait for flush or time this out + exitWaitPromises.push(window.PhStore.flushDB()); + raceAgainstTime(Promise.all(exitWaitPromises)) // wither wait for flush or time this out .finally(()=>{ raceAgainstTime(_safeNodeTerminate(), 4000) .finally(()=>{ @@ -2210,7 +2218,8 @@ define(function (require, exports, module) { event.preventDefault(); _handleWindowGoingAway(null, closeSuccess=>{ console.log('close success: ', closeSuccess); - raceAgainstTime(_safeFlushDB()) + exitWaitPromises.push(_safeFlushDB()); + raceAgainstTime(Promise.all(exitWaitPromises)) .finally(()=>{ raceAgainstTime(_safeNodeTerminate()) .finally(()=>{ diff --git a/src/extensionsIntegrated/NavigationAndHistory/FileRecovery.js b/src/extensionsIntegrated/NavigationAndHistory/FileRecovery.js index de5d41cab3..70a563389a 100644 --- a/src/extensionsIntegrated/NavigationAndHistory/FileRecovery.js +++ b/src/extensionsIntegrated/NavigationAndHistory/FileRecovery.js @@ -162,20 +162,25 @@ define(function (require, exports, module) { if(!input){ return null; } - const parts = input.split(',', 2); + // Find the first comma + const firstCommaIndex = input.indexOf(','); - if (parts.length !== 2) { + // If there's no comma or it's at the very beginning, the input is invalid + if (firstCommaIndex === -1 || firstCommaIndex === 0) { return null; } + // Extract the parts + const expectedLengthPart = input.slice(0, firstCommaIndex); + const actualString = input.slice(firstCommaIndex + 1); + // Parse the length part (should be the first part before the comma) - const expectedLength = parseInt(parts[0], 10); + const expectedLength = parseInt(expectedLengthPart, 10); if (isNaN(expectedLength)) { return null; } - // The second part is the actual string after the comma - const actualString = parts[1]; + // The second part is the actual string after the commas if (actualString.length === expectedLength) { return actualString; } @@ -471,6 +476,14 @@ define(function (require, exports, module) { // for the startup project. So we call manually. projectOpened(null, currentProjectRoot); } + ProjectManager.on("beforeAppClose", (_evt, waitPromises)=>{ + // this is a safe exit, we should delete all restore data. + let exitProjectRoot = ProjectManager.getProjectRoot(); + if(exitProjectRoot) { + const restoreRoot = getProjectRestoreRoot(exitProjectRoot.fullPath); + waitPromises.push(silentlyRemoveDirectory(restoreRoot)); + } + }); } function init() { diff --git a/src/extensionsIntegrated/Phoenix/html/new-project-template.html b/src/extensionsIntegrated/Phoenix/html/new-project-template.html index 529d020375..9e9dfb9baf 100644 --- a/src/extensionsIntegrated/Phoenix/html/new-project-template.html +++ b/src/extensionsIntegrated/Phoenix/html/new-project-template.html @@ -1,4 +1,4 @@ -