Skip to content

Commit

Permalink
Refactor: Renderer asks main for default install location. (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinjhuang authored Nov 8, 2024
1 parent ed73db3 commit 834aa5c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
7 changes: 2 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,8 @@ export const createWindow = async (): Promise<BrowserWindow> => {
});

log.info('Loading renderer into main window');
mainWindow.webContents.on('did-finish-load', () => {
if (mainWindow) {
mainWindow.webContents.send(IPC_CHANNELS.DEFAULT_INSTALL_LOCATION, app.getPath('documents'));
}
});

ipcMain.handle(IPC_CHANNELS.DEFAULT_INSTALL_LOCATION, () => app.getPath('documents'));

await loadRendererIntoMainWindow();
log.info('Renderer loaded into main window');
Expand Down
7 changes: 2 additions & 5 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ const electronAPI = {
onFirstTimeSetupComplete: (callback: () => void) => {
ipcRenderer.on(IPC_CHANNELS.FIRST_TIME_SETUP_COMPLETE, () => callback());
},
onDefaultInstallLocation: (callback: (location: string) => void) => {
ipcRenderer.on(IPC_CHANNELS.DEFAULT_INSTALL_LOCATION, (_event, value) => {
console.log(`Received ${IPC_CHANNELS.DEFAULT_INSTALL_LOCATION} event`, value);
callback(value);
});
getDefaultInstallLocation: (): Promise<string> => {
return ipcRenderer.invoke(IPC_CHANNELS.DEFAULT_INSTALL_LOCATION);
},
/**
* Various paths that are useful to the renderer.
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const Home: React.FC = () => {
}, [updateProgress, addLogMessage]);

useEffect(() => {
electronAPI.onDefaultInstallLocation((location: string) => {
electronAPI.getDefaultInstallLocation().then((location: string) => {
setDefaultInstallLocation(location);
});
}, []);
Expand Down

0 comments on commit 834aa5c

Please sign in to comment.