From 571920ab830b54b888bd9e929753a649bbb34917 Mon Sep 17 00:00:00 2001 From: 04041b <65881086+04041b@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:37:59 -0800 Subject: [PATCH] update __TAURI__ api --- app/components/exporter.tsx | 4 ++-- app/store/update.ts | 10 +++++----- app/utils.ts | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index 79ae87be2..a8836de21 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -473,7 +473,7 @@ export function ImagePreviewer(props: { if (isMobile || (isApp && window.__TAURI__)) { if (isApp && window.__TAURI__) { - const result = await window.__TAURI__.dialog.save({ + const result = await window.__TAURI__.core.dialog.save({ defaultPath: `${props.topic}.png`, filters: [ { @@ -491,7 +491,7 @@ export function ImagePreviewer(props: { const response = await fetch(blob); const buffer = await response.arrayBuffer(); const uint8Array = new Uint8Array(buffer); - await window.__TAURI__.fs.writeBinaryFile(result, uint8Array); + await window.__TAURI__.core.fs.writeBinaryFile(result, uint8Array); showToast(Locale.Download.Success); } else { showToast(Locale.Download.Failed); diff --git a/app/store/update.ts b/app/store/update.ts index 327dc5e88..38259bdd0 100644 --- a/app/store/update.ts +++ b/app/store/update.ts @@ -89,22 +89,22 @@ export const useUpdateStore = createPersistStore( set(() => ({ remoteVersion: remoteId, })); - if (window.__TAURI__?.notification && isApp) { + if (window.__TAURI__?.core.notification && isApp) { // Check if notification permission is granted - await window.__TAURI__?.notification + await window.__TAURI__?.core.notification .isPermissionGranted() .then((granted) => { if (!granted) { return; } else { // Request permission to show notifications - window.__TAURI__?.notification + window.__TAURI__?.core.notification .requestPermission() .then((permission) => { if (permission === "granted") { if (version === remoteId) { // Show a notification using Tauri - window.__TAURI__?.notification.sendNotification({ + window.__TAURI__?.core.notification.sendNotification({ title: "NextChat", body: `${Locale.Settings.Update.IsLatest}`, icon: `${ChatGptIcon.src}`, @@ -114,7 +114,7 @@ export const useUpdateStore = createPersistStore( const updateMessage = Locale.Settings.Update.FoundUpdate(`${remoteId}`); // Show a notification for the new version using Tauri - window.__TAURI__?.notification.sendNotification({ + window.__TAURI__?.core.notification.sendNotification({ title: "NextChat", body: updateMessage, icon: `${ChatGptIcon.src}`, diff --git a/app/utils.ts b/app/utils.ts index b62bc126d..7f5fceaf0 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -21,7 +21,7 @@ export function trimTopic(topic: string) { export async function copyToClipboard(text: string) { try { if (window.__TAURI__) { - window.__TAURI__.writeText(text); + window.__TAURI__.core.writeText(text); } else { await navigator.clipboard.writeText(text); } @@ -45,7 +45,7 @@ export async function copyToClipboard(text: string) { export async function downloadAs(text: string, filename: string) { if (window.__TAURI__) { - const result = await window.__TAURI__.dialog.save({ + const result = await window.__TAURI__.core.dialog.save({ defaultPath: `${filename}`, filters: [ { @@ -61,7 +61,7 @@ export async function downloadAs(text: string, filename: string) { if (result !== null) { try { - await window.__TAURI__.fs.writeTextFile(result, text); + await window.__TAURI__.core.fs.writeTextFile(result, text); showToast(Locale.Download.Success); } catch (error) { showToast(Locale.Download.Failed); @@ -396,11 +396,11 @@ export function getOperationId(operation: { export function clientUpdate() { // this a wild for updating client app - return window.__TAURI__?.updater + return window.__TAURI__?.core.updater .checkUpdate() .then((updateResult) => { if (updateResult.shouldUpdate) { - window.__TAURI__?.updater + window.__TAURI__?.core.updater .installUpdate() .then((result) => { showToast(Locale.Settings.Update.Success);