Refactor external source files to live in app/
This commit is contained in:
parent
db62494109
commit
ed831dacd0
6 changed files with 13 additions and 9 deletions
65
app/autoupdate.js
Normal file
65
app/autoupdate.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
const autoUpdater = require('electron-updater').autoUpdater
|
||||
const { dialog } = require('electron');
|
||||
|
||||
const windowState = require('./window_state');
|
||||
|
||||
const hour = 60 * 60;
|
||||
const autoUpdaterInterval = hour * 1000;
|
||||
|
||||
const RESTART_BUTTON = 0;
|
||||
const LATER_BUTTON = 1;
|
||||
|
||||
function autoUpdateDisabled(config) {
|
||||
return process.mas || config.get('disableAutoUpdate');
|
||||
}
|
||||
|
||||
function checkForUpdates() {
|
||||
autoUpdater.checkForUpdates();
|
||||
}
|
||||
|
||||
function showUpdateDialog(localeMessages) {
|
||||
return function() {
|
||||
const options = {
|
||||
type: 'info',
|
||||
buttons: [
|
||||
localeMessages.autoUpdateRestartButtonLabel.message,
|
||||
localeMessages.autoUpdateLaterButtonLabel.message
|
||||
],
|
||||
title: localeMessages.autoUpdateNewVersionTitle.message,
|
||||
message: localeMessages.autoUpdateNewVersionMessage.message,
|
||||
detail: localeMessages.autoUpdateNewVersionInstructions.message,
|
||||
defaultId: RESTART_BUTTON,
|
||||
cancelId: LATER_BUTTON
|
||||
}
|
||||
|
||||
dialog.showMessageBox(options, function(response) {
|
||||
if (response == RESTART_BUTTON) {
|
||||
windowState.markShouldQuit();
|
||||
autoUpdater.quitAndInstall();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onError(error) {
|
||||
console.log("Got an error while updating: ", error.stack);
|
||||
}
|
||||
|
||||
function initializeAutoUpdater(config, localeMessages) {
|
||||
if (autoUpdateDisabled(config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const onUpdateDownloaded = showUpdateDialog(localeMessages);
|
||||
|
||||
autoUpdater.addListener('update-downloaded', onUpdateDownloaded);
|
||||
autoUpdater.addListener('error', onError);
|
||||
|
||||
checkForUpdates();
|
||||
|
||||
setInterval(checkForUpdates, autoUpdaterInterval);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
initializeAutoUpdater
|
||||
};
|
29
app/locale.js
Normal file
29
app/locale.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
function normalizeLocaleName(locale) {
|
||||
if (/^en-/.test(locale)) {
|
||||
return 'en';
|
||||
}
|
||||
|
||||
return locale;
|
||||
}
|
||||
|
||||
function getLocaleMessages(locale) {
|
||||
const onDiskLocale = locale.replace('-', '_');
|
||||
|
||||
const targetFile = path.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'_locales',
|
||||
onDiskLocale,
|
||||
'messages.json'
|
||||
);
|
||||
|
||||
return JSON.parse(fs.readFileSync(targetFile, 'utf-8'))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
normalizeLocaleName,
|
||||
getLocaleMessages
|
||||
}
|
153
app/menu.js
Normal file
153
app/menu.js
Normal file
|
@ -0,0 +1,153 @@
|
|||
const {Menu} = require('electron')
|
||||
|
||||
const template = [
|
||||
{
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{
|
||||
role: 'undo'
|
||||
},
|
||||
{
|
||||
role: 'redo'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'cut'
|
||||
},
|
||||
{
|
||||
role: 'copy'
|
||||
},
|
||||
{
|
||||
role: 'paste'
|
||||
},
|
||||
{
|
||||
role: 'pasteandmatchstyle'
|
||||
},
|
||||
{
|
||||
role: 'delete'
|
||||
},
|
||||
{
|
||||
role: 'selectall'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{
|
||||
role: 'reload'
|
||||
},
|
||||
{
|
||||
role: 'forcereload'
|
||||
},
|
||||
{
|
||||
role: 'toggledevtools'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'resetzoom'
|
||||
},
|
||||
{
|
||||
role: 'zoomin'
|
||||
},
|
||||
{
|
||||
role: 'zoomout'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'togglefullscreen'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
role: 'window',
|
||||
submenu: [
|
||||
{
|
||||
role: 'minimize'
|
||||
},
|
||||
{
|
||||
role: 'close'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
template.unshift({
|
||||
submenu: [
|
||||
{
|
||||
role: 'about'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'hide'
|
||||
},
|
||||
{
|
||||
role: 'hideothers'
|
||||
},
|
||||
{
|
||||
role: 'unhide'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'quit'
|
||||
}
|
||||
]
|
||||
})
|
||||
// Edit menu.
|
||||
template[1].submenu.push(
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Speech',
|
||||
submenu: [
|
||||
{
|
||||
role: 'startspeaking'
|
||||
},
|
||||
{
|
||||
role: 'stopspeaking'
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
// Window menu.
|
||||
template[3].submenu = [
|
||||
{
|
||||
label: 'Close',
|
||||
accelerator: 'CmdOrCtrl+W',
|
||||
role: 'close'
|
||||
},
|
||||
{
|
||||
label: 'Minimize',
|
||||
accelerator: 'CmdOrCtrl+M',
|
||||
role: 'minimize'
|
||||
},
|
||||
{
|
||||
label: 'Zoom',
|
||||
role: 'zoom'
|
||||
},
|
||||
{
|
||||
label: 'Show',
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Bring All to Front',
|
||||
role: 'front'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
module.exports = template;
|
14
app/window_state.js
Normal file
14
app/window_state.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
let shouldQuitFlag = false;
|
||||
|
||||
function markShouldQuit() {
|
||||
shouldQuitFlag = true;
|
||||
}
|
||||
|
||||
function shouldQuit() {
|
||||
return shouldQuitFlag;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
shouldQuit,
|
||||
markShouldQuit
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue