signal-desktop/ts/services/bounce.ts

34 lines
811 B
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-06-04 18:16:19 +00:00
import { app, BrowserWindow, ipcMain } from 'electron';
let bounceId = -1;
2020-09-03 14:59:24 +00:00
export function init(win: BrowserWindow): void {
2020-06-04 18:16:19 +00:00
ipcMain.on('bounce-app-icon-start', (_, isCritical = false) => {
if (app.dock) {
const type = isCritical ? 'critical' : 'informational';
bounceId = app.dock.bounce(type);
} else if (win && win.flashFrame) {
win.once('focus', () => {
win.flashFrame(false);
});
win.flashFrame(true);
}
});
ipcMain.on('bounce-app-icon-stop', () => {
if (app.dock) {
if (bounceId < 0) {
return;
}
app.dock.cancelBounce(bounceId);
bounceId = -1;
} else if (win && win.flashFrame) {
win.flashFrame(false);
}
});
}