mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-04 06:58:02 +00:00
feat: trigger welcome modal from electron
This commit is contained in:
committed by
Carlos Valente
parent
22fe65c655
commit
b4eabfae72
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user