Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
GH-17: Patched generated electron code.
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <kittaakos@gmail.com>
  • Loading branch information
kittaakos committed Nov 15, 2017
1 parent c340413 commit fa28e8e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
59 changes: 59 additions & 0 deletions GH-17/electron-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// @ts-check
const cluster = require('cluster');
if (cluster.isMaster) {
// Workaround for https://github.com/electron/electron/issues/9225. Chrome has an issue where
// in certain locales (e.g. PL), image metrics are wrongly computed. We explicitly set the
// LC_NUMERIC to prevent this from happening (selects the numeric formatting category of the
// C locale, http://en.cppreference.com/w/cpp/locale/LC_categories).
if (process.env.LC_ALL) {
process.env.LC_ALL = 'C';
}
process.env.LC_NUMERIC = 'C';
const electron = require('electron');
electron.app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
electron.app.quit();
}
});
electron.app.on('ready', function () {
const path = require('path');
const { fork } = require('child_process');
// Check whether we are in bundled application or development mode.
const devMode = process.defaultApp || /node_modules[\/]electron[\/]/.test(process.execPath);
const mainWindow = new electron.BrowserWindow({ width: 1024, height: 728, show: false });
mainWindow.on('ready-to-show', () => mainWindow.show());
const mainPath = path.join(__dirname, '..', 'backend', 'main');
const loadMainWindow = function (port) {
mainWindow.loadURL(`file://${path.join(__dirname, '../../lib/index.html')}?port=${port}`);
};
// We need to distinguish between bundled application and development mode when starting the clusters.
// https://github.com/electron/electron/issues/6337#issuecomment-230183287
if (devMode) {
require(mainPath).then(address => {
loadMainWindow(address.port);
}).catch((error) => {
console.error(error);
electron.app.exit(1);
});
} else {
const cp = fork(mainPath);
cp.on('message', function (message) {
loadMainWindow(message);
});
cp.on('error', function (error) {
console.error(error);
electron.app.exit(1);
});
electron.app.on('quit', function() {
// If we forked the process for the clusters, we need to manually terminate it.
// See: https://github.com/theia-ide/theia/issues/835
process.kill(cp.pid);
})
}
mainWindow.on('closed', function () {
electron.app.exit(0);
});
});
} else {
require('../backend/main');
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"target": "electron"
},
"scripts": {
"build": "theia build",
"build": "theia build && shx cp ./GH-17/electron-main.js ./src-gen/frontend/",
"package": "yarn run build && electron-builder",
"package:all": "yarn run build && electron-builder -lmw"
},
Expand Down Expand Up @@ -41,6 +41,8 @@
},
"devDependencies": {
"@theia/cli": "^0.2.1",
"electron-builder": "^19.30.2"
"electron-builder": "^19.30.2",
"//": "GH-17",
"shx": "^0.2.2"
}
}
}

0 comments on commit fa28e8e

Please sign in to comment.