diff --git a/package.json b/package.json index f50c8a823ac..7c4691b2514 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "@mediapipe/tasks-vision": "0.10.18", "@wireapp/avs": "9.10.16", "@wireapp/commons": "5.4.0", - "@wireapp/core": "46.12.0", + "@wireapp/core": "46.13.0", "@wireapp/react-ui-kit": "9.28.0", "@wireapp/store-engine-dexie": "2.1.15", "@wireapp/telemetry": "0.1.3", diff --git a/src/script/auth/main.tsx b/src/script/auth/main.tsx index 177562ebbbf..f01c58f89a0 100644 --- a/src/script/auth/main.tsx +++ b/src/script/auth/main.tsx @@ -38,6 +38,7 @@ import {actionRoot} from './module/action'; import {Root} from './page/Root'; import {Config} from '../Config'; +import {updateApiVersion} from '../lifecycle/updateRemoteConfigs'; import {setAppLocale} from '../localization/Localizer'; import {APIClient} from '../service/APIClientSingleton'; import {Core} from '../service/CoreSingleton'; @@ -77,8 +78,7 @@ const render = (Component: FC): void => { const config = Config.getConfig(); async function runApp() { - const [min, max] = config.SUPPORTED_API_RANGE; - const {domain} = await core.useAPIVersion(min, max, config.ENABLE_DEV_BACKEND_API); + const {domain} = await updateApiVersion(); await initializeDataDog(config, {domain: domain}); render(Root); diff --git a/src/script/lifecycle/updateRemoteConfigs.ts b/src/script/lifecycle/updateRemoteConfigs.ts new file mode 100644 index 00000000000..a559ed45099 --- /dev/null +++ b/src/script/lifecycle/updateRemoteConfigs.ts @@ -0,0 +1,60 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + * + */ + +import {TaskParams} from '@wireapp/core/lib/util/RecurringTaskScheduler'; +import {container} from 'tsyringe'; + +import {getLogger} from 'Util/Logger'; +import {TIME_IN_MILLIS} from 'Util/TimeUtil'; + +import {Config} from '../Config'; +import {Core} from '../service/CoreSingleton'; + +let core: Core | undefined = undefined; +export const updateRemoteConfigLogger = getLogger('updateRemoteConfigs'); + +export const scheduleRecurringTask = async (params: TaskParams) => { + if (!core) { + core = container.resolve(Core); + } + return core.recurringTaskScheduler.registerTask(params); +}; + +export const updateApiVersion = async () => { + if (!core) { + core = container.resolve(Core); + } + const { + SUPPORTED_API_RANGE: [min, max], + ENABLE_DEV_BACKEND_API, + } = Config.getConfig(); + + updateRemoteConfigLogger.info('Updating api-version and info'); + return core.useAPIVersion(min, max, ENABLE_DEV_BACKEND_API); +}; + +export const scheduleApiVersionUpdate = async () => { + // Schedule the task to run every day and add it to the window focus event + await scheduleRecurringTask({ + every: TIME_IN_MILLIS.DAY, + task: updateApiVersion, + key: 'try-api-version-backend-sync', + addTaskOnWindowFocusEvent: true, + }); +}; diff --git a/src/script/main/app.ts b/src/script/main/app.ts index f3951c49ade..e64605cf6af 100644 --- a/src/script/main/app.ts +++ b/src/script/main/app.ts @@ -85,6 +85,7 @@ import {externalUrl} from '../externalRoute'; import {IntegrationRepository} from '../integration/IntegrationRepository'; import {IntegrationService} from '../integration/IntegrationService'; import {startNewVersionPolling} from '../lifecycle/newVersionHandler'; +import {scheduleApiVersionUpdate, updateApiVersion} from '../lifecycle/updateRemoteConfigs'; import {MediaRepository} from '../media/MediaRepository'; import {initMLSGroupConversations, initialiseSelfAndTeamConversations} from '../mls'; import {joinConversationsAfterMigrationFinalisation} from '../mls/MLSMigration/migrationFinaliser'; @@ -343,8 +344,8 @@ export class App { async initApp(clientType: ClientType, onProgress: (progress: number, message?: string) => void) { // add body information const startTime = Date.now(); - const [apiVersionMin, apiVersionMax] = this.config.SUPPORTED_API_RANGE; - await this.core.useAPIVersion(apiVersionMin, apiVersionMax, this.config.ENABLE_DEV_BACKEND_API); + await updateApiVersion(); + await scheduleApiVersionUpdate(); const osCssClass = Runtime.isMacOS() ? 'os-mac' : 'os-pc'; const platformCssClass = Runtime.isDesktopApp() ? 'platform-electron' : 'platform-web'; diff --git a/src/script/team/TeamRepository.ts b/src/script/team/TeamRepository.ts index 865027b14ba..6df488df779 100644 --- a/src/script/team/TeamRepository.ts +++ b/src/script/team/TeamRepository.ts @@ -55,6 +55,7 @@ import {EventSource} from '../event/EventSource'; import {NOTIFICATION_HANDLING_STATE} from '../event/NotificationHandlingState'; import {IntegrationMapper} from '../integration/IntegrationMapper'; import {ServiceEntity} from '../integration/ServiceEntity'; +import {scheduleRecurringTask, updateRemoteConfigLogger} from '../lifecycle/updateRemoteConfigs'; import {MLSMigrationStatus, getMLSMigrationStatus} from '../mls/MLSMigration/migrationStatus'; import {APIClient} from '../service/APIClientSingleton'; import {ROLE, ROLE as TEAM_ROLE, roleFromTeamPermissions} from '../user/UserPermission'; @@ -144,7 +145,7 @@ export class TeamRepository extends TypedEventEmitter { }); const members = await this.loadInitialTeamMembers(teamId); - this.scheduleTeamRefresh(); + await this.scheduleTeamRefresh(); return {team, features: newFeatureList, members}; } @@ -162,18 +163,24 @@ export class TeamRepository extends TypedEventEmitter { }; } - private readonly scheduleTeamRefresh = (): void => { + private readonly scheduleTeamRefresh = async (): Promise => { const updateTeam = async () => { try { + updateRemoteConfigLogger.info('Updating team-settings'); await this.getTeam(); await this.updateFeatureConfig(); } catch (error) { this.logger.error(error); } }; + // We want to poll the latest team data every time the app is focused and every day - window.addEventListener('focus', updateTeam); - window.setInterval(updateTeam, TIME_IN_MILLIS.DAY); + await scheduleRecurringTask({ + every: TIME_IN_MILLIS.DAY, + task: updateTeam, + key: 'team-refresh', + addTaskOnWindowFocusEvent: true, + }); }; private async getInitialTeamMembers(teamId: string): Promise { diff --git a/yarn.lock b/yarn.lock index d899021f7ec..ef2c273bcab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5941,14 +5941,14 @@ __metadata: languageName: node linkType: hard -"@wireapp/api-client@npm:^27.13.1": - version: 27.13.1 - resolution: "@wireapp/api-client@npm:27.13.1" +"@wireapp/api-client@npm:^27.13.2": + version: 27.13.2 + resolution: "@wireapp/api-client@npm:27.13.2" dependencies: "@wireapp/commons": "npm:^5.4.0" "@wireapp/priority-queue": "npm:^2.1.11" "@wireapp/protocol-messaging": "npm:1.51.0" - axios: "npm:1.7.7" + axios: "npm:1.7.9" axios-retry: "npm:4.5.0" http-status-codes: "npm:2.3.0" logdown: "npm:3.3.1" @@ -5958,7 +5958,7 @@ __metadata: tough-cookie: "npm:4.1.4" ws: "npm:8.18.0" zod: "npm:3.23.8" - checksum: 10/8e297f4da3ac3d4a052d5670b0ddcd6302c9a246ef61760c61b3ecf0e1e78b0d01107fa32a10ad70e8203e7e3a6cab0d2373cc52ece4bfd154f8840b2e9db84b + checksum: 10/1fbe961c5648fd349de4f59df29eb52e80d7999c7114066cfdfbf14a7c42e4ebfa6276218f4694aa4a141e7e6221e1b2bd9f65de48cfcd2c3207e330e00edc9d languageName: node linkType: hard @@ -6012,11 +6012,11 @@ __metadata: languageName: node linkType: hard -"@wireapp/core@npm:46.12.0": - version: 46.12.0 - resolution: "@wireapp/core@npm:46.12.0" +"@wireapp/core@npm:46.13.0": + version: 46.13.0 + resolution: "@wireapp/core@npm:46.13.0" dependencies: - "@wireapp/api-client": "npm:^27.13.1" + "@wireapp/api-client": "npm:^27.13.2" "@wireapp/commons": "npm:^5.4.0" "@wireapp/core-crypto": "npm:2.0.0" "@wireapp/cryptobox": "npm:12.8.0" @@ -6024,7 +6024,7 @@ __metadata: "@wireapp/promise-queue": "npm:^2.3.10" "@wireapp/protocol-messaging": "npm:1.51.0" "@wireapp/store-engine": "npm:5.1.11" - axios: "npm:1.7.7" + axios: "npm:1.7.9" bazinga64: "npm:^6.3.11" deepmerge-ts: "npm:6.0.0" hash.js: "npm:1.1.7" @@ -6034,7 +6034,7 @@ __metadata: long: "npm:^5.2.0" uuid: "npm:9.0.1" zod: "npm:3.23.8" - checksum: 10/3553572c04ade544185d65865f7f03c6ab5ff35b9bfc198da9217bdfb3fc93ed7942b792968fe6fb10c635c506cf84cd89d64d9da068dbd473ac01b034057229 + checksum: 10/30b90cdc3fdc0ba8e015bac7182244c410528ba66ed0a48c7aa647e8354e2b4fa6aa0c9e30af18923aa02551b6c10562632604c6d59537e49dc1e113d4858cb6 languageName: node linkType: hard @@ -6874,6 +6874,17 @@ __metadata: languageName: node linkType: hard +"axios@npm:1.7.9": + version: 1.7.9 + resolution: "axios@npm:1.7.9" + dependencies: + follow-redirects: "npm:^1.15.6" + form-data: "npm:^4.0.0" + proxy-from-env: "npm:^1.1.0" + checksum: 10/b7a5f660ea53ba9c2a745bf5ad77ad8bf4f1338e13ccc3f9f09f810267d6c638c03dac88b55dae8dc98b79c57d2d6835be651d58d2af97c174f43d289a9fd007 + languageName: node + linkType: hard + "axobject-query@npm:^3.1.1": version: 3.2.1 resolution: "axobject-query@npm:3.2.1" @@ -18672,7 +18683,7 @@ __metadata: "@wireapp/avs": "npm:9.10.16" "@wireapp/commons": "npm:5.4.0" "@wireapp/copy-config": "npm:2.2.10" - "@wireapp/core": "npm:46.12.0" + "@wireapp/core": "npm:46.13.0" "@wireapp/eslint-config": "npm:3.0.7" "@wireapp/prettier-config": "npm:0.6.4" "@wireapp/react-ui-kit": "npm:9.28.0"