mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 11:37:47 +01:00
refactor: improved loss after refresh (#874)
* refactor: improved loss after refresh * refactor: update * style: change code line
This commit is contained in:
@@ -9,3 +9,7 @@ export const DEFAULT_COCO_SERVER_ID = "default_coco_server";
|
||||
export const MAIN_WINDOW_LABEL = "main";
|
||||
|
||||
export const SETTINGS_WINDOW_LABEL = "settings";
|
||||
|
||||
export const CHECK_WINDOW_LABEL = "check";
|
||||
|
||||
export const CHAT_WINDOW_LABEL = "chat";
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
import { useMount } from "ahooks";
|
||||
import { useMount, useSessionStorageState } from "ahooks";
|
||||
import { useEffect } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
import LayoutOutlet from "./outlet";
|
||||
import { useAppStore } from "@/stores/appStore";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import platformAdapter from "@/utils/platformAdapter";
|
||||
import { MAIN_WINDOW_LABEL, SETTINGS_WINDOW_LABEL } from "@/constants";
|
||||
import { useEffect, useState } from "react";
|
||||
import { CHAT_WINDOW_LABEL, MAIN_WINDOW_LABEL } from "@/constants";
|
||||
|
||||
const Layout = () => {
|
||||
const { language } = useAppStore();
|
||||
const [ready, setReady] = useState(false);
|
||||
const [ready, setReady] = useSessionStorageState("rust_ready", {
|
||||
defaultValue: false,
|
||||
});
|
||||
|
||||
useMount(async () => {
|
||||
const label = await platformAdapter.getCurrentWindowLabel();
|
||||
|
||||
if (label === CHAT_WINDOW_LABEL) {
|
||||
setReady(true);
|
||||
}
|
||||
|
||||
if (ready || label !== MAIN_WINDOW_LABEL) return;
|
||||
|
||||
await invoke("backend_setup", {
|
||||
appLang: language,
|
||||
});
|
||||
|
||||
setReady(true);
|
||||
|
||||
platformAdapter.emitEvent("rust_ready");
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const unlisten = platformAdapter.listenEvent("rust_ready", () => {
|
||||
@@ -20,26 +41,6 @@ const Layout = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useMount(async () => {
|
||||
const label = await platformAdapter.getCurrentWindowLabel();
|
||||
|
||||
if (label === MAIN_WINDOW_LABEL) {
|
||||
await invoke("backend_setup", {
|
||||
appLang: language,
|
||||
});
|
||||
|
||||
setReady(true);
|
||||
|
||||
return platformAdapter.emitEvent("rust_ready", true);
|
||||
}
|
||||
|
||||
if (label !== SETTINGS_WINDOW_LABEL) {
|
||||
setReady(true);
|
||||
}
|
||||
});
|
||||
|
||||
console.log("ready", ready);
|
||||
|
||||
return ready && <LayoutOutlet />;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user