Skip to content

Commit

Permalink
apply suggestions from code review
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Seese <seesemichaelj@gmail.com>
  • Loading branch information
mikeseese committed Jul 24, 2024
1 parent d28209a commit 3866dec
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions pkg/rancher-desktop/main/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,12 @@ export class Tray {
}
}

if (this.runBuildFromConfigTimer === null) {
// This prevents calling buildFromConfig multiple times in quick succession
// while making sure that the last file change within the period is processed.
this.runBuildFromConfigTimer = setTimeout(() => {
this.runBuildFromConfigTimer = null;
this.buildFromConfig();
}, 1_000);
}
// This prevents calling buildFromConfig multiple times in quick succession
// while making sure that the last file change within the period is processed.
this.runBuildFromConfigTimer ||= setTimeout(() => {
this.runBuildFromConfigTimer = null;
this.buildFromConfig();
}, 1_000);
}));
}

Expand Down Expand Up @@ -190,24 +188,20 @@ export class Tray {
this.buildFromConfig();
this.watchForChanges();

/**
* We reset the watchers on an interval in the event that `fs.watch` silently
* fails to keep watching. This original issue is documented at
* https://github.com/rancher-sandbox/rancher-desktop/pull/2038 and further discussed at
* https://github.com/rancher-sandbox/rancher-desktop/pull/7238#discussion_r1690128729
*/
// We reset the watchers on an interval in the event that `fs.watch` silently
// fails to keep watching. This original issue is documented at
// https://github.com/rancher-sandbox/rancher-desktop/pull/2038 and further discussed at
// https://github.com/rancher-sandbox/rancher-desktop/pull/7238#discussion_r1690128729
this.fsWatcherInterval = setInterval(() => this.watchForChanges(), 5 * 60_000);

mainEvents.on('backend-locked-update', this.backendStateEvent);
mainEvents.emit('backend-locked-check');
mainEvents.on('k8s-check-state', this.k8sStateChangedEvent);
mainEvents.on('settings-update', this.settingsUpdateEvent);

/**
* This triggers the CONNECTED_TO_INTERNET diagnostic at a set interval and
* updates the network status in the tray if there's a change in the network
* state.
*/
// This triggers the CONNECTED_TO_INTERNET diagnostic at a set interval and
// updates the network status in the tray if there's a change in the network
// state.
this.networkInterval = setInterval(async() => {
const networkDiagnostic = await mainEvents.invoke('diagnostics-trigger', 'CONNECTED_TO_INTERNET');

Expand Down Expand Up @@ -264,6 +258,7 @@ export class Tray {
clearInterval(this.networkInterval);
if (this.runBuildFromConfigTimer) {
clearTimeout(this.runBuildFromConfigTimer);
this.runBuildFromConfigTimer = null;
}
for (const watcher of this.kubeConfigWatchers) {
watcher.close();
Expand Down

0 comments on commit 3866dec

Please sign in to comment.