Merge pull request #3 from daaanny90/dark-mode

Dark mode
This commit is contained in:
Nicco 2020-03-04 19:33:47 +01:00 committed by GitHub
commit bdbb27966a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 13 deletions

View File

@ -11,12 +11,13 @@
"start": "electron ." "start": "electron ."
}, },
"devDependencies": { "devDependencies": {
"electron": "^2", "electron": "^7",
"electron-builder": "^20" "electron-builder": "^20"
}, },
"dependencies": { "dependencies": {
"auto-launch": "^5", "auto-launch": "^5",
"battery-level": "^3", "battery-level": "^3",
"dark-mode": "^3.0.0",
"electron-settings": "^3" "electron-settings": "^3"
} }
} }

BIN
src/battery_dark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -27,7 +27,16 @@ body,
width: 100%; width: 100%;
padding: 0; padding: 0;
margin: 0; margin: 0;
}
#app.dark {
background: #333;
color: #f2f2f2;
}
#app.light {
background: #F7FFF7; background: #F7FFF7;
color: #3B252C;
} }
hr { hr {

View File

@ -3,6 +3,7 @@ const {
shell, shell,
remote remote
} = require('electron') } = require('electron')
const darkMode = require('dark-mode')
let rangeSlider let rangeSlider
let autoLaunch let autoLaunch
@ -14,6 +15,14 @@ document.addEventListener('DOMContentLoaded', () => {
document.getElementById('close').addEventListener('click', () => { document.getElementById('close').addEventListener('click', () => {
remote.getCurrentWindow().hide() remote.getCurrentWindow().hide()
}) })
darkMode.isDark().then((dark) => {
if (dark) {
document.querySelector('#app').classList.add('dark')
} else {
document.querySelector('#app').classList.add('light')
}
})
}) })
function iniSlider() { function iniSlider() {

View File

@ -4,6 +4,7 @@ const {
ipcMain, ipcMain,
Tray, Tray,
nativeImage, nativeImage,
nativeTheme,
Notification, Notification,
electron electron
} = require('electron') } = require('electron')
@ -40,17 +41,32 @@ app.on('window-all-closed', () => {
app.quit() app.quit()
}) })
const createTray = () => { const createIcon = (image) => {
const icon = nativeImage.createFromPath(path.join(__dirname, 'battery.png')).resize({ return nativeImage.createFromPath(path.join(__dirname, image)).resize({
width: 24, width: 24,
height: 24 height: 24
}) })
}
const createTray = () => {
let icon
if (nativeTheme.shouldUseDarkColors) {
icon = createIcon('battery_dark.png')
} else {
icon = createIcon('battery_light.png')
}
tray = new Tray(icon) tray = new Tray(icon)
tray.on('right-click', toggleWindow) tray.on('right-click', toggleWindow)
tray.on('double-click', toggleWindow) tray.on('double-click', toggleWindow)
tray.on('click', toggleWindow) tray.on('click', toggleWindow)
} }
nativeTheme.on('updated', function() {
tray.destroy()
createTray()
window.reload()
})
const getWindowPosition = () => { const getWindowPosition = () => {
const windowBounds = window.getBounds() const windowBounds = window.getBounds()
const trayBounds = tray.getBounds() const trayBounds = tray.getBounds()
@ -72,7 +88,10 @@ const createWindow = () => {
frame: false, frame: false,
fullscreenable: false, fullscreenable: false,
resizable: false, resizable: false,
transparent: true transparent: true,
webPreferences: {
nodeIntegration: true
}
}) })
window.loadURL(`file://${path.join(__dirname, 'index.html')}`) window.loadURL(`file://${path.join(__dirname, 'index.html')}`)
@ -81,10 +100,6 @@ const createWindow = () => {
}) })
window.webContents.on('did-finish-load', sendCurrentValues) window.webContents.on('did-finish-load', sendCurrentValues)
// window.openDevTools({
// mode: 'detach'
// })
} }
const toggleWindow = () => { const toggleWindow = () => {