Skip to content

Commit

Permalink
Upgrade to Electron v16
Browse files Browse the repository at this point in the history
  • Loading branch information
ferllings authored Mar 25, 2022
1 parent 2af7f7a commit f5ef6a6
Show file tree
Hide file tree
Showing 26 changed files with 1,228 additions and 1,201 deletions.
1,426 changes: 707 additions & 719 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
"license": "GPL-3.0",
"devDependencies": {
"cross-env": "^7.0.3",
"electron": "^9.4.4",
"electron-builder": "^22.11.7",
"electron-notarize": "1.0.0"
"electron": "^16.0.1",
"electron-builder": "^22.14.5",
"electron-notarize": "1.1.1"
},
"dependencies": {
"color-blind": "^0.1.1",
"color-convert": "^2.0.1",
"color-name": "^1.1.4",
"dotenv": "^10.0.0",
"electron-log": "^2.2.17",
"electron-store": "^8.0.0",
"electron-updater": "^4.3.9",
"focus-visible": "^4.1.5",
"electron-browser-storage": "^1.0.7",
"electron-log": "^4.4.1",
"electron-store": "^8.0.1",
"electron-updater": "^4.6.1",
"focus-visible": "^5.2.0",
"simple-swizzle": "^0.2.2"
},
"build": {
Expand Down
254 changes: 171 additions & 83 deletions src/CCAcontroller.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/browsers/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')

module.exports = (dirname, sharedObject) => {
module.exports = (dirname) => {
let win

let init = () => {
Expand Down
5 changes: 3 additions & 2 deletions src/browsers/deficiency.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')

module.exports = (dirname, sharedObject) => {
module.exports = (dirname) => {
let win

let init = () => {
Expand All @@ -22,7 +22,8 @@ module.exports = (dirname, sharedObject) => {
alwaysOnTop: true,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true
nodeIntegration: true,
contextIsolation: false
}
})

Expand Down
10 changes: 5 additions & 5 deletions src/browsers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = (dirname, sharedObject) => ({
main: require('./main')(dirname, sharedObject),
about: require('./about')(dirname, sharedObject),
deficiency: require('./deficiency')(dirname, sharedObject),
preferences: require('./preferences')(dirname, sharedObject),
module.exports = (dirname, preferences) => ({
main: require('./main')(dirname, preferences),
about: require('./about')(dirname),
deficiency: require('./deficiency')(dirname),
preferences: require('./preferences')(dirname),
})
21 changes: 13 additions & 8 deletions src/browsers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {app, BrowserWindow, shell, Menu, MenuItem} = require('electron')
const path = require('path')
const url = require('url')

module.exports = (dirname, sharedObject) => {
module.exports = (dirname, preferences) => {
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
Expand All @@ -18,20 +18,25 @@ module.exports = (dirname, sharedObject) => {
else mainWindow.show()
}

let createWindow = () => {
let createWindow = async () => {
const x = await preferences.get('main.position.x')
const y = await preferences.get('main.position.y')
const alwaysOnTop = await preferences.get('main.alwaysOnTop')

// Create the browser window.
mainWindow = new BrowserWindow({
show: false, // Hide the application until the page has loaded
width: 480,
height: 600,
x: sharedObject.preferences.main.position.x,
y: sharedObject.preferences.main.position.y,
alwaysOnTop: global.sharedObject.preferences.main.alwaysOnTop,
x,
y,
alwaysOnTop,
resizable: false,
focusable: true,
useContentSize: true,
webPreferences: {
nodeIntegration: true
nodeIntegration: true,
contextIsolation: false
}
})
// and load the index.html of the app.
Expand All @@ -47,8 +52,8 @@ module.exports = (dirname, sharedObject) => {
mainWindow.on('close', function () {
if (mainWindow) {
pos = mainWindow.getPosition()
sharedObject.preferences.main.position.x = pos[0]
sharedObject.preferences.main.position.y = pos[1]
preferences.set('main.position.x', pos[0])
preferences.set('main.position.y', pos[1])
mainWindow = null
}
app.quit()
Expand Down
5 changes: 3 additions & 2 deletions src/browsers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')

module.exports = (dirname, sharedObject) => {
module.exports = (dirname) => {
let win

let init = (x, y) => {
Expand All @@ -24,7 +24,8 @@ module.exports = (dirname, sharedObject) => {
alwaysOnTop: true,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true
nodeIntegration: true,
contextIsolation: false
}
})

Expand Down
12 changes: 7 additions & 5 deletions src/controllers/about.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
const {ipcMain, app} = require('electron')

module.exports = (browsers, sharedObject) => {
module.exports = (browsers, preferences) => {
const {about} = browsers
ipcMain.on('init-about', () => {
const i18n = new(require('../i18n'))(sharedObject.preferences.main.lang)
ipcMain.on('init-about', async () => {
const lang = await preferences.get('main.lang')
const i18n = new(require('../i18n'))(lang)
let config = {
version: app.getVersion(),
i18n: i18n.asObject().About
}
sendEvent('init', config)
})

let sendEvent = (event, ...params) => {
let sendEvent = async (event, ...params) => {
const win = about.getWindow()
if (win) {

switch(event) {
case 'langChanged':
const i18n = new(require('../i18n'))(sharedObject.preferences.main.lang)
const lang = await preferences.get('main.lang')
const i18n = new(require('../i18n'))(lang)
win.webContents.send(event, i18n.asObject().About)
break
default:
Expand Down
12 changes: 7 additions & 5 deletions src/controllers/deficiency.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
const {ipcMain} = require('electron')

module.exports = (browsers, sharedObject) => {
module.exports = (browsers, preferences) => {
const {deficiency} = browsers
ipcMain.on('init-deficiency', () => {
const i18n = new(require('../i18n'))(sharedObject.preferences.main.lang)
ipcMain.on('init-deficiency', async () => {
const lang = await preferences.get('main.lang')
const i18n = new(require('../i18n'))(lang)
let config = {
i18n: i18n.asObject().Deficiency
}
sendEvent('init', config)
})

let sendEvent = (event, ...params) => {
let sendEvent = async (event, ...params) => {
const win = deficiency.getWindow()
if (win) {

switch(event) {
case 'langChanged':
const i18n = new(require('../i18n'))(sharedObject.preferences.main.lang)
const lang = await preferences.get('main.lang')
const i18n = new(require('../i18n'))(lang)
win.webContents.send(event, i18n.asObject().Deficiency)
break
default:
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = (browsers, sharedObject) => ({
main: require('./main')(browsers, sharedObject),
about: require('./about')(browsers, sharedObject),
deficiency: require('./deficiency')(browsers, sharedObject),
preferences: require('./preferences')(browsers, sharedObject),
module.exports = (browsers, preferences) => ({
main: require('./main')(browsers, preferences),
about: require('./about')(browsers, preferences),
deficiency: require('./deficiency')(browsers, preferences),
preferences: require('./preferences')(browsers, preferences),
})
14 changes: 8 additions & 6 deletions src/controllers/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const {ipcMain} = require('electron')

module.exports = (browsers, sharedObject) => {
module.exports = (browsers, preferences) => {
const {main} = browsers
ipcMain.on('init-app', () => {
const i18n = new(require('../i18n'))(sharedObject.preferences.main.lang)
ipcMain.on('init-app', async () => {
const lang = await preferences.get('main.lang')
const i18n = new(require('../i18n'))(lang)
let config = {
i18n: i18n.asObject().Main
}
Expand All @@ -14,14 +15,15 @@ module.exports = (browsers, sharedObject) => {
main.changeSize(null, height)
})

let sendEvent = (event, ...params) => {
let sendEvent = async (event, ...params) => {
const win = main.getWindow()
if (win) {

switch(event) {
case 'langChanged':
const i18n = new(require('../i18n'))(sharedObject.preferences.main.lang)
win.webContents.send(event, i18n.asObject().Main)
const lang = await preferences.get('main.lang')
const i18n = new(require('../i18n'))(lang)
win.webContents.send(event, i18n.asObject().Main)
break
default:
win.webContents.send(event, ...params)
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/preferences.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const {ipcMain, app} = require('electron')

module.exports = (browsers, sharedObject) => {
module.exports = (browsers, prefs) => {
const {preferences} = browsers
ipcMain.on('init-preferences', () => {
const i18n = new(require('../i18n'))(sharedObject.preferences.main.lang)
const i18n = new(require('../i18n'))(prefs.get('main.lang'))
let config = {
i18n: i18n.asObject().Preferences
}
Expand Down
71 changes: 71 additions & 0 deletions src/globalStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Preferences structure
// main : {
// position : {
// x,
// y,
// },
// rounding,
// alwaysOnTop,
// lang
// },
// foreground : {
// format,
// picker : {
// shortcut
// },
// sliders : {
// open,
// tab
// }
// },
// background : {
// format,
// picker : {
// shortcut
// },
// sliders : {
// open,
// tab
// }
// }

const defaults = {
'main.checkForUpdates': false,
'main.lang': 'auto',
'main.checkForUpdates': false,
'main.rounding': 1,
'main.alwaysOnTop': true,
'main.lang': 'auto',
'foreground.format': 'hex',
'background.format': 'hex',
'foreground.picker.shortcut': 'F11',
'background.picker.shortcut': 'F12',
'foreground.sliders.open': false,
'background.sliders.open': false,
'foreground.sliders.tab': 'rgb',
'background.sliders.tab': 'rgb',
}

function GlobalStorage(win) {
if (win) {
this.storage = win.localStorage;
} else {
const { localStorage } = require('electron-browser-storage');
this.storage = localStorage
}
}

GlobalStorage.prototype = {
get: async function (name) {
let value = await this.storage.getItem(name)
if (value === null && name in defaults) {
value = defaults[name]
}
return value
},
set: function (name, value) {
this.storage.setItem(name, value)
}
}

module.exports = GlobalStorage;
Loading

0 comments on commit f5ef6a6

Please sign in to comment.