mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 04:43:35 +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 { useCallback, useEffect } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { addDialog } from '../stores/dialogStore';
|
||||||
|
|
||||||
const isElectron = window.process?.type === 'renderer';
|
const isElectron = window.process?.type === 'renderer';
|
||||||
const ipcRenderer = isElectron ? window.require('electron').ipcRenderer : null;
|
const ipcRenderer = isElectron ? window.require('electron').ipcRenderer : null;
|
||||||
|
|
||||||
@@ -24,6 +26,12 @@ export function useElectronListener() {
|
|||||||
ipcRenderer.on('request-editor-location', (_event: unknown, location: string) => {
|
ipcRenderer.on('request-editor-location', (_event: unknown, location: string) => {
|
||||||
navigate(location, { relative: 'route' });
|
navigate(location, { relative: 'route' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcRenderer.on('dialog', (_event: unknown, dialog: string) => {
|
||||||
|
if (dialog === 'welcome') {
|
||||||
|
addDialog('welcome');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean the listener after the component is dismounted
|
// Clean the listener after the component is dismounted
|
||||||
|
|||||||
@@ -114,13 +114,21 @@ function escalateError(error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows electron to ask react app redirect
|
* Allows electron to ask the react app to redirect
|
||||||
* @param string location
|
* @param {string} location
|
||||||
*/
|
*/
|
||||||
function redirectWindow(location) {
|
function redirectWindow(location) {
|
||||||
win.webContents.send('request-editor-location', 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
|
// Ensure there isn't another instance of the app running already
|
||||||
const lock = app.requestSingleInstanceLock();
|
const lock = app.requestSingleInstanceLock();
|
||||||
if (!lock) {
|
if (!lock) {
|
||||||
@@ -190,7 +198,7 @@ app.whenReady().then(() => {
|
|||||||
.then((port) => {
|
.then((port) => {
|
||||||
const clientUrl = getClientUrl(port);
|
const clientUrl = getClientUrl(port);
|
||||||
const serverUrl = getServerUrl(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),
|
win.webContents.downloadURL(url),
|
||||||
);
|
);
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
|
|||||||
@@ -21,13 +21,14 @@ const {
|
|||||||
* @param {string} clientUrl - base url for the application
|
* @param {string} clientUrl - base url for the application
|
||||||
* @param {string} serverUrl - base url for the application
|
* @param {string} serverUrl - base url for the application
|
||||||
* @param {function} redirectWindow - function to redirect main window content
|
* @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
|
* @param {function} download - function to download a resource from url
|
||||||
* @returns {Menu} - application menu
|
* @returns {Menu} - application menu
|
||||||
*/
|
*/
|
||||||
function getApplicationMenu(askToQuit, clientUrl, serverUrl, redirectWindow, download) {
|
function getApplicationMenu(askToQuit, clientUrl, serverUrl, redirectWindow, showDialog, download) {
|
||||||
const template = [
|
const template = [
|
||||||
...(isMac ? [makeMacMenu(askToQuit)] : []),
|
...(isMac ? [makeMacMenu(askToQuit)] : []),
|
||||||
makeFileMenu(serverUrl, redirectWindow, download),
|
makeFileMenu(serverUrl, redirectWindow, showDialog, download),
|
||||||
makeViewMenu(clientUrl),
|
makeViewMenu(clientUrl),
|
||||||
makeSettingsMenu(redirectWindow),
|
makeSettingsMenu(redirectWindow),
|
||||||
makeHelpMenu(redirectWindow),
|
makeHelpMenu(redirectWindow),
|
||||||
@@ -53,7 +54,7 @@ function makeMacMenu(askToQuit) {
|
|||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: 'Quit',
|
label: 'Quit',
|
||||||
click: () => askToQuit(),
|
click: askToQuit,
|
||||||
accelerator: isMac ? 'Cmd+Q' : 'Alt+F4',
|
accelerator: isMac ? 'Cmd+Q' : 'Alt+F4',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -64,10 +65,11 @@ function makeMacMenu(askToQuit) {
|
|||||||
* Utility function generates the file menu
|
* Utility function generates the file menu
|
||||||
* @param {string} serverUrl - base url for the application
|
* @param {string} serverUrl - base url for the application
|
||||||
* @param {function} redirectWindow - function to redirect main window content
|
* @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
|
* @param {function} download - function to download a resource from url
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
function makeFileMenu(serverUrl, redirectWindow, download) {
|
function makeFileMenu(serverUrl, redirectWindow, showDialog, download) {
|
||||||
const downloadProject = () => {
|
const downloadProject = () => {
|
||||||
try {
|
try {
|
||||||
download(serverUrl + downloadPath);
|
download(serverUrl + downloadPath);
|
||||||
@@ -83,6 +85,10 @@ function makeFileMenu(serverUrl, redirectWindow, download) {
|
|||||||
label: 'New project...',
|
label: 'New project...',
|
||||||
click: () => redirectWindow('/editor?settings=project__manage&new=true'),
|
click: () => redirectWindow('/editor?settings=project__manage&new=true'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Load...',
|
||||||
|
click: () => showDialog('welcome'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Quick start...',
|
label: 'Quick start...',
|
||||||
click: () => redirectWindow('/editor?settings=project__create'),
|
click: () => redirectWindow('/editor?settings=project__create'),
|
||||||
|
|||||||
Reference in New Issue
Block a user