Skip to content

Commit

Permalink
fix: check for recent episodes only if network is active
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Sep 15, 2022
1 parent 50ea2f9 commit f48786b
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions src/app/modules/background/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,32 @@ export class MainComponent implements OnInit {

private autoCheckLoop() {
setTimeout(async () => {
// Check for recent episodes
const [count, notifications] = await this.getRecentEpisodesCount();
this.debug.log('Recent episodes count:', count);
if (count > 0) {
// Set badge count
const badgeText: string = await this.browser.getBadgeText();
if (badgeText.length) {
this.badgeCount += count;
} else {
this.badgeCount = count;
}
this.debug.log('Total count:', this.badgeCount);
this.browser.setBadgeText(this.badgeCount);
// Notify
if (this.settings.enableNotifications) {
notifications.forEach((notification: EpisodeNotification) => {
this.notifications.push(
notification.message,
NotificationType.Success
);
const id = now().getTime() + '::' + notification.episode.index;
this.browser.sendNotification(notification.message, id);
});
this.debug.log('online:', navigator.onLine);
if (navigator.onLine) {
// Check for recent episodes
const [count, notifications] = await this.getRecentEpisodesCount();
this.debug.log('Recent episodes count:', count);
if (count > 0) {
// Set badge count
const badgeText: string = await this.browser.getBadgeText();
if (badgeText.length) {
this.badgeCount += count;
} else {
this.badgeCount = count;
}
this.debug.log('Total count:', this.badgeCount);
this.browser.setBadgeText(this.badgeCount);
// Notify
if (this.settings.enableNotifications) {
notifications.forEach((notification: EpisodeNotification) => {
this.notifications.push(
notification.message,
NotificationType.Success
);
const id = now().getTime() + '::' + notification.episode.index;
this.browser.sendNotification(notification.message, id);
});
}
}
}
// Re-loop
Expand Down

0 comments on commit f48786b

Please sign in to comment.