This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEMP COMMIT2 TEMP disable all thingse that break
- Loading branch information
1 parent
69d740d
commit 00293c0
Showing
28 changed files
with
2,112 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
import { remote } from 'electron'; | ||
// import { remote } from 'electron'; | ||
import { useState, useEffect, useCallback } from 'react'; | ||
|
||
export type WindowActiveState = 'focused' | 'blurred'; | ||
|
||
export function useWindowFocus() { | ||
const [win] = remote.BrowserWindow.getAllWindows(); | ||
const [windowState, setWindowState] = useState<WindowActiveState>( | ||
win.isFocused() ? 'focused' : 'blurred' | ||
); | ||
|
||
const focusHandler = useCallback(() => setWindowState('focused'), []); | ||
const blurHandler = useCallback(() => setWindowState('blurred'), []); | ||
|
||
useEffect(() => { | ||
win.on('focus', focusHandler); | ||
win.on('blur', blurHandler); | ||
|
||
window.addEventListener('beforeunload', () => { | ||
win.removeListener('focus', focusHandler); | ||
win.removeListener('blur', blurHandler); | ||
}); | ||
|
||
return () => { | ||
win.removeListener('focus', focusHandler); | ||
win.removeListener('blur', blurHandler); | ||
}; | ||
}, [blurHandler, focusHandler, win]); | ||
return windowState; | ||
// const [win] = remote.BrowserWindow.getAllWindows(); | ||
// const [windowState, setWindowState] = useState<WindowActiveState>( | ||
// win.isFocused() ? 'focused' : 'blurred' | ||
// ); | ||
// const focusHandler = useCallback(() => setWindowState('focused'), []); | ||
// const blurHandler = useCallback(() => setWindowState('blurred'), []); | ||
// useEffect(() => { | ||
// win.on('focus', focusHandler); | ||
// win.on('blur', blurHandler); | ||
// window.addEventListener('beforeunload', () => { | ||
// win.removeListener('focus', focusHandler); | ||
// win.removeListener('blur', blurHandler); | ||
// }); | ||
// return () => { | ||
// win.removeListener('focus', focusHandler); | ||
// win.removeListener('blur', blurHandler); | ||
// }; | ||
// }, [blurHandler, focusHandler, win]); | ||
// return windowState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.