Skip to content

Commit

Permalink
fix: Move mixxing dependency logic to main process
Browse files Browse the repository at this point in the history
  • Loading branch information
erdkse committed Oct 13, 2021
1 parent 4a8e649 commit 681f932
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 44 deletions.
27 changes: 12 additions & 15 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {createMenu, getDockMenu} from './menu';
import initKubeconfig from './src/initKubeconfig';
import terminal from '../cli/terminal';
import {downloadPlugin} from './pluginService';
import {AlertEnum, AlertType} from '@models/alert';
import {setAlert} from '@redux/reducers/alert';

Object.assign(console, ElectronLog.functions);
autoUpdater.logger = console;
Expand Down Expand Up @@ -88,13 +90,6 @@ ipcMain.on('run-kustomize', (event, folder: string) => {
}
});

ipcMain.on('check-missing-dependency', event => {
const missingDependecies = checkMissingDependencies(APP_DEPENDENCIES);
if (missingDependecies.length > 0) {
event.sender.send('missing-dependency-result', {dependencies: missingDependecies});
}
});

ipcMain.handle('select-file', async (event, options: any) => {
const browserWindow = BrowserWindow.fromId(event.sender.id);
let dialogOptions: Electron.OpenDialogSyncOptions = {};
Expand Down Expand Up @@ -246,17 +241,19 @@ export const createWindow = (givenPath?: string) => {
mainStore.dispatch(updateNewVersion({code: NewVersionCode.Downloaded, data: null}));
});

const missingDependecies = checkMissingDependencies(APP_DEPENDENCIES);

if (missingDependecies.length > 0) {
win.webContents.on('did-finish-load', () => {
win.webContents.send('missing-dependency-result', {dependencies: missingDependecies});
});
}

win.webContents.on('did-finish-load', async () => {
await checkNewVersion(true);
initKubeconfig(mainStore, userHomeDir);
const missingDependecies = checkMissingDependencies(APP_DEPENDENCIES);

if (missingDependecies.length > 0) {
const alert: AlertType = {
type: AlertEnum.Warning,
title: 'Missing dependency',
message: `${missingDependecies.toString()} must be installed for all Monokle functionality to be available`,
};
mainStore.dispatch(setAlert(alert));
}
win.webContents.send('executed-from', {path: givenPath});
});

Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

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

26 changes: 1 addition & 25 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useEffect} from 'react';
import React from 'react';
import 'antd/dist/antd.less';
import {Layout} from '@atoms';
import {
Expand All @@ -15,39 +15,15 @@ import {
} from '@organisms';
import {Size} from '@models/window';
import {useWindowSize} from '@utils/hooks';
import {useAppDispatch} from '@redux/hooks';
import {ipcRenderer} from 'electron';
import {setAlert} from '@redux/reducers/alert';
import {AlertEnum, AlertType} from '@models/alert';
import ValidationErrorsModal from '@components/molecules/ValidationErrorsModal';
import UpdateModal from '@components/organisms/UpdateModal';
import AppContext from './AppContext';

const App = () => {
const dispatch = useAppDispatch();
const size: Size = useWindowSize();

const mainHeight = `${size.height}px`;

const onMissingDependencyResult = useCallback(
(_, {dependencies}) => {
const alert: AlertType = {
type: AlertEnum.Warning,
title: 'Missing dependency',
message: `${dependencies.toString()} must be installed for all Monokle functionality to be available`,
};
dispatch(setAlert(alert));
},
[dispatch]
);

useEffect(() => {
ipcRenderer.on('missing-dependency-result', onMissingDependencyResult);
return () => {
ipcRenderer.removeListener('missing-dependency-result', onMissingDependencyResult);
};
}, [onMissingDependencyResult]);

return (
<AppContext.Provider value={{windowSize: size}}>
<div style={{overflowY: 'hidden'}}>
Expand Down
2 changes: 0 additions & 2 deletions src/redux/thunks/previewCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ const previewClusterHandler = async (configPath: string, thunkAPI: any) => {
type: AlertEnum.Warning,
};

console.log('previewResult1', previewResult);
return previewResult;
}
}
console.log('previewResult2', previewResult);
return previewResult;
},
reason => {
Expand Down

0 comments on commit 681f932

Please sign in to comment.