Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 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';
import {libInit, gn, scaleMultiplier, newHTML,
isAndroid, isTablet, getUrlVars, CSSTransition3D, frame} from '../utils/lib';

import { ipcRenderer } from 'electron';

let workingCanvas = document.createElement('canvas');
let workingCanvas2 = document.createElement('canvas');
let activeFocus;
Expand Down Expand Up @@ -992,3 +994,11 @@ 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');
});
44 changes: 32 additions & 12 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ isDev = (isDev) || process.env.DEBUG_SCRATCHJR;

const { app, dialog, BrowserWindow, BrowserView, ipcMain, Menu } = require('electron');

var myWindow = null;

var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
// Someone tried to run a second instance, we should focus our window.
if (myWindow) {
if (myWindow.isMinimized()) myWindow.restore();
myWindow.focus();
}
});

if (shouldQuit) {
app.quit();
}


/* eslint-enable import/extensions */ // --> ON
Expand Down Expand Up @@ -128,23 +141,30 @@ function createWindow() {
win.webContents.openDevTools();
}

// Emitted when the window is closed.
win.on('closed', () => {
// 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;
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 Expand Up @@ -459,7 +479,7 @@ ipcMain.on('io_getAudioData', (event, audioName) => {

ipcMain.on('database_stmt', (event, json) => {
// {"stmt":"select name,thumbnail,id,isgift from projects where deleted = ? AND version = ? AND gallery IS NULL order by ctime desc","values":["NO","iOSv01"]}
if (DEBUG_DATABASE) debugLog('database_stmt', json);
if (DEBUG_DATABASE) debugLog('database_stmt', json);

const db = dataStore.getDatabaseManager();
event.returnValue = db.stmt(json);
Expand Down