From 864e82e67b4622f42a0c15d4f31c3674e20ca0e2 Mon Sep 17 00:00:00 2001 From: neauoire Date: Sun, 3 Nov 2019 14:50:35 -0500 Subject: [PATCH] * --- desktop/main.js | 2 +- desktop/sources/index.html | 2 +- desktop/sources/scripts/lib/acels.js | 23 ++++++++++++++++++++--- desktop/sources/scripts/lib/source.js | 4 ++-- desktop/sources/scripts/lib/theme.js | 7 ++++--- desktop/sources/scripts/ronin.js | 13 ++----------- 6 files changed, 30 insertions(+), 21 deletions(-) diff --git a/desktop/main.js b/desktop/main.js index 0e3b0ee..16eb20f 100644 --- a/desktop/main.js +++ b/desktop/main.js @@ -25,7 +25,7 @@ app.on('ready', () => { app.win.webContents.removeAllListeners('devtools-reload-page') app.win.loadURL(`file://${__dirname}/sources/index.html`) - app.inspect() + // app.inspect() app.win.on('closed', () => { win = null diff --git a/desktop/sources/index.html b/desktop/sources/index.html index 18a8342..49797f9 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -23,7 +23,7 @@ window.addEventListener('load', () => { ronin.start() - ronin.acels.inject() + ronin.acels.inject('Ronin') }) diff --git a/desktop/sources/scripts/lib/acels.js b/desktop/sources/scripts/lib/acels.js index b5beaed..17d9c9a 100644 --- a/desktop/sources/scripts/lib/acels.js +++ b/desktop/sources/scripts/lib/acels.js @@ -27,7 +27,7 @@ function Acels () { } this.convert = (event) => { - const accelerator = event.accelerator.substr(0, 1).toUpperCase() + event.accelerator.substr(1) + const accelerator = event.key.substr(0, 1).toUpperCase() + event.key.substr(1) if ((event.ctrlKey || event.metaKey) && event.shiftKey) { return `CmdOrCtrl+Shift+${accelerator}` } @@ -77,8 +77,25 @@ function Acels () { return text.trim() } - this.inject = () => { + // Electron specifics + + this.inject = (name = 'Untitled') => { + const app = require('electron').remote.app const injection = [] + + injection.push({ + label: name, + submenu: [ + { label: 'About', click: () => { require('electron').shell.openExternal('https://github.com/hundredrabbits/' + name) } }, + { label: 'Download Themes', click: () => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes') } }, + { label: 'Fullscreen', accelerator: 'CmdOrCtrl+Enter', click: () => { app.toggleFullscreen() } }, + { label: 'Hide', accelerator: 'CmdOrCtrl+H', click: () => { app.toggleVisible() } }, + { label: 'Toggle Menubar', accelerator: 'Alt+H', click: () => { app.toggleMenubar() } }, + { label: 'Inspect', accelerator: 'CmdOrCtrl+.', click: () => { app.inspect() } }, + { label: 'Quit', accelerator: 'CmdOrCtrl+Q', click: () => { app.exit() } } + ] + }) + const sorted = this.sort() for (const cat of Object.keys(sorted)) { const submenu = [] @@ -93,6 +110,6 @@ function Acels () { } injection.push({ label: cat, submenu: submenu }) } - require('electron').remote.app.injectMenu(injection) + app.injectMenu(injection) } } diff --git a/desktop/sources/scripts/lib/source.js b/desktop/sources/scripts/lib/source.js index 8176c61..7c007c1 100644 --- a/desktop/sources/scripts/lib/source.js +++ b/desktop/sources/scripts/lib/source.js @@ -55,14 +55,14 @@ function Source () { reader.readAsText(file, 'UTF-8') } - this.download = (name, content, type) => { + this.download = (name, content, type, settings = 'charset=utf-8') => { console.info('Source', `Downloading ${name}(${type})`) const link = document.createElement('a') link.setAttribute('download', name) if (type === 'image/png' || type === 'image/jpeg') { link.setAttribute('href', content) } else { - link.setAttribute('href', 'data:' + type + ';charset=utf-8,' + encodeURIComponent(content)) + link.setAttribute('href', 'data:' + type + ';' + settings + ',' + encodeURIComponent(content)) } link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })) } diff --git a/desktop/sources/scripts/lib/theme.js b/desktop/sources/scripts/lib/theme.js index 897243f..94061ed 100644 --- a/desktop/sources/scripts/lib/theme.js +++ b/desktop/sources/scripts/lib/theme.js @@ -7,6 +7,7 @@ function Theme () { const themer = this + this.default = { background: '#eee', f_high: '#000', f_med: '#999', f_low: '#ccc', f_inv: '#000', b_high: '#000', b_med: '#888', b_low: '#aaa', b_inv: '#ffb545' } this.active = {} this.el = document.createElement('style') @@ -17,8 +18,8 @@ function Theme () { this.callback = callback } - this.start = (defaultTheme) => { - this.active = defaultTheme + this.start = () => { + this.active = this.default console.log('Theme', 'Starting..') if (isJson(localStorage.theme)) { const storage = JSON.parse(localStorage.theme) @@ -44,7 +45,7 @@ function Theme () { } this.reset = () => { - this.load(_default) + this.load(this.default) } this.get = (key) => { diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js index 4551563..d2fe0fd 100644 --- a/desktop/sources/scripts/ronin.js +++ b/desktop/sources/scripts/ronin.js @@ -17,6 +17,7 @@ function Ronin () { this.acels = new Acels() this.theme = new Theme() this.source = new Source() + this.commander = new Commander(this) this.surface = new Surface(this) this.library = new Library(this) @@ -55,17 +56,7 @@ function Ronin () { this.start = function () { console.log('Ronin', 'Starting..') console.info(`${this.acels}`) - this.theme.start({ - background: '#111', - f_high: '#fff', - f_med: '#999', - f_low: '#444', - f_inv: '#000', - b_high: '#ffffff', - b_med: '#72dec2', - b_low: '#aaaaaa', - b_inv: '#ffb545' - }) + this.theme.start() this.source.start() this.commander.start() this.surface.start()