mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-26 13:24:48 +02:00
Add a typed platform package to decouple the frontend from Tauri (#539)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
0068be9ffc
commit
2383f06e71
@@ -1,9 +1,9 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
import { Fonts } from "./bindings/gen_fonts";
|
||||
|
||||
export async function listFonts() {
|
||||
return invoke<Fonts>("plugin:yaak-fonts|list", {});
|
||||
return platform.rpc<Fonts>("plugin:yaak-fonts|list", {});
|
||||
}
|
||||
|
||||
export function useFonts() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
import { appInfo } from "@yaakapp/yaak-client/lib/appInfo";
|
||||
import { useEffect } from "react";
|
||||
import { LicenseCheckStatus } from "./bindings/license";
|
||||
@@ -13,24 +12,21 @@ export function useLicense() {
|
||||
const queryClient = useQueryClient();
|
||||
const activate = useMutation<void, string, { licenseKey: string }>({
|
||||
mutationKey: ["license.activate"],
|
||||
mutationFn: (payload) => invoke("plugin:yaak-license|activate", payload),
|
||||
mutationFn: (payload) => platform.rpc("plugin:yaak-license|activate", payload),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: CHECK_QUERY_KEY }),
|
||||
});
|
||||
|
||||
const deactivate = useMutation<void, string, void>({
|
||||
mutationKey: ["license.deactivate"],
|
||||
mutationFn: () => invoke("plugin:yaak-license|deactivate"),
|
||||
mutationFn: () => platform.rpc("plugin:yaak-license|deactivate"),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: CHECK_QUERY_KEY }),
|
||||
});
|
||||
|
||||
// Check the license again after a license is activated
|
||||
useEffect(() => {
|
||||
const unlisten = listen("license-activated", async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: CHECK_QUERY_KEY });
|
||||
return platform.listen("license-activated", () => {
|
||||
void queryClient.invalidateQueries({ queryKey: CHECK_QUERY_KEY });
|
||||
});
|
||||
return () => {
|
||||
void unlisten.then((fn) => fn());
|
||||
};
|
||||
}, []);
|
||||
|
||||
const check = useQuery<LicenseCheckStatus | null, string>({
|
||||
@@ -41,7 +37,7 @@ export function useLicense() {
|
||||
if (!appInfo.featureLicense) {
|
||||
return null;
|
||||
}
|
||||
return invoke<LicenseCheckStatus>("plugin:yaak-license|check");
|
||||
return platform.rpc<LicenseCheckStatus>("plugin:yaak-license|check");
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
|
||||
export function setWindowTitle(title: string) {
|
||||
invoke("plugin:yaak-mac-window|set_title", { title }).catch(console.error);
|
||||
platform.rpc("plugin:yaak-mac-window|set_title", { title }).catch(console.error);
|
||||
}
|
||||
|
||||
export function setWindowTheme(bgColor: string) {
|
||||
invoke("plugin:yaak-mac-window|set_theme", { bgColor }).catch(console.error);
|
||||
platform.rpc("plugin:yaak-mac-window|set_theme", { bgColor }).catch(console.error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user