Moved electron related stuff into app folder

This commit is contained in:
Joel Collins 2019-05-02 14:48:25 +01:00
parent b0a9021a02
commit 31f088f805
33 changed files with 18 additions and 18 deletions

27
app/app.dev.js Normal file
View file

@ -0,0 +1,27 @@
const electron = require('electron')
const contextMenu = require('electron-context-menu')
const path = require('path')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
let url = 'http://localhost:8080/'
// Set the application menu
require('./menu.js')
app.on('ready', () => {
let window = new BrowserWindow({
width: 1124,
height: 800,
icon: path.join(__dirname, '/icons/png/64x64.png')
})
contextMenu({
showCopyImageAddress: true,
showSaveImageAs: true,
showInspectElement: true,
});
window.loadURL(url)
})

69
app/app.js Normal file
View file

@ -0,0 +1,69 @@
//handle setupevents as quickly as possible
const setupEvents = require('./setupEvents')
if (setupEvents.handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
return;
}
// Required packages
const electron = require('electron')
const contextMenu = require('electron-context-menu')
const path = require('path')
// Set up the app
const app = electron.app
const BrowserWindow = electron.BrowserWindow
// Set the window content
let url = `file://${path.join(__dirname, '../dist/index.html')}`
let mainWindow
// Set the application menu
require('./menu.js')
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1124,
height: 800,
icon: path.join(__dirname, '/icons/png/64x64.png')
})
contextMenu({
showCopyImageAddress: true,
showSaveImageAs: true,
showInspectElement: false,
});
mainWindow.loadURL(url)
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// 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.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function() {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function() {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})

BIN
app/icons/icon_base.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

BIN
app/icons/mac/icon.icns Normal file

Binary file not shown.

BIN
app/icons/png/1024x1024.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 885 KiB

BIN
app/icons/png/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
app/icons/png/16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B

BIN
app/icons/png/24x24.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
app/icons/png/256x256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
app/icons/png/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
app/icons/png/48x48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
app/icons/png/512x512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

BIN
app/icons/png/64x64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
app/icons/win/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -0,0 +1,36 @@
const convertToWindowsStore = require('electron-windows-store')
const path = require('path')
const package = require('../package.json');
var majorVer = package.version
var minorVer = 0
if (majorVer.indexOf("alpha") > -1) {
minorVer = 1
}
else if (majorVer.indexOf("beta") > -1) {
minorVer = 5
}
var numericVersion = package.version.replace(/[^\d.]/g, '')
var appxVersion = `${numericVersion}.${minorVer}`
convertToWindowsStore({
containerVirtualization: false,
inputDirectory: path.join(__dirname, '../release-builds/openflexure-ev-win32-x64'),
outputDirectory: path.join(__dirname, '../release-builds/dist', package.version),
assets: path.join(__dirname, '/appx/assets'),
makePri: true,
identityName: '60425J.T.Collins.OpenFlexureeV',
packageExecutable: 'app/openflexure-ev.exe',
packageName: 'OpenFlexureEV',
packageVersion: appxVersion,
packageDisplayName: package.productName,
packageDescription: package.description,
packageBackgroundColor: '#C5247F',
publisherDisplayName: 'J. T. Collins',
deploy: false,
publisher: 'CN=CC867BEF-0715-4D48-8035-8881993DBB68',
devCert: "C:\\Certs\\CC867BEF-0715-4D48-8035-8881993DBB68.pfx",
windowsKit: 'C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.17763.0\\x64'
})

View file

@ -0,0 +1,25 @@
const installer = require('electron-installer-debian')
const path = require('path')
const package = require('../package.json');
const options = {
src: path.join(__dirname, '../release-builds/openflexure-ev-linux-armv7l/'),
dest: path.join(__dirname, '../release-builds/dist', package.version),
arch: 'armhf',
icon: path.join(__dirname, '../icons/png/1024x1024.png'),
categories: [
"Science"
],
lintianOverrides: [
"changelog-file-missing-in-native-package"
]
}
console.log('Creating package (this may take a while)')
installer(options)
.then(() => console.log(`Successfully created package at ${options.dest}`))
.catch(err => {
console.error(err, err.stack)
process.exit(1)
})

View file

@ -0,0 +1,25 @@
const installer = require('electron-installer-debian')
const path = require('path')
const package = require('../package.json');
const options = {
src: path.join(__dirname, '../release-builds/openflexure-ev-linux-x64/'),
dest: path.join(__dirname, '../release-builds/dist', package.version),
arch: 'amd64',
icon: path.join(__dirname, '../icons/png/1024x1024.png'),
categories: [
"Science"
],
lintianOverrides: [
"changelog-file-missing-in-native-package"
]
}
console.log('Creating package (this may take a while)')
installer(options)
.then(() => console.log(`Successfully created package at ${options.dest}`))
.catch(err => {
console.error(err, err.stack)
process.exit(1)
})

View file

