-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow user to input shortcuts in the Shortcut component (requir…
…es backend changes) (#523) * feat: allow user to input shortcuts in the Shortcut component * refactor(renderer): extract tray icon logic to custom hook * refactor(renderer): use event.key to make code more understandable * fix(renderer): redo shortcut now ignores Z character casing, it uses the shift key * chore: update some comments * refactor: rename close, minimize and show events to reflect better its behaviour
- Loading branch information
Showing
16 changed files
with
157 additions
and
107 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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { CounterContext } from "contexts"; | ||
import { useEffect, useContext } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import type { AppStateTypes } from "store"; | ||
import { TraySVG } from "components"; | ||
import { encodeSvg } from "utils"; | ||
|
||
export const useTrayIconUpdates = ( | ||
onNewIcon: (dataUrl: string) => void | ||
) => { | ||
const timer = useSelector((state: AppStateTypes) => state.timer); | ||
|
||
const { count, duration, timerType } = useContext(CounterContext); | ||
const dashOffset = (duration - count) * (24 / duration); | ||
|
||
useEffect(() => { | ||
if (timer.playing) { | ||
const canvas = document.createElement("canvas"); | ||
const ctx = canvas.getContext("2d"); | ||
|
||
canvas.width = 16; | ||
canvas.height = 16; | ||
|
||
let svgXML = encodeSvg( | ||
<TraySVG timerType={timerType} dashOffset={dashOffset} /> | ||
); | ||
|
||
const img = new Image(); | ||
img.src = svgXML; | ||
|
||
img.onload = function () { | ||
ctx?.drawImage(img, 0, 0); | ||
const dataUrl = canvas.toDataURL("image/png"); | ||
|
||
onNewIcon(dataUrl); | ||
}; | ||
} | ||
}, [onNewIcon, timer.playing, timerType, dashOffset]); | ||
}; |
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
Oops, something went wrong.