forked from akai/readest
* added current time to desktop bar * added time prototype to footer, needs code cleanup and settings toggle * fixed settings toggle, added translations and code cleanup * added battery support and moved Statusbar to own Component * #3306 added 24 hour clock support * refactored code styling and getting rid of any type in battery hook * Add battery info for Tauri Apps --------- Co-authored-by: Huang Xin <chrox.huang@gmail.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { useEffect, useState, useMemo } from 'react';
|
||||
|
||||
export function useCurrentTime(enabled: boolean, use24Hour = true, intervalMs = 10000) {
|
||||
const [currentTime, setCurrentTime] = useState(() => new Date());
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
|
||||
const timer = setInterval(() => {
|
||||
setCurrentTime(new Date());
|
||||
}, intervalMs);
|
||||
|
||||
return () => clearInterval(timer);
|
||||
}, [enabled, intervalMs]);
|
||||
|
||||
return useMemo(() => {
|
||||
if (!enabled) return '';
|
||||
|
||||
return currentTime.toLocaleTimeString([], {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: !use24Hour,
|
||||
});
|
||||
}, [currentTime, enabled, use24Hour]);
|
||||
}
|
||||
Reference in New Issue
Block a user