FreeDATA/gui_vue/electron/main.ts
2023-10-03 21:04:37 +02:00

95 lines
2.4 KiB
TypeScript

import { app, BrowserWindow, ipcMain } from 'electron'
import path from 'node:path'
// pinia store setup
import { setActivePinia } from "pinia";
import pinia from "../store/index";
setActivePinia(pinia);
import { useSettingsStore } from "../store/settingsStore.js";
const settings = useSettingsStore(pinia);
//import { useIpcRenderer } from '@vueuse/electron'
//const ipcRenderer = useIpcRenderer()
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
// The built directory structure
//
// ├─┬─┬ dist
// │ │ └── index.html
// │ │
// │ ├─┬ dist-electron
// │ │ ├── main.js
// │ │ └── preload.js
// │
process.env.DIST = path.join(__dirname, '../dist')
process.env.PUBLIC = app.isPackaged ? process.env.DIST : path.join(process.env.DIST, '../public')
let win: BrowserWindow | null
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - Vite@2.x
const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL']
function createWindow() {
win = new BrowserWindow({
icon: path.join(process.env.PUBLIC, 'icon_cube_border.png'),
//webPreferences: {
// preload: path.join(__dirname, 'preload.js'),
//},
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
//preload: path.join(__dirname, 'preload-main.js'),
backgroundThrottle: false,
//preload: require.resolve("preload-main.js"),
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: false,
sandbox: false,
//https://stackoverflow.com/questions/53390798/opening-new-window-electron/53393655
//https://github.com/electron/remote
},
})
win.setMenuBarVisibility(false);
// Test active push message to Renderer-process.
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', (new Date).toLocaleString())
})
win.once("ready-to-show", () => {
console.log(settings.update_channel)
autoUpdater.channel = settings.update_channel;
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.autoDownload = true;
autoUpdater.checkForUpdatesAndNotify();
//autoUpdater.quitAndInstall();
});
if (VITE_DEV_SERVER_URL) {
win.loadURL(VITE_DEV_SERVER_URL)
} else {
// win.loadFile('dist/index.html')
win.loadFile(path.join(process.env.DIST, 'index.html'))
}
}
app.on('window-all-closed', () => {
win = null
})
app.whenReady().then(createWindow)