Add setup window on first app launch

This commit is contained in:
TheThomaas 2026-01-26 14:16:56 +01:00
parent c6a5731a88
commit 22a81c1058

View file

@ -3,12 +3,21 @@ import { join } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils' import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import icon from '../../resources/icon.png?asset' import icon from '../../resources/icon.png?asset'
import { autoUpdater } from 'electron-updater' import { autoUpdater } from 'electron-updater'
import Store from './lib/Store'
autoUpdater.autoDownload = false; autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = true; autoUpdater.autoInstallOnAppQuit = true;
const store = new Store({
configName: 'user-preferences',
defaults: {
showSetupWindow: true
}
});
let mainWindow: BrowserWindow; let mainWindow: BrowserWindow;
let splashWindow: BrowserWindow; let splashWindow: BrowserWindow;
let setupWindow: BrowserWindow;
function createSplashWindow(): void { function createSplashWindow(): void {
splashWindow = new BrowserWindow({ splashWindow = new BrowserWindow({
@ -24,7 +33,22 @@ function createSplashWindow(): void {
splashWindow.show(); splashWindow.show();
} }
function createWindow(): void { function createSetupWindow(): void {
setupWindow = new BrowserWindow({
width: 380,
height: 390,
show: false,
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
sandbox: false
},
});
setupWindow.loadFile('src/renderer/setup.html');
}
function createMainWindow(): void {
// Create the browser window. // Create the browser window.
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
width: 900, width: 900,
@ -38,20 +62,6 @@ function createWindow(): void {
} }
}) })
createSplashWindow();
mainWindow.on('ready-to-show', () => {
if (is.dev) {
setTimeout((): void => {
splashWindow.close();
mainWindow.show();
}, 2000);
} else {
splashWindow.close();
mainWindow.show();
}
})
mainWindow.webContents.setWindowOpenHandler((details) => { mainWindow.webContents.setWindowOpenHandler((details) => {
shell.openExternal(details.url) shell.openExternal(details.url)
return { action: 'deny' } return { action: 'deny' }
@ -66,6 +76,35 @@ function createWindow(): void {
} }
} }
function finishSetup(): void {
store.set('showSetupWindow', false);
createMainWindow();
mainWindow.on('ready-to-show', () => {
mainWindow.show();
setupWindow.close();
})
}
function createWindow(): void {
createSplashWindow();
let showSetupWindow = store.get('showSetupWindow');
if (showSetupWindow) {
createSetupWindow();
setupWindow.on('ready-to-show', () => {
splashWindow.close();
setupWindow.show();
})
} else {
createMainWindow();
mainWindow.on('ready-to-show', () => {
splashWindow.close();
mainWindow.show();
})
}
}
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
@ -82,6 +121,7 @@ app.whenReady().then(() => {
// IPC test // IPC test
ipcMain.on('ping', () => console.log('pong')) ipcMain.on('ping', () => console.log('pong'))
ipcMain.on('finish-setup', () => finishSetup())
ipcMain.handle('get-version', () => app.getVersion()) ipcMain.handle('get-version', () => app.getVersion())