mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 02:00:31 +08:00
Add test-http-api crate to make app work in browser
A new `invoke` function calls either the tauri backend or the `test-http-api` function if ran in a browser.
This commit is contained in:
+9
-7
@@ -3,7 +3,7 @@
|
||||
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
@@ -25,13 +25,15 @@
|
||||
let unlistenNodeEvents: UnlistenFn | undefined = undefined;
|
||||
|
||||
onMount(async () => {
|
||||
unlistenEvents = await listen("event", event => {
|
||||
console.log(event.payload);
|
||||
});
|
||||
if (window.__TAURI_INTERNALS__) {
|
||||
unlistenEvents = await listen("event", event => {
|
||||
console.log(event.payload);
|
||||
});
|
||||
|
||||
unlistenNodeEvents = await listen<boolean>("node_running", event => {
|
||||
nodeRunning.set(event.payload);
|
||||
});
|
||||
unlistenNodeEvents = await listen<boolean>("node_running", event => {
|
||||
nodeRunning.set(event.payload);
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await invoke("authenticate");
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import { Renderer, markdownWithExtensions } from "@app/lib/markdown";
|
||||
import { highlight } from "@app/lib/syntax";
|
||||
import { twemoji, scrollIntoView, isCommit } from "@app/lib/utils";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
|
||||
export let rid: string;
|
||||
export let content: string;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
patchStatusBackgroundColor,
|
||||
patchStatusColor,
|
||||
} from "@app/lib/utils";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import { onMount } from "svelte";
|
||||
import { push } from "@app/lib/router";
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import * as tauri from "@tauri-apps/api/core";
|
||||
|
||||
export async function invoke<T = null>(
|
||||
cmd: string,
|
||||
args?: tauri.InvokeArgs,
|
||||
options?: tauri.InvokeOptions,
|
||||
): Promise<T> {
|
||||
if (window.__TAURI_INTERNALS__) {
|
||||
return tauri.invoke(cmd, args, options);
|
||||
} else {
|
||||
return fetch(`http://127.0.0.1:8080/${cmd}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(args),
|
||||
})
|
||||
.then(data => data.json())
|
||||
.catch(() => {
|
||||
throw Error(`Issue with HTTP Route: ${JSON.stringify({ cmd, args })}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import type { Config } from "@bindings/config/Config";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
import type { LoadedRepoRoute, RepoRoute } from "@app/views/repo/router";
|
||||
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
|
||||
import {
|
||||
loadCreateIssue,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { Issue } from "@bindings/cob/issue/Issue";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
|
||||
import { issueStatusColor } from "@app/lib/utils";
|
||||
import * as router from "@app/lib/router";
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
publicKeyFromDid,
|
||||
scrollIntoView,
|
||||
} from "@app/lib/utils";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
|
||||
import { announce } from "@app/components/AnnounceSwitch.svelte";
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
formatTimestamp,
|
||||
patchStatusColor,
|
||||
} from "@app/lib/utils";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
|
||||
import Border from "@app/components/Border.svelte";
|
||||
import CopyableId from "@app/components/CopyableId.svelte";
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import type { PatchStatus } from "./router";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
|
||||
import Layout from "./Layout.svelte";
|
||||
import Border from "@app/components/Border.svelte";
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { Patch } from "@bindings/cob/patch/Patch";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
import type { Revision } from "@bindings/cob/patch/Revision";
|
||||
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import { unreachable } from "@app/lib/utils";
|
||||
|
||||
export type IssueStatus = "all" | Issue["state"]["status"];
|
||||
|
||||
Reference in New Issue
Block a user