@ -0,0 +1,19 @@
const createDMG = require('electron-installer-dmg')
const path = require('path')
const package = require('../package.json');
var opts = {
appPath: path.join(__dirname, '../release-builds/openflexure-ev-darwin-x64/openflexure-ev.app'),
name: package.productName,
icon: path.join(__dirname, '../icons/mac/icon.icns'),
out: path.join(__dirname, '../release-builds/dist', package.version)
}
createDMG(opts, function done (err) {
if (err) {
console.log(`Error creating dmg: ${err}`)
}
else {
console.log("Done")
}
})

View file

@ -0,0 +1,25 @@
const createWindowsInstaller = require('electron-winstaller').createWindowsInstaller
const path = require('path')
const package = require('../package.json');
getInstallerConfig()
.then(createWindowsInstaller)
.catch((error) => {
console.error(error.message || error)
process.exit(1)
})
function getInstallerConfig () {
console.log('creating windows installer')
return Promise.resolve({
setupExe: `${package.name}.exe`,
appDirectory: path.join(__dirname, '../release-builds/openflexure-ev-win32-x64'),
authors: 'OpenFlexure',
noMsi: true,
outputDirectory: path.join(__dirname, '../release-builds/dist', package.version),
exe: 'openflexure-ev.exe',
setupIcon: path.join(__dirname, '../icons/win/icon.ico'),
certificateFile: "C:\\Certs\\BATH-OPEN-INSTRUMENTATION-GROUP.pfx"
})
}

25
app/installers/make.ps1 Normal file
View file

@ -0,0 +1,25 @@
echo "Setting up..."
$here = $PSScriptRoot
$root = "$here/.."
$package = Get-Content "$root/package.json" | Out-String | ConvertFrom-Json
$version = $package.version
$name = $package.name
$wslhere = (wsl wslpath -a ("$here" -Replace '\\','\\'))
$wslroot = (wsl wslpath -a ("$root" -Replace '\\','\\'))
mkdir "$root/release-builds/dist/$version/"
echo "Gzipping PWA..."
wsl tar -czvf "$wslroot/release-builds/dist/$version/${name}_web.tar.gz" -C "$wslroot/dist" .
echo "Building deb packages..."
wsl node "$wslhere/create-deb-x64.js"
wsl node "$wslhere/create-deb-arm.js"
echo "Building Windows installer..."
node "$here\create-exe.js"
echo "Building Windows appx package..."
node "$here\create-appx.js"

102
app/menu.js Normal file
View file

@ -0,0 +1,102 @@
const { app, Menu } = require('electron')
const path = require('path')
const openAboutWindow = require('about-window').default
const template = [
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'delete' },
{ role: 'selectall' }
]
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forcereload' },
{ role: 'toggledevtools' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
{
role: 'window',
submenu: [
{ role: 'minimize' },
{ role: 'close' }
]
},
{
role: 'help',
submenu: [
{
label: 'About',
click () {
openAboutWindow({
package_json_dir: path.join(__dirname, '..'),
icon_path: path.join(__dirname, '/icons/png/512x512.png'),
bug_report_url: "https://gitlab.com/openflexure/openflexure-microscope-jsclient/issues",
homepage: "https://gitlab.com/openflexure/openflexure-microscope-jsclient",
})
}
}
]
}
]
if (process.platform === 'darwin') {
template.unshift({
label: app.getName(),
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'services' },
{ 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 = [
{ role: 'close' },
{ role: 'minimize' },
{ role: 'zoom' },
{ type: 'separator' },
{ role: 'front' }
]
}
else {
template.unshift({
label: 'File',
submenu: [
{ role: 'quit' }
]
})
}
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)

67
app/setupEvents.js Normal file
View file

@ -0,0 +1,67 @@
const electron = require('electron')
const app = electron.app
module.exports = {
handleSquirrelEvent: function () {
if (process.argv.length === 1) {
return false;
}
const ChildProcess = require('child_process');
const path = require('path');
const appFolder = path.resolve(process.execPath, '..');
const rootAtomFolder = path.resolve(appFolder, '..');
const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
const exeName = path.basename(process.execPath);
const spawn = function (command, args) {
let spawnedProcess, error;
try {
spawnedProcess = ChildProcess.spawn(command, args, {
detached: true
});
} catch (error) {}
return spawnedProcess;
};
const spawnUpdate = function (args) {
return spawn(updateDotExe, args);
};
const squirrelEvent = process.argv[1];
switch (squirrelEvent) {
case '--squirrel-install':
case '--squirrel-updated':
// Optionally do things such as:
// - Add your .exe to the PATH
// - Write to the registry for things like file associations and
// explorer context menus
// Install desktop and start menu shortcuts
spawnUpdate(['--createShortcut', exeName]);
setTimeout(app.quit, 1000);
return true;
case '--squirrel-uninstall':
// Undo anything you did in the --squirrel-install and
// --squirrel-updated handlers
// Remove desktop and start menu shortcuts
spawnUpdate(['--removeShortcut', exeName]);
setTimeout(app.quit, 1000);
return true;
case '--squirrel-obsolete':
// This is called on the outgoing version of your app before
// we update to the new version - it's the opposite of
// --squirrel-updated
app.quit();
return true;
}
}
}