From 9256e9b016f536e4c24611c76abc2d67c1b80d18 Mon Sep 17 00:00:00 2001 From: DNLRQ <18170433@itculiacan.edu.mx> Date: Mon, 2 Dec 2024 17:40:00 -0700 Subject: [PATCH] electron utils, missing paths modified for electron --- src/App.jsx | 20 +------------ src/components/EditorHeader/ControlPanel.jsx | 30 ++++++++++++++++---- src/pages/Templates.jsx | 11 +++++++ src/utils/electronUtils.js | 20 +++++++++++++ 4 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 src/utils/electronUtils.js diff --git a/src/App.jsx b/src/App.jsx index b2dc9da8..e4e33bf4 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -9,25 +9,7 @@ import LandingPage from "./pages/LandingPage"; import SettingsContextProvider from "./context/SettingsContext"; import { useSettings } from "./hooks"; import NotFound from "./pages/NotFound"; - -function isElectron() { - if ( - typeof window !== "undefined" && - typeof window.process === "object" && - window.process.type === "renderer" - ) { - return true; - } - if ( - typeof navigator === "object" && - typeof navigator.userAgent === "string" && - navigator.userAgent.indexOf("Electron") >= 0 - ) { - return true; - } - - return false; -} +import {isElectron} from "./utils/electronUtils" const Router = isElectron() ? HashRouter : BrowserRouter; diff --git a/src/components/EditorHeader/ControlPanel.jsx b/src/components/EditorHeader/ControlPanel.jsx index 6fde7507..36a16ec3 100644 --- a/src/components/EditorHeader/ControlPanel.jsx +++ b/src/components/EditorHeader/ControlPanel.jsx @@ -73,6 +73,7 @@ import { jsonToMermaid } from "../../utils/exportAs/mermaid"; import { isRtl } from "../../i18n/utils/rtl"; import { jsonToDocumentation } from "../../utils/exportAs/documentation"; import { IdContext } from "../Workspace"; +import { isElectron } from "../../utils/electronUtils"; export default function ControlPanel({ diagramId, @@ -1333,21 +1334,40 @@ export default function ControlPanel({ }, help: { shortcuts: { - function: () => window.open("/shortcuts", "_blank"), + function: () => isElectron() + ? (window.location.href = "#/shortcuts") + : window.open("/shortcuts", "_blank"), shortcut: "Ctrl+H", }, ask_on_discord: { - function: () => window.open("https://discord.gg/BrjZgNrmR6", "_blank"), + function: () => { + const discordAppUrl = "discord://invite/BrjZgNrmR6"; + const fallbackUrl = "https://discord.gg/BrjZgNrmR6"; + try { + if (isElectron()) { + window.electron(discordAppUrl); + } else { + window.open(fallbackUrl, "_blank"); + } + } catch (error) { + window.open(fallbackUrl, "_blank"); + } + }, }, report_bug: { - function: () => window.open("/bug-report", "_blank"), + function: () => isElectron() + ? (window.location.href = "#/bug-report") + : window.open("/bug-report", "_blank"), }, feedback: { - function: () => window.open("/survey", "_blank"), + function: () => isElectron() + ? (window.location.href = "#/survey") + : window.open("/survey", "_blank"), }, }, }; + useHotkeys("ctrl+i, meta+i", fileImport, { preventDefault: true }); useHotkeys("ctrl+z, meta+z", undo, { preventDefault: true }); useHotkeys("ctrl+y, meta+y", redo, { preventDefault: true }); @@ -1387,7 +1407,7 @@ export default function ControlPanel({ style={isRtl(i18n.language) ? { direction: "rtl" } : {}} > {header()} - {window.name.split(" ")[0] !== "t" && ( + {!isElectron() && window.name.split(" ")[0] !== "t" && (