Skip to content

Commit

Permalink
add save on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSch committed Jan 13, 2023
1 parent b979d2a commit 7e215c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
9 changes: 9 additions & 0 deletions src/app/src/editor/ScratchJr.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Localization from '../utils/Localization.js';
import {libInit, gn, scaleMultiplier, newHTML,
isAndroid, isTablet, getUrlVars, CSSTransition3D, frame} from '../utils/lib.js';

const { ipcRenderer } = require('electron');

let workingCanvas = document.createElement('canvas');
let workingCanvas2 = document.createElement('canvas');
let activeFocus;
Expand Down Expand Up @@ -992,3 +994,10 @@ export default class ScratchJr {
}
}
}

ipcRenderer.on('app-close', function(event) {
// save the project
ScratchJr.saveProject(null, function () {});
// tell electron that it can exit now
event.sender.send('app-closed-acked');
});
27 changes: 16 additions & 11 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,28 @@ function createWindow() {
win.webContents.openDevTools();
}

// Emitted when the window is closed.
win.on('closed', async () => {
// save the database if it has been opened.
if (dataStore.databaseManager) {
await dataStore.databaseManager.save();
}

// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
win.on('close', (e) => {
e.preventDefault();
//tell editor to flush the data
win.webContents.send('app-close');
});

win.webContents.on('did-finish-load', () => {
});
}

ipcMain.on('app-closed-acked',(event) => {
// save the database if it has been opened.
if (dataStore.databaseManager) {
dataStore.databaseManager.save();
}

// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
app.exit();
})

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
Expand Down

1 comment on commit 7e215c8

@JustSch
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implements jfo8000#85

Please sign in to comment.