-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from mattgodbolt/electron-app
Add an electron app
- Loading branch information
Showing
12 changed files
with
2,539 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,45 @@ | ||
sudo: false | ||
install: true | ||
language: node_js | ||
install: | ||
- pip install --user awscli | ||
node_js: | ||
- "8" | ||
- pip install --user awscli | ||
node_js: | ||
- '12' | ||
env: | ||
global: | ||
# include $HOME/.local/bin for `aws` | ||
- PATH=$HOME/.local/bin:$PATH | ||
matrix: | ||
- TEST_SUITE=short-tests | ||
- TEST_SUITE=long-tests | ||
- TEST_SUITE=lint | ||
script: | ||
make -j2 ${TEST_SUITE} | ||
|
||
global: | ||
- PATH=$HOME/.local/bin:$PATH | ||
# GH_TOKEN=<secret> maps to ecb...ca5 | ||
- secure: iSv2VWrSWlGERo6jl6V2SLwfWPxx/Y54jTyXBOQLz/nhuzHYFmzvCxNQ9uZkbPC+cQwopcWsxAM+rgWsOJtGiKay2hIJ9qBHknHcSlKaRwiA+2fr8ljTe52kHW3HY6IDj1PyCX7JDG7xFIhYP+URDF3eO9W5XxowIP5d2VP6GGI= | ||
cache: | ||
directories: | ||
- node_modules | ||
- "$HOME/.cache/electron" | ||
- "$HOME/.cache/electron-builder" | ||
- "$HOME/.npm/_prebuilds" | ||
jobs: | ||
include: | ||
- stage: deploy | ||
if: branch = master and type != pull_request | ||
env: TEST_SUITE=upload | ||
include: | ||
- name: Short tests | ||
script: make -j2 short-tests | ||
- name: Long tests | ||
script: make -j2 long-tests | ||
- name: Lint | ||
script: make -j2 lint | ||
- stage: deploy | ||
name: Website | ||
if: branch = master and type != pull_request | ||
env: TEST_SUITE=upload | ||
- stage: deploy | ||
name: Electron Windows & Mac | ||
os: osx | ||
osx_image: xcode11.4 | ||
script: | ||
- npm install | ||
- npm run dist -- --mac --win | ||
before_cache: | ||
- rm -rf $HOME/.cache/electron-builder/wine | ||
- stage: deploy | ||
name: Linux | ||
os: linux | ||
dist: trusty | ||
script: | ||
- npm install | ||
- npm run dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"strict": true, | ||
"undef": true, | ||
"browser": true, | ||
"node": true, | ||
"globals": { | ||
"define": false, | ||
"requirejs": false, | ||
"ga": false | ||
}, | ||
"esversion": 8, | ||
"eqeqeq": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
"use strict"; | ||
const {app, dialog, Menu, BrowserWindow} = require('electron'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const {ArgumentParser} = require('argparse'); | ||
|
||
const isMac = process.platform === 'darwin'; | ||
|
||
function getArguments() { | ||
// Heinous hack to get "built" versions working | ||
if (path.basename(process.argv[0]) === 'jsbeeb') // Is this ia "built" version? | ||
return process.argv.slice(1); | ||
return process.argv.slice(2); | ||
} | ||
|
||
const parser = new ArgumentParser({ | ||
prog: 'jsbeeb', | ||
addHelp: true, | ||
description: 'Emulate a Beeb' | ||
}); | ||
parser.addArgument(["--noboot"], {action: 'storeTrue', help: "don't autoboot if given a disc image"}); | ||
parser.addArgument(["disc1"], {nargs: '?', help: "image to load in drive 0"}); | ||
parser.addArgument(["disc2"], {nargs: '?', help: "image to load in drive 1"}); | ||
const args = parser.parseArgs(getArguments()); | ||
|
||
|
||
function getFileParam(filename) { | ||
try { | ||
return "file://" + fs.realpathSync(filename); | ||
} catch (e) { | ||
console.error("Unable to open file " + filename); | ||
throw e; | ||
} | ||
} | ||
|
||
async function createWindow() { | ||
const win = new BrowserWindow({ | ||
width: 1280, | ||
height: 1024, | ||
webPreferences: { | ||
preload: path.join(__dirname, 'preload.js') | ||
} | ||
}); | ||
|
||
const query = {}; | ||
if (args.disc1 && !args.noboot) query.autoboot = true; | ||
if (args.disc1) query.disc1 = getFileParam(args.disc1); | ||
if (args.disc2) query.disc2 = getFileParam(args.disc2); | ||
await win.loadFile('index.html', {query}); | ||
|
||
app.on('activate', function () { | ||
if (BrowserWindow.getAllWindows().length === 0) createWindow(); | ||
}); | ||
} | ||
|
||
app.on('window-all-closed', function () { | ||
if (process.platform !== 'darwin') app.quit(); | ||
}); | ||
|
||
app.whenReady().then(createWindow) | ||
.catch(e => { | ||
console.error("Unhandled exception", e); | ||
app.exit(1); | ||
}); | ||
|
||
function makeLoader(drive) { | ||
return async (_, browserWindow) => { | ||
const result = await dialog.showOpenDialog(browserWindow, { | ||
title: "Load a disc image", | ||
filters: [ | ||
{name: 'Disc images', extensions: ['ssd', 'dsd']}, | ||
{name: 'ZIPped disc images', extensions: ['zip']}, | ||
], | ||
properties: ['openFile'] | ||
}); | ||
if (!result.canceled) { | ||
browserWindow.webContents.send('load', {drive, path: getFileParam(result.filePaths[0])}); | ||
} | ||
}; | ||
} | ||
|
||
const template = [ | ||
// { role: 'appMenu' } | ||
...(isMac ? [{ | ||
label: app.name, | ||
submenu: [ | ||
{role: 'about'}, | ||
{type: 'separator'}, | ||
{role: 'services'}, | ||
{type: 'separator'}, | ||
{role: 'hide'}, | ||
{role: 'hideothers'}, | ||
{role: 'unhide'}, | ||
{type: 'separator'}, | ||
{role: 'quit'} | ||
] | ||
}] : []), | ||
// { role: 'fileMenu' } | ||
{ | ||
label: 'File', | ||
submenu: [ | ||
{ | ||
label: 'Load disc 0', | ||
click: makeLoader(0) | ||
}, | ||
{ | ||
label: 'Load disc 1', | ||
click: makeLoader(1) | ||
}, | ||
isMac ? {role: 'close'} : {role: 'quit'} | ||
] | ||
}, | ||
// { role: 'editMenu' } | ||
{ | ||
label: 'Edit', | ||
submenu: [{role: 'paste'}] | ||
}, | ||
// { role: 'viewMenu' } | ||
{ | ||
label: 'View', | ||
submenu: [ | ||
{role: 'reload'}, | ||
{role: 'forcereload'}, | ||
{role: 'toggledevtools'}, | ||
{type: 'separator'}, | ||
{role: 'resetzoom'}, | ||
{role: 'zoomin'}, | ||
{role: 'zoomout'}, | ||
{type: 'separator'}, | ||
{role: 'togglefullscreen'} | ||
] | ||
}, | ||
{ | ||
role: 'help', | ||
submenu: [ | ||
{ | ||
label: 'Learn More', | ||
click: async () => { | ||
const {shell} = require('electron'); | ||
await shell.openExternal('https://github.com/mattgodbolt/jsbeeb/'); | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
|
||
const menu = Menu.buildFromTemplate(template); | ||
Menu.setApplicationMenu(menu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
define([], function () { | ||
'use strict'; | ||
if (typeof window.nodeRequire === 'undefined') return function () { | ||
}; | ||
|
||
function init(args) { | ||
const {loadDiscImage, processor} = args; | ||
const electron = window.nodeRequire('electron'); | ||
electron.ipcRenderer.on('load', async (event, message) => { | ||
const {drive, path} = message; | ||
const image = await loadDiscImage(path); | ||
processor.fdc.loadDisc(drive, image); | ||
}); | ||
} | ||
|
||
return init; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
window.nodeRequire = require; | ||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
for (const node of document.getElementsByClassName("not-electron")) { | ||
node.remove(); | ||
} | ||
}); |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.