diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 2e72b66..7968297 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,6 +1,6 @@ module.exports = { root: true, - env: { node: true, es2020: true }, + env: { node: true, browser: true, es2020: true }, extends: [ 'eslint:recommended', 'plugin:react/recommended', @@ -16,5 +16,6 @@ module.exports = { 'warn', { allowConstantExport: true }, ], + 'react/prop-types': 'off', }, } diff --git a/dev-app-update.yml b/dev-app-update.yml new file mode 100644 index 0000000..320007f --- /dev/null +++ b/dev-app-update.yml @@ -0,0 +1,3 @@ +owner: lambor590 +repo: Packager +provider: github \ No newline at end of file diff --git a/electron/main/index.js b/electron/main/index.js index 8f22236..025ddef 100644 --- a/electron/main/index.js +++ b/electron/main/index.js @@ -29,8 +29,11 @@ const indexHtml = join(process.env.DIST, 'index.html') async function createWindow() { win = new BrowserWindow({ - title: 'Main window', + title: 'Packager', icon: join(process.env.VITE_PUBLIC, 'favicon.ico'), + width: 1200, + height: 720, + autoHideMenuBar: true, webPreferences: { preload, nodeIntegration: true, @@ -46,23 +49,16 @@ async function createWindow() { win.loadFile(indexHtml) } - // Test actively push message to the Electron-Renderer - win.webContents.on('did-finish-load', () => { - win?.webContents.send('main-process-message', new Date().toLocaleString()) - }) - // Make all links open with the browser, not with the application win.webContents.setWindowOpenHandler(({ url }) => { if (url.startsWith('https:')) shell.openExternal(url) return { action: 'deny' } }) - - // Apply electron-updater - update(win) } app.whenReady().then(createWindow) + app.on('window-all-closed', () => { win = null if (process.platform !== 'darwin') app.quit() @@ -85,20 +81,16 @@ app.on('activate', () => { } }) -// New window example arg: new windows url -ipcMain.handle('open-win', (_, arg) => { - const childWindow = new BrowserWindow({ - webPreferences: { - preload, - nodeIntegration: true, - contextIsolation: false, - }, - }) - - if (process.env.VITE_DEV_SERVER_URL) { - childWindow.loadURL(`${url}#${arg}`) - } else { - childWindow.loadFile(indexHtml, { hash: arg }) - } +ipcMain.handle("get-app-version", () => { + return app.getVersion() }) +ipcMain.on("do-action", (event, arg, data) => { + switch (arg) { + case "initAutoUpdater": + update(event) + break + default: + break + } +}) \ No newline at end of file diff --git a/electron/main/update.js b/electron/main/update.js index 090a0fa..c56f4c3 100644 --- a/electron/main/update.js +++ b/electron/main/update.js @@ -1,66 +1,24 @@ -import { app, ipcMain } from 'electron' import { autoUpdater } from 'electron-updater' -export function update(win) { +export function update(event) { - // When set to false, the update download will be triggered through the API - autoUpdater.autoDownload = false - autoUpdater.disableWebInstaller = false + autoUpdater.autoDownload = true autoUpdater.allowDowngrade = false + autoUpdater.disableWebInstaller = true + autoUpdater.autoInstallOnAppQuit = true + autoUpdater.forceDevUpdateConfig = true - // start check - autoUpdater.on('checking-for-update', function () { }) - // update available - autoUpdater.on('update-available', (arg) => { - win.webContents.send('update-can-available', { update: true, version: app.getVersion(), newVersion: arg?.version }) + autoUpdater.on('update-available', (_event) => { + event.sender.send('update-available', _event) }) - // update not available - autoUpdater.on('update-not-available', (arg) => { - win.webContents.send('update-can-available', { update: false, version: app.getVersion(), newVersion: arg?.version }) - }) - - // Checking for updates - ipcMain.handle('check-update', async () => { - if (!app.isPackaged) { - const error = new Error('The update feature is only available after the package.') - return { message: error.message, error } - } - try { - return await autoUpdater.checkForUpdatesAndNotify() - } catch (error) { - return { message: 'Network error', error } - } + autoUpdater.on('download-progress', (_event, progressInfo) => { + event.sender.send('download-progress', _event, progressInfo) }) - // Start downloading and feedback on progress - ipcMain.handle('start-download', (event) => { - startDownload( - (error, progressInfo) => { - if (error) { - // feedback download error message - event.sender.send('update-error', { message: error.message, error }) - } else { - // feedback update progress message - event.sender.send('download-progress', progressInfo) - } - }, - () => { - // feedback update downloaded message - event.sender.send('update-downloaded') - } - ) - }) - - // Install now - ipcMain.handle('quit-and-install', () => { - autoUpdater.quitAndInstall(false, true) - }) -} + autoUpdater.on('update-downloaded', () => { + autoUpdater.quitAndInstall(true, true) + }); -function startDownload(callback, complete) { - autoUpdater.on('download-progress', info => callback(null, info)) - autoUpdater.on('error', error => callback(error, null)) - autoUpdater.on('update-downloaded', complete) - autoUpdater.downloadUpdate() -} + autoUpdater.checkForUpdates() +} \ No newline at end of file diff --git a/index.html b/index.html index caf31aa..f8ed9a4 100644 --- a/index.html +++ b/index.html @@ -1,13 +1,16 @@ -
- - - -