Skip to content

Commit

Permalink
Updated herre, experimanl tauri
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnnsrs committed Aug 23, 2023
1 parent 162041f commit 06e81ef
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 72 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@heroicons/react": "^1.0.6",
"@jhnnsrs/datalayer": "0.0.7",
"@jhnnsrs/fakts": "0.1.10",
"@jhnnsrs/herre": "0.0.4",
"@jhnnsrs/herre": "0.0.11",
"@popperjs/core": "^2.11.5",
"@radix-ui/react-dialog": "^1.0.4",
"@react-spring/web": "^9.5.2",
Expand Down
38 changes: 28 additions & 10 deletions src/app/AppProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DatalayerProvider } from "@jhnnsrs/datalayer";
import { FaktsProvider } from "@jhnnsrs/fakts";
import { HerreProvider } from "@jhnnsrs/herre";
import { HerreProvider, windowRedirect } from "@jhnnsrs/herre";
import { listen } from "@tauri-apps/api/event";
import { open } from "@tauri-apps/api/shell";
import React from "react";
import { FlussProvider } from "../fluss/fluss-provider";
import { LokProvider } from "../lok/LokProvider";
Expand All @@ -14,17 +16,33 @@ import { RequesterProvider } from "../rekuest/providers/requester/requester-prov
import { ReserverProvider } from "../rekuest/providers/reserver/reserver-provider";
import { WidgetRegistryProvider } from "../rekuest/widgets/widget-provider";

const doRedirect = async (url: string, abortController: AbortController) => {
console.log("Redirecting to", url);
if (window.__TAURI__) {
console.log("Tauri detected");
open(url);

return new Promise<string>((resolve, reject) => {
console.log("Listening for code");
const unlisten = listen("oauth://url", async (event) => {
let url = event.payload as string;
let code = url.split("code=")[1];
console.log("Got code", code);
resolve(code);
});

const unlistend = listen("oauth://invalid-url", async (event) => {
console.log("Got invalid-rl", event);
reject(event);
});
});
} else {
return await windowRedirect(url, abortController);
}
};

