2023-09-05 09:22:00 +00:00
|
|
|
import { app, BrowserWindow, ipcMain } from 'electron'
|
2023-09-02 11:37:03 +00:00
|
|
|
import path from 'node:path'
|
|
|
|
|
2023-09-05 09:22:00 +00:00
|
|
|
|
|
|
|
//import { useIpcRenderer } from '@vueuse/electron'
|
|
|
|
//const ipcRenderer = useIpcRenderer()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
|
|
|
|
|
2023-09-02 11:37:03 +00:00
|
|
|
// 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({
|
2023-09-05 19:06:48 +00:00
|
|
|
icon: path.join(process.env.PUBLIC, 'icon_cube_border.png'),
|
2023-09-02 11:37:03 +00:00
|
|
|
//webPreferences: {
|
|
|
|
// preload: path.join(__dirname, 'preload.js'),
|
|
|
|
//},
|
|
|
|
webPreferences: {
|
2023-09-05 13:28:58 +00:00
|
|
|
preload: path.join(__dirname, 'preload.js'),
|
|
|
|
//preload: path.join(__dirname, 'preload-main.js'),
|
2023-09-02 11:37:03 +00:00
|
|
|
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
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-09-05 19:06:48 +00:00
|
|
|
win.setMenuBarVisibility(false);
|
|
|
|
|
|
|
|
|
2023-09-02 11:37:03 +00:00
|
|
|
// Test active push message to Renderer-process.
|
|
|
|
win.webContents.on('did-finish-load', () => {
|
|
|
|
win?.webContents.send('main-process-message', (new Date).toLocaleString())
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|