Introduce "AppSession"
This commit is contained in:
26
src/base/AppSession.ts
Normal file
26
src/base/AppSession.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) Contributors to the Suwayomi project
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { BrowserUtil } from '@/lib/BrowserUtil.ts';
|
||||||
|
import { AppStorage } from '@/lib/storage/AppStorage.ts';
|
||||||
|
|
||||||
|
const STARTUP_TIMESTAMP_KEY = 'webUIStartupTimestamp';
|
||||||
|
|
||||||
|
class AppSessionClass {
|
||||||
|
constructor() {
|
||||||
|
if (BrowserUtil.isActualPageLoad()) {
|
||||||
|
AppStorage.session.setItem(STARTUP_TIMESTAMP_KEY, Date.now());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get STARTUP_TIMESTAMP(): number {
|
||||||
|
return AppStorage.session.getItemParsed(STARTUP_TIMESTAMP_KEY, Date.now());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AppSession = new AppSessionClass();
|
||||||
@@ -17,7 +17,7 @@ import { useLingui } from '@lingui/react/macro';
|
|||||||
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
|
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
|
||||||
import type { WebUiUpdateStatus } from '@/lib/graphql/generated/graphql-base.types.ts';
|
import type { WebUiUpdateStatus } from '@/lib/graphql/generated/graphql-base.types.ts';
|
||||||
import { UpdateState, WebUiChannel } from '@/lib/graphql/generated/graphql-base.types.ts';
|
import { UpdateState, WebUiChannel } from '@/lib/graphql/generated/graphql-base.types.ts';
|
||||||
import { useLocalStorage, useSessionStorage } from '@/base/hooks/useStorage.tsx';
|
import { useLocalStorage } from '@/base/hooks/useStorage.tsx';
|
||||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||||
import { makeToast } from '@/base/utils/Toast.ts';
|
import { makeToast } from '@/base/utils/Toast.ts';
|
||||||
import { ABOUT_WEBUI, WEBUI_UPDATE_CHECK } from '@/lib/graphql/server/InfoFragments.ts';
|
import { ABOUT_WEBUI, WEBUI_UPDATE_CHECK } from '@/lib/graphql/server/InfoFragments.ts';
|
||||||
@@ -25,23 +25,15 @@ import { VersionUpdateInfoDialog } from '@/features/app-updates/components/Versi
|
|||||||
import { useUpdateChecker } from '@/features/app-updates/hooks/useUpdateChecker.tsx';
|
import { useUpdateChecker } from '@/features/app-updates/hooks/useUpdateChecker.tsx';
|
||||||
import { useMetadataServerSettings } from '@/features/settings/services/ServerSettingsMetadata.ts';
|
import { useMetadataServerSettings } from '@/features/settings/services/ServerSettingsMetadata.ts';
|
||||||
import { getErrorMessage, noOp } from '@/lib/HelperFunctions.ts';
|
import { getErrorMessage, noOp } from '@/lib/HelperFunctions.ts';
|
||||||
import { AppStorage } from '@/lib/storage/AppStorage.ts';
|
|
||||||
import { BrowserUtil } from '@/lib/BrowserUtil.ts';
|
|
||||||
import { STABLE_EMPTY_OBJECT } from '@/base/Base.constants.ts';
|
import { STABLE_EMPTY_OBJECT } from '@/base/Base.constants.ts';
|
||||||
|
import { AppSession } from '@/base/AppSession.ts';
|
||||||
|
|
||||||
const disabledUpdateCheck = () => Promise.resolve();
|
const disabledUpdateCheck = () => Promise.resolve();
|
||||||
|
|
||||||
const INITIAL_LOAD_TIMESTAMP_KEY = 'webUIInitialLoadTimestamp';
|
|
||||||
|
|
||||||
if (BrowserUtil.isActualPageLoad()) {
|
|
||||||
AppStorage.session.setItem(INITIAL_LOAD_TIMESTAMP_KEY, Date.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
export const WebUIUpdateChecker = () => {
|
export const WebUIUpdateChecker = () => {
|
||||||
const { t } = useLingui();
|
const { t } = useLingui();
|
||||||
|
|
||||||
const [webUIVersion, setWebUIVersion] = useLocalStorage<string>('webUIVersion');
|
const [webUIVersion, setWebUIVersion] = useLocalStorage<string>('webUIVersion');
|
||||||
const [initialLoadTimestamp] = useSessionStorage<number>(INITIAL_LOAD_TIMESTAMP_KEY, Date.now());
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -81,7 +73,7 @@ export const WebUIUpdateChecker = () => {
|
|||||||
const newVersion = aboutWebUI?.tag;
|
const newVersion = aboutWebUI?.tag;
|
||||||
const isSameAsCurrent = !newVersion || !webUIVersion || webUIVersion === newVersion;
|
const isSameAsCurrent = !newVersion || !webUIVersion || webUIVersion === newVersion;
|
||||||
|
|
||||||
const shouldForceRefresh = initialLoadTimestamp < Number(aboutWebUI?.updateTimestamp);
|
const shouldForceRefresh = AppSession.STARTUP_TIMESTAMP < Number(aboutWebUI?.updateTimestamp);
|
||||||
|
|
||||||
const saveInitialVersion = !webUIVersion && !!newVersion;
|
const saveInitialVersion = !webUIVersion && !!newVersion;
|
||||||
if (saveInitialVersion) {
|
if (saveInitialVersion) {
|
||||||
|
|||||||
@@ -698,6 +698,10 @@ msgstr "By upload date"
|
|||||||
msgid "Call timeout"
|
msgid "Call timeout"
|
||||||
msgstr "Call timeout"
|
msgstr "Call timeout"
|
||||||
|
|
||||||
|
#: src/features/migration/MangaMigration.ts
|
||||||
|
msgid "Can't migrate an entry to itself"
|
||||||
|
msgstr "Can't migrate an entry to itself"
|
||||||
|
|
||||||
#: src/base/collection/components/SelectableCollectionSelectMode.tsx
|
#: src/base/collection/components/SelectableCollectionSelectMode.tsx
|
||||||
#: src/base/components/inputs/LanguageSelect.tsx
|
#: src/base/components/inputs/LanguageSelect.tsx
|
||||||
#: src/base/components/modals/ConfirmDialog.tsx
|
#: src/base/components/modals/ConfirmDialog.tsx
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
import { StrictMode } from 'react';
|
import { StrictMode } from 'react';
|
||||||
import { createRoot } from 'react-dom/client';
|
import { createRoot } from 'react-dom/client';
|
||||||
|
|
||||||
|
import '@/base/AppSession.ts';
|
||||||
import '@/index.css';
|
import '@/index.css';
|
||||||
import '@/polyfill.manual';
|
import '@/polyfill.manual';
|
||||||
import { initializeLocalization } from '@/i18n';
|
import { initializeLocalization } from '@/i18n';
|
||||||
|
|||||||
Reference in New Issue
Block a user