Skip to content

Instantly share code, notes, and snippets.

@ahkohd
Last active April 5, 2020 22:15
Show Gist options
  • Save ahkohd/c6b0e706193795bdc969129703d32f46 to your computer and use it in GitHub Desktop.
Save ahkohd/c6b0e706193795bdc969129703d32f46 to your computer and use it in GitHub Desktop.
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