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',
config: 'vite.renderer.config.mjs',
},
{
name: 'settings_window',
config: 'vite.settings.config.mjs',
}
],
},
},

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta charset="UTF-8">
<title>ED Safari v0.0.1</title>
</head>
<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,33 +1,51 @@
const { app, BrowserWindow } = require('electron');
const { app, BrowserWindow, Menu } = require('electron');
const path = require('path');
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) {
app.quit();
app.quit();
}
let settingsWindow;
const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 1000,
height: 800,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false,
additionalArguments: [`EDS-ENV=${app.isPackaged}`],
},
});
// and load the index.html of the app.
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
} else {
mainWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`));
}
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 1000,
height: 800,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false,
additionalArguments: [`EDS-ENV=${app.isPackaged}`],
},
});
// and load the index.html of the app.
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
} else {
mainWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`));
}
// Open the DevTools.
if (!app.isPackaged) {
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
@ -39,18 +57,53 @@ app.on('ready', createWindow);
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// 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')
}
}
}
});