├── .gitignore ├── preload.js ├── style.css ├── renderer.js ├── package.json ├── main.js ├── index.html └── menu.js /.gitignore: -------------------------------------------------------------------------------- 1 | package-lock.json 2 | node_modules -------------------------------------------------------------------------------- /preload.js: -------------------------------------------------------------------------------- 1 | const { contextBridge, ipcRenderer } = require('electron') 2 | 3 | contextBridge.exposeInMainWorld('electronAPI', { 4 | onUpdateTheme: (callback) => ipcRenderer.on('update-theme', callback) 5 | }) 6 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --scheme: light dark; 3 | color-scheme: var(--scheme); 4 | } 5 | 6 | body { 7 | margin: 0; 8 | padding: 0; 9 | min-height: 100vh; 10 | display: grid; 11 | place-content: center; 12 | font-family: system-ui; 13 | } -------------------------------------------------------------------------------- /renderer.js: -------------------------------------------------------------------------------- 1 | const $ = selector => document.querySelector(selector) 2 | 3 | const $count = $('#count') 4 | const $button = $('button') 5 | 6 | $button.addEventListener('click', () => { 7 | const count = +$count.innerHTML 8 | $count.innerHTML = (count + 1).toString() 9 | }) 10 | 11 | window.electronAPI.onUpdateTheme((event, theme) => { 12 | const root = document.documentElement 13 | console.log({ theme }) 14 | root.style.setProperty('--scheme', theme) 15 | }) 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-app", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "main.js", 6 | "scripts": { 7 | "dev": "electron .", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "electron": "20.0.3", 15 | "standard": "17.0.0" 16 | }, 17 | "eslintConfig": { 18 | "extends": "standard" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | const { app, BrowserWindow } = require('electron') 2 | const { setMainMenu } = require('./menu.js') 3 | const path = require('path') 4 | 5 | const createWindow = () => { 6 | const mainWindow = new BrowserWindow({ 7 | width: 800, 8 | height: 600, 9 | minWidth: 400, 10 | minHeight: 400, 11 | webPreferences: { 12 | preload: path.join(__dirname, 'preload.js') 13 | } 14 | }) 15 | 16 | mainWindow.loadFile('index.html') 17 | 18 | setMainMenu(mainWindow) 19 | } 20 | 21 | app.whenReady().then(() => { 22 | createWindow() 23 | }) 24 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 12 | 16 | 17 | 18 | 19 |