Skip to content

Commit 8f98c8a

Browse files
committed
fix: skip if offline
1 parent c1f82c0 commit 8f98c8a

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/background/index.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,29 @@ async function refresh(withNotifications: boolean) {
2323
periodInMinutes: 1,
2424
});
2525

26-
const accessToken = await stores.accessToken.get();
26+
if (navigator.onLine) {
27+
const accessToken = await stores.accessToken.get();
2728

28-
let currentUser: HelixUser | null = null;
29-
let followedStreams = new Array<HelixStream>();
29+
let currentUser: HelixUser | null = null;
30+
let followedStreams = new Array<HelixStream>();
3031

31-
if (accessToken) {
32-
currentUser = await getCurrentUser();
32+
if (accessToken) {
33+
currentUser = await getCurrentUser();
3334

34-
if (currentUser) {
35-
followedStreams = await getFollowedStreams(currentUser.id);
35+
if (currentUser) {
36+
followedStreams = await getFollowedStreams(currentUser.id);
37+
}
3638
}
37-
}
3839

39-
refreshActionBadge(!!currentUser, followedStreams.length);
40+
refreshActionBadge(!!currentUser, followedStreams.length);
4041

41-
if (withNotifications) {
42-
sendStreamNotifications(await filterNewStreams(followedStreams));
43-
}
42+
if (withNotifications) {
43+
sendStreamNotifications(await filterNewStreams(followedStreams));
44+
}
4445

45-
stores.currentUser.set(currentUser);
46-
stores.followedStreams.set(followedStreams);
46+
stores.currentUser.set(currentUser);
47+
stores.followedStreams.set(followedStreams);
48+
}
4749
}
4850

4951
async function checkAlaram() {

0 commit comments

Comments
 (0)