Skip to content

Commit cff7785

Browse files
committed
feat: keep device information up to date
Previously, we only fetched the device information (including the compliance state) once when loading the accounts. However the compliance state can change over time (it is updated approximately every 1 hour). To always show an up-to-date version, we refresh it if it is older than 30 mins. To avoid frequent API calls to MS, we perform the refresh lazily when opening the UI. Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
1 parent 1e43440 commit cff7785

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/background.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ function notify_state_change(ui_only = false) {
102102
);
103103
}
104104
if (port_menu === null) return;
105+
deviceManager.updateDeviceInfo().then((updated) => {
106+
if (updated) {
107+
notify_state_change(true);
108+
}
109+
});
105110
port_menu.postMessage({
106111
event: "stateChanged",
107112
accounts: accountManager.getRegistered().map((a) => a.toMenuObject()),

src/device.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,29 @@ export class Device {
1616
}
1717

1818
export class DeviceManager {
19+
static DEVICE_REFRESH_INTERVAL_MIN = 30;
20+
1921
#am = null;
22+
#last_refresh = 0;
2023
device = null;
2124

2225
constructor(account_manager) {
2326
this.#am = account_manager;
2427
this.device = null;
2528
}
2629

30+
async updateDeviceInfo() {
31+
if (
32+
Date.now() <
33+
this.#last_refresh +
34+
DeviceManager.DEVICE_REFRESH_INTERVAL_MIN * 60 * 1000
35+
) {
36+
return false;
37+
}
38+
await this.loadDeviceInfo();
39+
return true;
40+
}
41+
2742
async loadDeviceInfo() {
2843
if (!this.#am.hasAccounts()) {
2944
return;
@@ -50,7 +65,9 @@ export class DeviceManager {
5065
return;
5166
}
5267
const data = await response.json();
68+
this.#last_refresh = Date.now();
5369
this.device = new Device(data.displayName, data.isCompliant);
70+
ssoLog("updated device information");
5471
}
5572

5673
getDevice() {

0 commit comments

Comments
 (0)