mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 19:47:43 +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 MAIN_WINDOW_LABEL = "main";
|
||||||
|
|
||||||
export const SETTINGS_WINDOW_LABEL = "settings";
|
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 LayoutOutlet from "./outlet";
|
||||||
import { useAppStore } from "@/stores/appStore";
|
import { useAppStore } from "@/stores/appStore";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
import platformAdapter from "@/utils/platformAdapter";
|
import platformAdapter from "@/utils/platformAdapter";
|
||||||
import { MAIN_WINDOW_LABEL, SETTINGS_WINDOW_LABEL } from "@/constants";
|
import { CHAT_WINDOW_LABEL, MAIN_WINDOW_LABEL } from "@/constants";
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
|
|
||||||
const Layout = () => {
|
const Layout = () => {
|
||||||
const { language } = useAppStore();
|
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(() => {
|
useEffect(() => {
|
||||||
const unlisten = platformAdapter.listenEvent("rust_ready", () => {
|
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 />;
|
return ready && <LayoutOutlet />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user