Settings window.

This commit is contained in:
punkfairie 2023-05-13 03:20:55 -07:00
parent 60ceaf5450
commit bea31a8131
6 changed files with 118 additions and 33 deletions

View file

@ -44,6 +44,10 @@ module.exports = {
name: 'main_window', name: 'main_window',
config: 'vite.renderer.config.mjs', config: 'vite.renderer.config.mjs',
}, },
{
name: 'settings_window',
config: 'vite.settings.config.mjs',
}
], ],
}, },
}, },

View file

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8">
<title>ED Safari v0.0.1</title> <title>ED Safari v0.0.1</title>
</head> </head>
<body> <body>

11
settings.html Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Settings</title>
</head>
<body>
<h1>Hello World this is settings!</h1>
<script type="module" src="/src/settings.js"></script>
</body>
</html>

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron'); const { app, BrowserWindow, Menu } = require('electron');
const path = require('path'); const path = require('path');
// Handle creating/removing shortcuts on Windows when installing/uninstalling. // Handle creating/removing shortcuts on Windows when installing/uninstalling.
@ -6,6 +6,8 @@ if (require('electron-squirrel-startup')) {
app.quit(); app.quit();
} }
let settingsWindow;
const createWindow = () => { const createWindow = () => {
// Create the browser window. // Create the browser window.
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
@ -27,7 +29,23 @@ const createWindow = () => {
} }
// Open the DevTools. // Open the DevTools.
if (!app.isPackaged) {
mainWindow.webContents.openDevTools(); mainWindow.webContents.openDevTools();
}
// Create the settings window that we can use later.
settingsWindow = new BrowserWindow({
width: 800,
height: 600,
parent: mainWindow,
modal: true,
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
additionalArguments: [`EDS-ENV=${app.isPackaged}`],
},
});
}; };
// This method will be called when Electron has finished // This method will be called when Electron has finished
@ -54,3 +72,38 @@ app.on('activate', () => {
// In this file you can include the rest of your app's specific main process // In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here. // code. You can also put them in separate files and import them here.
const openSettings = async () => {
if (SETTINGS_WINDOW_VITE_DEV_SERVER_URL) {
settingsWindow.loadURL(`${SETTINGS_WINDOW_VITE_DEV_SERVER_URL}/settings.html`);
} else {
settingsWindow.loadFile(path.join(__dirname, `../renderer/${SETTINGS_WINDOW_VITE_NAME}/settings.html`));
}
settingsWindow.show()
}
const menuTemplate = [
{
label: 'File',
submenu: [
{ label: 'Settings', click: async () => { openSettings(); } },
{ role: 'quit' }
]
},
{
role: 'help',
submenu: [
{
label: 'Github',
click: async () => {
const { shell } = require('electron');
await shell.openExternal('https://github.com/punkfairie/ed-safari');
}
}
]
}
]
const menu = Menu.buildFromTemplate(menuTemplate)
Menu.setApplicationMenu(menu)

4
src/settings.js Normal file
View file

@ -0,0 +1,4 @@
import 'bootstrap/dist/css/bootstrap.css'
import './assets/index.css'
import './assets/ldom.min'

13
vite.settings.config.mjs Normal file
View file

@ -0,0 +1,13 @@
import { resolve } from 'path';
import { defineConfig } from 'vite';
// https://vitejs.dev/config
export default defineConfig({
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'settings.html')
}
}
}
});