This commit is contained in:
04041b
2025-01-12 15:08:22 +08:00
committed by GitHub
98 changed files with 27275 additions and 1861 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

@@ -10,7 +10,7 @@ export const getBuildConfig = () => {
const buildMode = process.env.BUILD_MODE ?? "standalone";
const isApp = !!process.env.BUILD_APP;
const version = "v" + tauriConfig.package.version;
const version = "v" + tauriConfig.version;
const commitInfo = (() => {
try {

50
app/global.d.ts vendored
View File

@@ -12,32 +12,34 @@ declare module "*.svg";
declare interface Window {
__TAURI__?: {
writeText(text: string): Promise<void>;
invoke(command: string, payload?: Record<string, unknown>): Promise<any>;
core: {
writeText(text: string): Promise<void>;
invoke(command: string, payload?: Record<string, unknown>): Promise<any>;
fs: {
writeBinaryFile(path: string, data: Uint8Array): Promise<void>;
writeTextFile(path: string, data: string): Promise<void>;
};
notification: {
requestPermission(): Promise<Permission>;
isPermissionGranted(): Promise<boolean>;
sendNotification(options: string | Options): void;
};
updater: {
checkUpdate(): Promise<UpdateResult>;
installUpdate(): Promise<void>;
onUpdaterEvent(
handler: (status: UpdateStatusResult) => void,
): Promise<UnlistenFn>;
};
http: {
fetch<T>(
url: string,
options?: Record<string, unknown>,
): Promise<Response<T>>;
};
};
dialog: {
save(options?: Record<string, unknown>): Promise<string | null>;
};
fs: {
writeBinaryFile(path: string, data: Uint8Array): Promise<void>;
writeTextFile(path: string, data: string): Promise<void>;
};
notification: {
requestPermission(): Promise<Permission>;
isPermissionGranted(): Promise<boolean>;
sendNotification(options: string | Options): void;
};
updater: {
checkUpdate(): Promise<UpdateResult>;
installUpdate(): Promise<void>;
onUpdaterEvent(
handler: (status: UpdateStatusResult) => void,
): Promise<UnlistenFn>;
};
http: {
fetch<T>(
url: string,
options?: Record<string, unknown>,
): Promise<Response<T>>;
};
};
}

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

@@ -24,7 +24,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);
}
@@ -64,7 +64,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);
@@ -410,11 +410,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);

View File

@@ -74,7 +74,7 @@ export function fetch(url: string, options?: RequestInit): Promise<Response> {
for (const item of new Headers(_headers || {})) {
headers[item[0]] = item[1];
}
return window.__TAURI__
return window.__TAURI__.core
.invoke("stream_fetch", {
method: method.toUpperCase(),
url,