Skip to content

Commit

Permalink
feat: Add update available logic to store
Browse files Browse the repository at this point in the history
  • Loading branch information
erdkse committed Aug 15, 2021
1 parent 9011693 commit c6fa0d1
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 19 deletions.
37 changes: 27 additions & 10 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import {execSync} from 'child_process';

import {APP_MIN_HEIGHT, APP_MIN_WIDTH} from '../src/constants/constants';

const {autoUpdater} = require('electron-updater'); // Hacky way to fix for `Conflicting definitions for 'node'` error
const electronLog = require('electron-log');
const ElectronStore = require('electron-store');
const {autoUpdater} = require('electron-updater'); // Hacky way to fix for `Conflicting definitions for 'node'` error

Object.assign(console, electronLog.functions);
console.log = electronLog.log;
autoUpdater.logger = electronLog;

const userHomeDir = app.getPath('home');

Expand Down Expand Up @@ -56,13 +61,16 @@ ipcMain.on('run-helm', (event, args: any) => {
}
});

ipcMain.on('app_version', event => {
event.sender.send('app_version', {version: app.getVersion()});
ipcMain.on('app-version', (event, args) => {
electronLog.info('app-version-ipcMain');
console.log('app-version-ipcMain', event, args);
event.sender.send('app-version', {version: app.getVersion()});
});

// ipcMain.on('restart_app', () => {
// autoUpdater.quitAndInstall();
// });
ipcMain.on('quit-and-install', (event, args) => {
electronLog.info('quit-and-install-ipcMain');
// autoUpdater.quitAndInstall();
});

function createWindow() {
const image = nativeImage.createFromPath(path.join(app.getAppPath(), '/public/icon.ico'));
Expand Down Expand Up @@ -114,12 +122,21 @@ function createWindow() {
autoUpdater.checkForUpdatesAndNotify();
});

autoUpdater.on('update-available', () => {
win.webContents.send('update_available');
autoUpdater.on('update-available', (info: any) => {
autoUpdater.logger.info(`update-available-autoUpdater ${info}`);
electronLog.info(`update-available-autoUpdater ${info}`);
win.webContents.send('update-available');
});

autoUpdater.on('download-progress', (progressObj: any) => {
autoUpdater.logger.info(`download-progress-autoUpdater ${JSON.stringify(progressObj)}`);
electronLog.info(`download-progress-autoUpdater ${JSON.stringify(progressObj)}`);
});

autoUpdater.on('update-downloaded', () => {
win.webContents.send('update_downloaded');
autoUpdater.on('update-downloaded', (info: any) => {
autoUpdater.logger.info(`update-available-autoUpdater ${info}`);
electronLog.info(`update-available-autoUpdater ${info}`);
win.webContents.send('update-downloaded');
});

return win;
Expand Down
19 changes: 14 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monokle",
"version": "v1.0.0",
"version": "v0.0.0",
"author": "Kubeshop",
"description": "UI for managing k8s manifests",
"homepage": "./",
Expand Down Expand Up @@ -72,6 +72,7 @@
"dayjs": "^1.10.6",
"electron-devtools-installer": "^3.2.0",
"electron-is-dev": "^2.0.0",
"electron-log": "^4.4.1",
"electron-store": "^8.0.0",
"electron-updater": "^4.3.9",
"es6-tween": "^5.5.11",
Expand Down
29 changes: 26 additions & 3 deletions src/components/organisms/PageFooter/PageFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,34 @@ const StyledFooter = styled(Footer)`
const PageFooter = () => {
const [appVersion, setAppVersion] = useState('');
const [footerText, setFooterText] = useState('');
const [updateAvailable, setUpdateAvailable] = useState(false);
const [updateDownloaded, setUpdateDownloaded] = useState(false);
const fileMap = useAppSelector(state => state.main.fileMap);
const rootEntry = fileMap[ROOT_FILE_ENTRY];

// not counting the root
const nrOfFiles = Object.keys(fileMap).length - 1;

ipcRenderer.send('app_version');
ipcRenderer.on('app_version', (event, {version}) => {
ipcRenderer.removeAllListeners('app_version');
ipcRenderer.send('app-version');
ipcRenderer.once('app-version', (_, {version}) => {
console.log('app-version');
setAppVersion(version);
});

ipcRenderer.once('update-available', () => {
console.log('update-available');
if (!updateAvailable) {
setUpdateAvailable(true);
}
});

ipcRenderer.once('update-downloaded', () => {
console.log('update-downloaded');
if (!updateDownloaded) {
setUpdateDownloaded(true);
}
});

useEffect(() => {
console.log('APP_VERSION', appVersion);
setFooterText(
Expand All @@ -41,6 +57,13 @@ const PageFooter = () => {
);
}, [appVersion]);

useEffect(() => {
if (updateAvailable && updateDownloaded) {
console.log('updateAvailable && updateDownloaded');
ipcRenderer.send('quit-and-install');
}
}, [updateAvailable, updateDownloaded]);

return <StyledFooter noborder="true">{footerText}</StyledFooter>;
};

Expand Down
1 change: 1 addition & 0 deletions src/models/appconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface AppConfig {
navigators: ObjectNavigator[]; // the currrent navigator configuration
kubeconfigPath: string;
isStartupModalVisible: boolean;
isUpdateAvailable: boolean;
settings: {
theme: Themes; // not used for now
textSize: TextSizes; // not used for now
Expand Down
1 change: 1 addition & 0 deletions src/redux/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const initialAppState: AppState = {

const initialAppConfigState: AppConfig = {
isStartupModalVisible: electronStore.get('appConfig.startupModalVisible'),
isUpdateAvailable: false,
kubeconfigPath: '',
settings: {
filterObjectsOnSelection: false,
Expand Down

0 comments on commit c6fa0d1

Please sign in to comment.