Skip to content

Commit

Permalink
feat: export via plutoDesktop
Browse files Browse the repository at this point in the history
  • Loading branch information
Illusion47586 committed Jul 8, 2022
1 parent 04a5de6 commit 43925bc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/main/baseEventListeners.ts
@@ -1,6 +1,12 @@
import { app, ipcMain } from 'electron';
import log from 'electron-log';
import { moveNotebook, openNotebook, shutdownNotebook } from './pluto';
import { PlutoExport } from '../../types/enums';
import {
exportNotebook,
moveNotebook,
openNotebook,
shutdownNotebook,
} from './pluto';

app.on('open-url', (_, url) => {
log.info(`Url changed to ${url}`);
Expand All @@ -24,3 +30,10 @@ ipcMain.on(
_event.sender.send('PLUTO-MOVE-NOTEBOOK', loc);
}
);

ipcMain.on(
'PLUTO-EXPORT-NOTEBOOK',
async (_event, id: string, type: PlutoExport): Promise<void> => {
await exportNotebook(id, type);
}
);
4 changes: 4 additions & 0 deletions src/main/preload.ts
@@ -1,4 +1,5 @@
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';
import { PlutoExport } from '../../types/enums';

export type Channels = 'ipc-example';

Expand Down Expand Up @@ -28,5 +29,8 @@ contextBridge.exposeInMainWorld('plutoDesktop', {
moveNotebook(id?: string) {
ipcRenderer.send('PLUTO-MOVE-NOTEBOOK', id);
},
exportNotebook(id: string, type: PlutoExport) {
ipcRenderer.send('PLUTO-EXPORT-NOTEBOOK', id, type);
},
},
});
2 changes: 2 additions & 0 deletions src/renderer/preload.d.ts
@@ -1,4 +1,5 @@
import { Channels } from 'main/preload';
import { PlutoExport } from '../../types/enums';

declare global {
interface Window {
Expand All @@ -21,6 +22,7 @@ declare global {
openNotebook(path?: string, forceNew?: boolean): void;
shutdownNotebook(id?: string): void;
moveNotebook(id?: string): void;
exportNotebook(id: string, type: PlutoExport): void;
};
};
}
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/useElectron.tsx
Expand Up @@ -24,7 +24,13 @@ const useElectron = (callback?: (window: Window) => void) => {
};
}, [callback]);

return isDesktop;
const conditionalCallback = (execute: () => void, fallback: () => void) => {
if (isDesktop) {
execute();
} else if (fallback) fallback();
};

return { isDesktop, conditionalCallback };
};

export default useElectron;

0 comments on commit 43925bc

Please sign in to comment.