mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 19:47:43 +01:00
refactor: invoke language update logic earlier (#774)
This commit is contained in:
@@ -30,7 +30,6 @@ import {
|
|||||||
change_shortcut,
|
change_shortcut,
|
||||||
unregister_shortcut,
|
unregister_shortcut,
|
||||||
} from "@/commands";
|
} from "@/commands";
|
||||||
import platformAdapter from "@/utils/platformAdapter";
|
|
||||||
|
|
||||||
export function ThemeOption({
|
export function ThemeOption({
|
||||||
icon: Icon,
|
icon: Icon,
|
||||||
@@ -77,12 +76,6 @@ export default function GeneralSettings() {
|
|||||||
|
|
||||||
const { showTooltip, setShowTooltip, language, setLanguage } = useAppStore();
|
const { showTooltip, setShowTooltip, language, setLanguage } = useAppStore();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
platformAdapter.invokeBackend("update_app_lang", {
|
|
||||||
lang: language,
|
|
||||||
});
|
|
||||||
}, [language]);
|
|
||||||
|
|
||||||
const fetchAutoStartStatus = async () => {
|
const fetchAutoStartStatus = async () => {
|
||||||
if (isTauri()) {
|
if (isTauri()) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Outlet, useLocation } from "react-router-dom";
|
import { Outlet, useLocation } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
@@ -24,10 +24,20 @@ import { useExtensionsStore } from "@/stores/extensionsStore";
|
|||||||
export default function Layout() {
|
export default function Layout() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const activeTheme = useThemeStore((state) => state.activeTheme);
|
const { language } = useAppStore();
|
||||||
const setTheme = useThemeStore((state) => state.setTheme);
|
const { i18n } = useTranslation();
|
||||||
const isDark = useThemeStore((state) => state.isDark);
|
const { activeTheme, isDark, setIsDark, setTheme } = useThemeStore();
|
||||||
const setIsDark = useThemeStore((state) => state.setIsDark);
|
const [langUpdated, setLangUpdated] = useState(false);
|
||||||
|
|
||||||
|
useAsyncEffect(async () => {
|
||||||
|
i18n.changeLanguage(language);
|
||||||
|
|
||||||
|
await platformAdapter.invokeBackend("update_app_lang", {
|
||||||
|
lang: language,
|
||||||
|
});
|
||||||
|
|
||||||
|
setLangUpdated(true);
|
||||||
|
}, [language]);
|
||||||
|
|
||||||
function updateBodyClass(path: string) {
|
function updateBodyClass(path: string) {
|
||||||
const body = document.body;
|
const body = document.body;
|
||||||
@@ -85,14 +95,8 @@ export default function Layout() {
|
|||||||
|
|
||||||
useSettingsWindow();
|
useSettingsWindow();
|
||||||
|
|
||||||
const { i18n } = useTranslation();
|
|
||||||
const language = useAppStore((state) => state.language);
|
|
||||||
const { text: selectionText } = useTextSelection();
|
const { text: selectionText } = useTextSelection();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
i18n.changeLanguage(language);
|
|
||||||
}, [language]);
|
|
||||||
|
|
||||||
// Disable right-click for production environment
|
// Disable right-click for production environment
|
||||||
useEventListener("contextmenu", (event) => {
|
useEventListener("contextmenu", (event) => {
|
||||||
if (import.meta.env.DEV || selectionText) return;
|
if (import.meta.env.DEV || selectionText) return;
|
||||||
@@ -108,7 +112,7 @@ export default function Layout() {
|
|||||||
platformAdapter.error(message);
|
platformAdapter.error(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
useIconfontScript('app');
|
useIconfontScript("app");
|
||||||
|
|
||||||
const setDisabledExtensions = useExtensionsStore((state) => {
|
const setDisabledExtensions = useExtensionsStore((state) => {
|
||||||
return state.setDisabledExtensions;
|
return state.setDisabledExtensions;
|
||||||
@@ -131,7 +135,7 @@ export default function Layout() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Outlet />
|
{langUpdated && <Outlet />}
|
||||||
<ErrorNotification />
|
<ErrorNotification />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user