Skip to content

Commit

Permalink
Fix Electron related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mborik committed Nov 19, 2022
1 parent 9622743 commit 6036b7e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
8 changes: 1 addition & 7 deletions electron.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
"buildResources": "assets/resources",
"output": "dist"
},
"extraFiles": [
{
"from": "assets/scripts",
"to": "."
}
],
"files": [
"!**/.*",
"!{electron.json,webpack.config.js,tsconfig.json}",
Expand Down Expand Up @@ -43,7 +37,7 @@
]
},
"appImage": {
"artifactName": "${productName}-${version}-${env.ELECTRON_BUILDER_ARCHITECTURE}.${ext}"
"artifactName": "${productName}-${version}-${arch}.${ext}"
},
"rpm": {
"depends": ["util-linux"]
Expand Down
12 changes: 8 additions & 4 deletions electron/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const { app, BrowserWindow, nativeImage, ipcMain } = require('electron');
const { app, ipcMain, BrowserWindow, nativeImage, session } = require('electron');
const meow = require('meow');
const { squirrel } = require('./squirrel');
const { createWindow } = require('./window');
Expand Down Expand Up @@ -78,9 +78,13 @@ if (squirrel(cli.flags, app.quit)) {
}
});

ipcMain.handle('close', () => mainWindow?.close());
ipcMain.handle('clear-cache', () => {
mainWindow?.webContents.session.clearStorageData({
ipcMain.handle('relaunch', () => {
app.relaunch();
app.quit();
});
ipcMain.handle('clear-cache', async () => {
await session.defaultSession.clearCache();
await session.defaultSession.clearStorageData({
storages: ['appcache', 'serviceworkers', 'cachestorage']
});
});
Expand Down
2 changes: 1 addition & 1 deletion electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('electron', {
version: process.versions.electron,
close: () => ipcRenderer.invoke('close'),
relaunch: () => ipcRenderer.invoke('relaunch'),
clearCache: () => ipcRenderer.invoke('clear-cache'),
});
2 changes: 1 addition & 1 deletion electron/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const { BrowserWindow } = require('electron');
const WindowState = require('electron-window-state');

const minBounds = { w: 1152, h: 690 };
const minBounds = { w: 1152, h: 720 };

const createWindow = (title, devTools) => {
const windowState = WindowState({
Expand Down
2 changes: 1 addition & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare interface Window {
electron?: {
version: string;
close: () => void;
relaunch: () => void;
clearCache: () => void;
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/tracker/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ Tracker.prototype.onCmdAppUpdate = function() {
document.body.className = 'loading';
this.destroying = true;

window.electron?.clearCache();
setTimeout(() => {
window.electron?.clearCache();
window.electron?.close();
window.electron?.relaunch();
}, 1024);
}
}
Expand Down

0 comments on commit 6036b7e

Please sign in to comment.