feat: reload currrent page in electron
This commit is contained in:
@@ -242,6 +242,7 @@ export const serverApi = createApi({
|
||||
try {
|
||||
const resp = await queryFulfilled;
|
||||
if (resp.data) {
|
||||
console.info("update login config in redux", resp.data);
|
||||
dispatch(updateInfo({ loginConfig: resp.data }));
|
||||
}
|
||||
} catch {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
|
||||
import useStreaming from "@/hooks/useStreaming";
|
||||
// import clsx from "clsx";
|
||||
import Button from "./styled/Button";
|
||||
import { reloadCurrentPage } from "@/utils";
|
||||
|
||||
interface Props {}
|
||||
|
||||
@@ -21,7 +22,7 @@ const InactiveScreen: FC<Props> = () => {
|
||||
};
|
||||
}, []);
|
||||
const handleReload = () => {
|
||||
location.reload();
|
||||
reloadCurrentPage();
|
||||
};
|
||||
return (
|
||||
<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 Button from "./styled/Button";
|
||||
import { reloadCurrentPage } from "@/utils";
|
||||
|
||||
interface Props {
|
||||
reload?: boolean;
|
||||
@@ -16,7 +17,7 @@ const Loading: FC<Props> = ({ reload = false, fullscreen = false, context = "" }
|
||||
const { clearLocalData } = useLogout();
|
||||
const handleReload = () => {
|
||||
clearLocalData();
|
||||
location.reload();
|
||||
reloadCurrentPage();
|
||||
};
|
||||
useEffect(() => {
|
||||
let inter = 0;
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useAppSelector } from "@/app/store";
|
||||
import { unregister } from "../serviceWorkerRegistration";
|
||||
import Button from "./styled/Button";
|
||||
import { shallowEqual } from "react-redux";
|
||||
import { reloadCurrentPage } from "@/utils";
|
||||
|
||||
type Props = {};
|
||||
const Version: FC<Props> = () => {
|
||||
@@ -18,7 +19,7 @@ const Version: FC<Props> = () => {
|
||||
setSyncing(true);
|
||||
unregister();
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
reloadCurrentPage();
|
||||
}, 2000);
|
||||
};
|
||||
return (
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ import { register } from "./serviceWorkerRegistration";
|
||||
import "./i18n";
|
||||
import "./libs/polyfills";
|
||||
|
||||
import { isDarkMode } from "./utils";
|
||||
import { isDarkMode, reloadCurrentPage } from "./utils";
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
|
||||
// dark mode
|
||||
@@ -48,7 +48,7 @@ register({
|
||||
onUpdate: (reg) => {
|
||||
const handleUpdate = () => {
|
||||
reg.unregister().then(() => {
|
||||
window.location.reload();
|
||||
reloadCurrentPage();
|
||||
});
|
||||
};
|
||||
toast((t) => <NewVersion id={t.id} handleUpdate={handleUpdate} />, {
|
||||
|
||||
@@ -10,6 +10,7 @@ import FilterChannel from "./Channel";
|
||||
import FilterDate, { Dates } from "./Date";
|
||||
import FilterFrom from "./From";
|
||||
import FilterType, { FileTypes } from "./Type";
|
||||
import { shallowEqual } from "react-redux";
|
||||
|
||||
const getClass = (selected: boolean) => {
|
||||
return clsx(
|
||||
|
||||
@@ -434,6 +434,22 @@ export const transformInviteLink = (link: string) => {
|
||||
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 encodeBase64 = (str = "") => btoa(unescape(encodeURIComponent(str)));
|
||||
export const shouldPreviewImage = (type: string) => {
|
||||
|
||||
Reference in New Issue
Block a user