Last active
April 5, 2020 22:15
-
-
Save ahkohd/c6b0e706193795bdc969129703d32f46 to your computer and use it in GitHub Desktop.
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
import { remote, BrowserWindow } from 'electron'; | |
const fadeWindowOut = ( | |
_window: BrowserWindow, | |
step: number = 0.1, | |
fadeEveryXSeconds: number = 10 | |
) => { | |
let opacity = _window.getOpacity(); | |
const interval = setInterval(() => { | |
if (opacity <= 0) window.clearInterval(interval); | |
_window.setOpacity(opacity); | |
opacity -= step; | |
}, fadeEveryXSeconds); | |
return interval; | |
} | |
const fadeWindowIn = ( | |
_window: BrowserWindow, | |
step: number = 0.1, | |
fadeEveryXSeconds: number = 10 | |
) => { | |
let opacity = _window.getOpacity(); | |
const interval = setInterval(() => { | |
if (opacity >= 1) window.clearInterval(interval); | |
_window.setOpacity(opacity); | |
opacity += step; | |
}, fadeEveryXSeconds); | |
return interval; | |
} | |
// fade-out window... | |
let fadeOutWindowTimeIntervalRef = fadeWindowOut(remote.getCurrentWindow(), 0.1, 2) | |
// if you want to stop fade-out at will... | |
window.clearInterval(fadeOutWindowTimeIntervalRef); | |
// fade-in window... | |
let fadeInWindowTimeIntervalRef = fadeWindowIn(remote.getCurrentWindow(), 0.1, 2) | |
// if you want to stop fade-in at will... | |
window.clearInterval(fadeInWindowTimeIntervalRef); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment