mirror of
https://github.com/drawdb-io/drawdb.git
synced 2025-05-24 10:29:11 +00:00
electron utils, missing paths modified for electron
This commit is contained in:
parent
dedc41bfbf
commit
9256e9b016
20
src/App.jsx
20
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;
|
||||
|
||||
|
@ -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" && (
|
||||
<Button
|
||||
type="primary"
|
||||
className="text-base me-2 pe-6 ps-5 py-[18px] rounded-md"
|
||||
|
@ -7,6 +7,7 @@ import { useLiveQuery } from "dexie-react-hooks";
|
||||
import Thumbnail from "../components/Thumbnail";
|
||||
import logo_light from "../assets/logo_light_160.png";
|
||||
import template_screenshot from "../assets/template_screenshot.png";
|
||||
import { isElectron } from "../utils/electronUtils";
|
||||
|
||||
export default function Templates() {
|
||||
const defaultTemplates = useLiveQuery(() =>
|
||||
@ -22,13 +23,23 @@ export default function Templates() {
|
||||
};
|
||||
|
||||
const editTemplate = (id) => {
|
||||
if(isElectron()){
|
||||
const newWindow = window.open("#/editor", "_blank");
|
||||
newWindow.name = "t " + id;
|
||||
}else{
|
||||
const newWindow = window.open("/editor", "_blank");
|
||||
newWindow.name = "t " + id;
|
||||
}
|
||||
};
|
||||
|
||||
const forkTemplate = (id) => {
|
||||
if(isElectron()){
|
||||
const newWindow = window.open("#/editor", "_blank");
|
||||
newWindow.name = "lt " + id;
|
||||
}else{
|
||||
const newWindow = window.open("/editor", "_blank");
|
||||
newWindow.name = "lt " + id;
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
20
src/utils/electronUtils.js
Normal file
20
src/utils/electronUtils.js
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
export 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user