⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/renderer/hooks/timers/useInactivityTimer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useCallback, useEffect, useRef } from 'react';

import { isOnline } from '../../utils/network';

const events = ['mousedown', 'keypress', 'click'];

/**
Expand All @@ -23,8 +25,10 @@ export const useInactivityTimer = (callback: () => void, delay: number) => {

if (delay !== null && savedCallback.current) {
timeoutRef.current = setTimeout(() => {
// Fire callback once inactivity threshold reached
savedCallback.current();
// Fire callback once inactivity threshold reached if online
if (savedCallback.current && isOnline()) {
savedCallback.current();
}

// Schedule next run while still inactive
resetTimer();
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/hooks/timers/useIntervalTimer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useEffect, useRef } from 'react';

import { isOnline } from '../../utils/network';

/**
* Hook that triggers a callback after a specified period of time.
*
Expand All @@ -16,7 +18,9 @@ export const useIntervalTimer = (callback: () => void, delay: number) => {
// Set up the interval.
useEffect(() => {
function tick() {
savedCallback.current();
if (savedCallback.current && isOnline()) {
savedCallback.current();
}
}

if (delay !== null) {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/utils/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Simple utility to centralize online status checks
export const isOnline = (): boolean => {
return typeof navigator !== 'undefined' ? navigator.onLine : true;
};

export default isOnline;