From c972ce223e899acc540d2c64a417cd9ef8dcc4e9 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Tue, 18 Jun 2024 02:02:42 -0700 Subject: [PATCH] Mobile: Fixes #10593: Fix plugin list not cached in config screen (#10599) Co-authored-by: Laurent Cozic --- .../ConfigScreen/plugins/testUtils/newRepoApi.ts | 2 +- .../screens/ConfigScreen/plugins/utils/useRepoApi.ts | 2 +- packages/lib/services/plugins/RepositoryApi.ts | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/app-mobile/components/screens/ConfigScreen/plugins/testUtils/newRepoApi.ts b/packages/app-mobile/components/screens/ConfigScreen/plugins/testUtils/newRepoApi.ts index a7f989a3e8..bd95860b9e 100644 --- a/packages/app-mobile/components/screens/ConfigScreen/plugins/testUtils/newRepoApi.ts +++ b/packages/app-mobile/components/screens/ConfigScreen/plugins/testUtils/newRepoApi.ts @@ -6,7 +6,7 @@ import { createTempDir, supportDir } from '@joplin/lib/testing/test-utils'; const newRepoApi = async (installMode: InstallMode, appVersion = '3.0.0'): Promise => { const appInfo = { type: AppType.Mobile, version: appVersion }; const repo = new RepositoryApi(`${supportDir}/pluginRepo`, await createTempDir(), appInfo, installMode); - await repo.initialize(); + await repo.reinitialize(); return repo; }; diff --git a/packages/app-mobile/components/screens/ConfigScreen/plugins/utils/useRepoApi.ts b/packages/app-mobile/components/screens/ConfigScreen/plugins/utils/useRepoApi.ts index 7d7dda7826..3ff1a47c7a 100644 --- a/packages/app-mobile/components/screens/ConfigScreen/plugins/utils/useRepoApi.ts +++ b/packages/app-mobile/components/screens/ConfigScreen/plugins/utils/useRepoApi.ts @@ -35,7 +35,7 @@ const useRepoApi = ({ reloadRepoCounter, setRepoApiError, onRepoApiLoaded }: Pro setRepoApiError(null); try { - await repoApi.initialize(); + await repoApi.reinitialize(); } catch (error) { logger.error(error); setRepoApiError(error); diff --git a/packages/lib/services/plugins/RepositoryApi.ts b/packages/lib/services/plugins/RepositoryApi.ts index 35a63d753b..cb0c5c50d0 100644 --- a/packages/lib/services/plugins/RepositoryApi.ts +++ b/packages/lib/services/plugins/RepositoryApi.ts @@ -77,6 +77,7 @@ export default class RepositoryApi { private githubApiUrl_: string; private contentBaseUrl_: string; private isUsingDefaultContentUrl_ = true; + private lastInitializedTime_ = 0; public constructor(baseUrl: string, tempDir: string, appInfo: AppInfo, installMode: InstallMode) { this.installMode_ = installMode; @@ -102,6 +103,15 @@ export default class RepositoryApi { await this.loadManifests(); await this.loadRelease(); + + this.lastInitializedTime_ = Date.now(); + } + + public async reinitialize() { + // Refresh at most once per minute + if (Date.now() - this.lastInitializedTime_ > 5 * 60000) { + await this.initialize(); + } } private async loadManifests() {