diff --git a/apps/client/src/common/hooks/useElectronEvent.ts b/apps/client/src/common/hooks/useElectronEvent.ts index 93d03b0e7..503b858f3 100644 --- a/apps/client/src/common/hooks/useElectronEvent.ts +++ b/apps/client/src/common/hooks/useElectronEvent.ts @@ -1,6 +1,8 @@ import { useCallback, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; +import { addDialog } from '../stores/dialogStore'; + const isElectron = window.process?.type === 'renderer'; const ipcRenderer = isElectron ? window.require('electron').ipcRenderer : null; @@ -24,6 +26,12 @@ export function useElectronListener() { ipcRenderer.on('request-editor-location', (_event: unknown, location: string) => { navigate(location, { relative: 'route' }); }); + + ipcRenderer.on('dialog', (_event: unknown, dialog: string) => { + if (dialog === 'welcome') { + addDialog('welcome'); + } + }); } // Clean the listener after the component is dismounted diff --git a/apps/electron/src/main.js b/apps/electron/src/main.js index 9cadd2ad0..8741afdeb 100644 --- a/apps/electron/src/main.js +++ b/apps/electron/src/main.js @@ -114,13 +114,21 @@ function escalateError(error) { } /** - * Allows electron to ask react app redirect - * @param string location + * Allows electron to ask the react app to redirect + * @param {string} location */ function redirectWindow(location) { win.webContents.send('request-editor-location', location); } +/** + * Asks the react app to show a user dialog + * @param {string} name + */ +function showDialog(name) { + win.webContents.send('dialog', name); +} + // Ensure there isn't another instance of the app running already const lock = app.requestSingleInstanceLock(); if (!lock) { @@ -190,7 +198,7 @@ app.whenReady().then(() => { .then((port) => { const clientUrl = getClientUrl(port); const serverUrl = getServerUrl(port); - const menu = getApplicationMenu(askToQuit, clientUrl, serverUrl, redirectWindow, (url) => + const menu = getApplicationMenu(askToQuit, clientUrl, serverUrl, redirectWindow, showDialog, (url) => win.webContents.downloadURL(url), ); Menu.setApplicationMenu(menu); diff --git a/apps/electron/src/menu/applicationMenu.js b/apps/electron/src/menu/applicationMenu.js index f3613c1c0..a5d9f2682 100644 --- a/apps/electron/src/menu/applicationMenu.js +++ b/apps/electron/src/menu/applicationMenu.js @@ -21,13 +21,14 @@ const { * @param {string} clientUrl - base url for the application * @param {string} serverUrl - base url for the application * @param {function} redirectWindow - function to redirect main window content + * @param {function} showDialog - asks the react app to show a user dialog * @param {function} download - function to download a resource from url * @returns {Menu} - application menu */ -function getApplicationMenu(askToQuit, clientUrl, serverUrl, redirectWindow, download) { +function getApplicationMenu(askToQuit, clientUrl, serverUrl, redirectWindow, showDialog, download) { const template = [ ...(isMac ? [makeMacMenu(askToQuit)] : []), - makeFileMenu(serverUrl, redirectWindow, download), + makeFileMenu(serverUrl, redirectWindow, showDialog, download), makeViewMenu(clientUrl), makeSettingsMenu(redirectWindow), makeHelpMenu(redirectWindow), @@ -53,7 +54,7 @@ function makeMacMenu(askToQuit) { { type: 'separator' }, { label: 'Quit', - click: () => askToQuit(), + click: askToQuit, accelerator: isMac ? 'Cmd+Q' : 'Alt+F4', }, ], @@ -64,10 +65,11 @@ function makeMacMenu(askToQuit) { * Utility function generates the file menu * @param {string} serverUrl - base url for the application * @param {function} redirectWindow - function to redirect main window content + * @param {function} showDialog - asks the react app to show a user dialog * @param {function} download - function to download a resource from url * @returns {Object} */ -function makeFileMenu(serverUrl, redirectWindow, download) { +function makeFileMenu(serverUrl, redirectWindow, showDialog, download) { const downloadProject = () => { try { download(serverUrl + downloadPath); @@ -83,6 +85,10 @@ function makeFileMenu(serverUrl, redirectWindow, download) { label: 'New project...', click: () => redirectWindow('/editor?settings=project__manage&new=true'), }, + { + label: 'Load...', + click: () => showDialog('welcome'), + }, { label: 'Quick start...', click: () => redirectWindow('/editor?settings=project__create'),