-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrefreshManager.js
More file actions
110 lines (99 loc) · 3.29 KB
/
Copy pathrefreshManager.js
File metadata and controls
110 lines (99 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import GLib from "gi://GLib";
export class RefreshManager {
/**
* @param {object} opts
* @param {import('gi://Gio').Settings} opts.settings
* @param {function(): void} opts.loadRepositories
* @param {function(): void} opts.loadNotifications
* @param {function(): void} opts.loadMonitoredWorkflowRuns
*/
constructor({ settings, loadRepositories, loadNotifications, loadMonitoredWorkflowRuns }) {
this._settings = settings;
this._loadRepositories = loadRepositories;
this._loadNotifications = loadNotifications;
this._loadMonitoredWorkflowRuns = loadMonitoredWorkflowRuns;
this._refreshTimeout = null;
this._notificationRefreshTimeout = null;
this._monitoredWorkflowRefreshTimeout = null;
}
// Starts periodic repository refresh (every 5 minutes)
setupAutoRefresh() {
if (this._refreshTimeout) {
GLib.source_remove(this._refreshTimeout);
this._refreshTimeout = null;
}
this._refreshTimeout = GLib.timeout_add_seconds(
GLib.PRIORITY_DEFAULT,
300,
() => {
this._loadRepositories();
return GLib.SOURCE_CONTINUE;
},
);
}
// Starts periodic notification refresh based on the configured interval
setupNotificationRefresh() {
if (!this._settings.get_boolean("show-notifications")) return;
if (this._notificationRefreshTimeout) {
GLib.source_remove(this._notificationRefreshTimeout);
this._notificationRefreshTimeout = null;
}
const interval = this._settings.get_int("notification-interval");
this._notificationRefreshTimeout = GLib.timeout_add_seconds(
GLib.PRIORITY_DEFAULT,
interval,
() => {
if (this._settings.get_boolean("show-notifications")) {
this._loadNotifications();
}
return GLib.SOURCE_CONTINUE;
},
);
}
// Starts periodic monitored workflow refresh (every 5 minutes)
setupMonitoredWorkflowRefresh() {
if (this._monitoredWorkflowRefreshTimeout) {
GLib.source_remove(this._monitoredWorkflowRefreshTimeout);
this._monitoredWorkflowRefreshTimeout = null;
}
const interval = 300;
this._monitoredWorkflowRefreshTimeout = GLib.timeout_add_seconds(
GLib.PRIORITY_DEFAULT,
interval,
() => {
this._loadMonitoredWorkflowRuns();
return GLib.SOURCE_CONTINUE;
},
);
}
// Restarts the notification refresh timer (e.g. when show-notifications setting changes)
restartNotificationRefresh() {
if (this._notificationRefreshTimeout) {
GLib.source_remove(this._notificationRefreshTimeout);
this._notificationRefreshTimeout = null;
}
this.setupNotificationRefresh();
if (this._settings.get_boolean("show-notifications")) {
this._loadNotifications();
}
}
// Removes all active refresh timers
cleanup() {
if (this._refreshTimeout) {
GLib.source_remove(this._refreshTimeout);
this._refreshTimeout = null;
}
if (this._notificationRefreshTimeout) {
GLib.source_remove(this._notificationRefreshTimeout);
this._notificationRefreshTimeout = null;
}
if (this._monitoredWorkflowRefreshTimeout) {
GLib.source_remove(this._monitoredWorkflowRefreshTimeout);
this._monitoredWorkflowRefreshTimeout = null;
}
}
destroy() {
this.cleanup();
this._settings = null;
}
}