//TODO: Mater provider needs to be seperate
export const AppProvider = ({ children }: { children: React.ReactNode }) => {
const doRedirect = (url: string) => {
console.log("Redirecting to", url);
if (window.__TAURI__) {
open(url);
} else {
window.open(url, "_blank", "noreferrer, popup");
}
};

return (
<FaktsProvider>
<HerreProvider doRedirect={doRedirect}>
Expand Down
5 changes: 5 additions & 0 deletions src/app/AutoConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MikroWard } from "../bridges/MikroWard";
import { PortAutoConfigure } from "../bridges/PortAutoConfigure";
import { RekuestAutoConfigure } from "../bridges/RekuestAutoConfigure";
import { RekuestWard } from "../bridges/RekuestWard";
import { TauriHerreCallback } from "../bridges/TauriHerreCallback";
import { GeneralMenu } from "../components/command/GeneralMenu";
import { NavigationActions } from "../components/command/NavigationActions";
import { NodesExtension } from "../components/command/NodesExtension";
Expand All @@ -30,6 +31,7 @@ import { GraphQLPostman } from "../rekuest/providers/postman/GraphQLPostman";
import { RequestResolver } from "../rekuest/providers/requester/RequestResolver";
import { ReserveResolver } from "../rekuest/providers/reserver/ReserveResolver";
import { WidgetsContainer } from "../rekuest/widgets/containers/ReturnWidgetsContainer";
import { TauriGuard } from "../tauri/guard";
import { DndPreview } from "../universal/components/DndPreview";

const Internal = (props: { assignation: PostmanAssignationFragment }) => {
Expand Down Expand Up @@ -134,6 +136,9 @@ export const AutoConfiguration = () => {
<NodesExtension />
<GraphQLPostman onAssignUpdate={onAssignUpdate} />
</RekuestGuard>
<TauriGuard>
<TauriHerreCallback />
</TauriGuard>
<SelectionActions />
</>
);
Expand Down
59 changes: 26 additions & 33 deletions src/protected/ProtectedRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { FaktsGuard } from "@jhnnsrs/fakts";
import { HerreGuard } from "@jhnnsrs/herre";
import React from "react";
import { Route, Routes } from "react-router";
import { TauriFaktsFallback } from "../bridges/TauriFaktsFallback";
import { AdaptiveFaktsFallback } from "../bridges/AdaptiveFallback";
import { NavigationBar } from "../components/navigation/NavigationBar";
import FlussModule from "../fluss/FlussModule";
import { LokGuard } from "../lok/LokGuard";
import LokModule from "../lok/LokModule";
import MikroModule from "../mikro/MikroModule";
import MikroNextModule from "../mikro_next/MikroNextModule";
import { NoRoute } from "../pages/fallbacks/NoRoute";
import { PublicFakts } from "../pages/public/PublicFakts";
import { PublicLogin } from "../pages/public/PublicLogin";
import PortModule from "../port/PortModule";
import RekuestModule from "../rekuest/RekuestModule";
import SettingsModule from "../settings/SettingsModule";
Expand All @@ -24,45 +21,41 @@ export const ProtectedRouter: React.FC<Props> = (props) => {
return (
<div className="flex flex-col h-screen sm:flex-row-reverse">
<div className="flex-grow flex bg-gradient-to-b from-back-900 via-back-900 via-back-850 via-back-850 to-back-800 overflow-y-auto">
<FaktsGuard
fallback={window.__TAURI__ ? <TauriFaktsFallback /> : <PublicFakts />}
>
<HerreGuard fallback={<PublicLogin />}>
<LokGuard>
<React.Suspense fallback={<>Loading slowly....</>}>
<Routes>
<Route index element={<Home />} />
<FaktsGuard fallback={<AdaptiveFaktsFallback />}>
<LokGuard>
<React.Suspense fallback={<>Loading slowly....</>}>
<Routes>
<Route index element={<Home />} />

{/* Mikro Next*/}
<Route path="mikronext/*" element={<MikroNextModule />} />
{/* Mikro Next*/}
<Route path="mikronext/*" element={<MikroNextModule />} />

{/* Mikro*/}
<Route path="mikro/*" element={<MikroModule />} />
{/* Mikro*/}
<Route path="mikro/*" element={<MikroModule />} />

{/* lok */}
<Route path="lok/*" element={<LokModule />}></Route>
{/* lok */}
<Route path="lok/*" element={<LokModule />}></Route>

{/* Fluss */}
{/* Fluss */}

<Route path="fluss/*" element={<FlussModule />}></Route>
<Route path="fluss/*" element={<FlussModule />}></Route>

{/* Rekuest */}
<Route path="rekuest/*" element={<RekuestModule />}></Route>
{/* Rekuest */}
<Route path="rekuest/*" element={<RekuestModule />}></Route>

{/* port */}
<Route path="port/*" element={<PortModule />}></Route>
{/* port */}
<Route path="port/*" element={<PortModule />}></Route>

{/* Settings */}
<Route path="settings/*" element={<SettingsModule />} />
{/* Settings */}
<Route path="settings/*" element={<SettingsModule />} />

{/* Tauri */}
<Route path="tauri" element={<TauriModule />} />
{/* Tauri */}
<Route path="tauri" element={<TauriModule />} />

<Route path="*" element={<NoRoute />} />
</Routes>
</React.Suspense>
</LokGuard>
</HerreGuard>
<Route path="*" element={<NoRoute />} />
</Routes>
</React.Suspense>
</LokGuard>
</FaktsGuard>
</div>
<div className="flex-initial sm:flex-initial sm:static sm:w-20">
Expand Down
24 changes: 14 additions & 10 deletions src/public/PublicRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { FaktsGuard } from "@jhnnsrs/fakts";
import React from "react";
import { Route, Routes } from "react-router";
import { AdaptiveFaktsFallback } from "../bridges/AdaptiveFallback";
import { PublicNavigationBar } from "../components/navigation/PublicNavigationBar";
import { Callback } from "./pages/Callback";
import { Home } from "./pages/Home";
interface Props {}

export const PublicRouter: React.FC<Props> = (props) => {
return (
<div className="flex flex-col h-screen sm:flex-row-reverse">
<div className="flex-grow flex bg-gradient-to-b from-back-900 via-back-900 via-back-850 via-back-850 to-back-800 overflow-y-auto">
<Routes>
<Route path="callback" element={<Callback />} />
<Route index element={<Home />} />
</Routes>
<FaktsGuard fallback={<AdaptiveFaktsFallback />}>
<div className="flex flex-col h-screen sm:flex-row-reverse">
<div className="flex-grow flex bg-gradient-to-b from-back-900 via-back-900 via-back-850 via-back-850 to-back-800 overflow-y-auto">
<Routes>
<Route path="callback" element={<Callback />} />
<Route index element={<Home />} />
</Routes>
</div>
<div className="flex-initial sm:flex-initial sm:static sm:w-20">
<PublicNavigationBar />
</div>
</div>
<div className="flex-initial sm:flex-initial sm:static sm:w-20">
<PublicNavigationBar />
</div>
</div>
</FaktsGuard>
);
};

Expand Down
14 changes: 3 additions & 11 deletions src/public/pages/Callback.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import { useHerre } from "@jhnnsrs/herre";
import { emit } from "@tauri-apps/api/event";
import React, { useEffect } from "react";
import { useNavigate } from "react-router";
import { useSearchParams } from "react-router-dom";

export interface CallbackProps {}

export const Callback: React.FC<CallbackProps> = (props) => {
const [params, setParams] = useSearchParams();
const { setCode } = useHerre();
const navigate = useNavigate();

useEffect(() => {
let code = params.get("code");
console.log(code);
if (code) {
if (window.__TAURI__) {
emit("code", { code: code });
} else {
setCode(code);
window.close();
}
localStorage.setItem("herre-code", code);
window.close();
}
}, []);

Expand Down
6 changes: 4 additions & 2 deletions src/public/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const FaktualReconfigure: React.FC<PublicHomeProps> = (props) => {
}}
className="w-full flex items-center justify-center border-gray-500 border-dotted shadow-lg shadow-white/30 px-8 py-3 border border-transparent text-base font-medium rounded-md text-primary-600 bg-indigo-100 hover:bg-indigo-200 md:py-4 md:text-lg md:px-10"
>
Logoutss
Disconnect from {fakts.self.name}
</button>
</>
);
Expand All @@ -53,7 +53,9 @@ export const Home: React.FC<PublicHomeProps> = (props) => {
<main className="mt-10 mx-auto px-4 sm:mt-12 sm:px-6 md:mt-16 lg:mt-20 lg:px-8 xl:mt-28">
<div className="sm:text-center lg:text-left">
<h1 className="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:text-6xl">
<span className="block xl:inline text-white">Arkitekt </span>{" "}
<span className="block xl:inline text-white">
Arkitekt {window.__TAURI__ && "@ tauri"}{" "}
</span>{" "}
<span className="block text-primary-300 xl:inline drop-shadow-2xl ">
<TextTransition springConfig={presets.gentle} inline>
{TEXTS[index % TEXTS.length]}
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1129,13 +1129,13 @@
dependencies:
cancelable-promise "^4.3.0"

"@jhnnsrs/herre@0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@jhnnsrs/herre/-/herre-0.0.4.tgz#3b58575013aba9b2200a873d648cbada01cea067"
integrity sha512-BkcnJqzJ4Jm1ygd2OWg00Q2vB6Yeac4MekQ2pLR38f6LKYS5Fsjq0MNUejttvIOBOV79bhgr2hcBNzXgUL/1kQ==
"@jhnnsrs/herre@0.0.11":
version "0.0.11"
resolved "https://registry.yarnpkg.com/@jhnnsrs/herre/-/herre-0.0.11.tgz#5a10ce5c0d006ad50cda56feef299e9cc8d0aefd"
integrity sha512-GxMiBAOngBxOlLdT95nyq8hGo3BILPy8WyFkW5u/Pqy19Kd2YgDskRq9EkJlLe5TEGb1r1T8HWQPdrjRBe1qVg==
dependencies:
cancelable-promise "^4.3.1"
pkce-challenge "^3.0.0"
crypto-js "^4.1.1"

"@jridgewell/gen-mapping@^0.1.0":
version "0.1.1"
Expand Down

0 comments on commit 06e81ef

Please sign in to comment.