feat: reload currrent page in electron
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vocechat-web",
|
"name": "vocechat-web",
|
||||||
"version": "0.5.0",
|
"version": "0.5.2",
|
||||||
"homepage": "https://voce.chat",
|
"homepage": "https://voce.chat",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron-toolkit/preload": "^2.0.0",
|
"@electron-toolkit/preload": "^2.0.0",
|
||||||
|
|||||||
@@ -242,6 +242,7 @@ export const serverApi = createApi({
|
|||||||
try {
|
try {
|
||||||
const resp = await queryFulfilled;
|
const resp = await queryFulfilled;
|
||||||
if (resp.data) {
|
if (resp.data) {
|
||||||
|
console.info("update login config in redux", resp.data);
|
||||||
dispatch(updateInfo({ loginConfig: resp.data }));
|
dispatch(updateInfo({ loginConfig: resp.data }));
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import useStreaming from "@/hooks/useStreaming";
|
import useStreaming from "@/hooks/useStreaming";
|
||||||
// import clsx from "clsx";
|
// import clsx from "clsx";
|
||||||
import Button from "./styled/Button";
|
import Button from "./styled/Button";
|
||||||
|
import { reloadCurrentPage } from "@/utils";
|
||||||
|
|
||||||
interface Props {}
|
interface Props {}
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ const InactiveScreen: FC<Props> = () => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
const handleReload = () => {
|
const handleReload = () => {
|
||||||
location.reload();
|
reloadCurrentPage();
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div className="w-screen h-screen dark:bg-gray-700 flex-center text-4xl font-bold">
|
<div className="w-screen h-screen dark:bg-gray-700 flex-center text-4xl font-bold">
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import clsx from "clsx";
|
|||||||
|
|
||||||
import useLogout from "@/hooks/useLogout";
|
import useLogout from "@/hooks/useLogout";
|
||||||
import Button from "./styled/Button";
|
import Button from "./styled/Button";
|
||||||
|
import { reloadCurrentPage } from "@/utils";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
reload?: boolean;
|
reload?: boolean;
|
||||||
@@ -16,7 +17,7 @@ const Loading: FC<Props> = ({ reload = false, fullscreen = false, context = "" }
|
|||||||
const { clearLocalData } = useLogout();
|
const { clearLocalData } = useLogout();
|
||||||
const handleReload = () => {
|
const handleReload = () => {
|
||||||
clearLocalData();
|
clearLocalData();
|
||||||
location.reload();
|
reloadCurrentPage();
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let inter = 0;
|
let inter = 0;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { useAppSelector } from "@/app/store";
|
|||||||
import { unregister } from "../serviceWorkerRegistration";
|
import { unregister } from "../serviceWorkerRegistration";
|
||||||
import Button from "./styled/Button";
|
import Button from "./styled/Button";
|
||||||
import { shallowEqual } from "react-redux";
|
import { shallowEqual } from "react-redux";
|
||||||
|
import { reloadCurrentPage } from "@/utils";
|
||||||
|
|
||||||
type Props = {};
|
type Props = {};
|
||||||
const Version: FC<Props> = () => {
|
const Version: FC<Props> = () => {
|
||||||
@@ -18,7 +19,7 @@ const Version: FC<Props> = () => {
|
|||||||
setSyncing(true);
|
setSyncing(true);
|
||||||
unregister();
|
unregister();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
location.reload();
|
reloadCurrentPage();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
|||||||
+2
-2
@@ -18,7 +18,7 @@ import { register } from "./serviceWorkerRegistration";
|
|||||||
import "./i18n";
|
import "./i18n";
|
||||||
import "./libs/polyfills";
|
import "./libs/polyfills";
|
||||||
|
|
||||||
import { isDarkMode } from "./utils";
|
import { isDarkMode, reloadCurrentPage } from "./utils";
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
|
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
|
||||||
// dark mode
|
// dark mode
|
||||||
@@ -48,7 +48,7 @@ register({
|
|||||||
onUpdate: (reg) => {
|
onUpdate: (reg) => {
|
||||||
const handleUpdate = () => {
|
const handleUpdate = () => {
|
||||||
reg.unregister().then(() => {
|
reg.unregister().then(() => {
|
||||||
window.location.reload();
|
reloadCurrentPage();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
toast((t) => <NewVersion id={t.id} handleUpdate={handleUpdate} />, {
|
toast((t) => <NewVersion id={t.id} handleUpdate={handleUpdate} />, {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import FilterChannel from "./Channel";
|
|||||||
import FilterDate, { Dates } from "./Date";
|
import FilterDate, { Dates } from "./Date";
|
||||||
import FilterFrom from "./From";
|
import FilterFrom from "./From";
|
||||||
import FilterType, { FileTypes } from "./Type";
|
import FilterType, { FileTypes } from "./Type";
|
||||||
|
import { shallowEqual } from "react-redux";
|
||||||
|
|
||||||
const getClass = (selected: boolean) => {
|
const getClass = (selected: boolean) => {
|
||||||
return clsx(
|
return clsx(
|
||||||
|
|||||||
@@ -434,6 +434,22 @@ export const transformInviteLink = (link: string) => {
|
|||||||
return tmpLink;
|
return tmpLink;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const reloadCurrentPage = () => {
|
||||||
|
if (isElectronContext()) {
|
||||||
|
// 改变theme color 然后electron reload(约定)
|
||||||
|
const metaThemeColor = document.querySelector("meta[name=theme-color]");
|
||||||
|
if (metaThemeColor) {
|
||||||
|
metaThemeColor.setAttribute("content", "#123456");
|
||||||
|
} else {
|
||||||
|
const meta = document.createElement("meta");
|
||||||
|
meta.name = "theme-color";
|
||||||
|
meta.content = "#123456";
|
||||||
|
document.head.appendChild(meta);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
};
|
||||||
export const isInIframe = () => window.location !== window.parent.location;
|
export const isInIframe = () => window.location !== window.parent.location;
|
||||||
export const encodeBase64 = (str = "") => btoa(unescape(encodeURIComponent(str)));
|
export const encodeBase64 = (str = "") => btoa(unescape(encodeURIComponent(str)));
|
||||||
export const shouldPreviewImage = (type: string) => {
|
export const shouldPreviewImage = (type: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user