update __TAURI__ api

This commit is contained in:
04041b 2024-12-13 15:37:59 -08:00
parent 7c23a39e75
commit 571920ab83
3 changed files with 12 additions and 12 deletions

View File

@ -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);

View File

@ -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}`,

View File

@ -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);