Add whatsapp terminal command and single-instance window focus
This commit is contained in:
1 parent
2b7460d976
commit
510daa9c9a
3 files changed
+35
-4
No files matched your search
@@ -18,6 +18,14 @@ const WHATSAPP_URL = 'https://web.whatsapp.com/';
|
||||
const WHATSAPP_ORIGIN = new URL(WHATSAPP_URL).origin;
|
||||
const PARTITION = 'persist:whatsapp';
|
||||
|
||||
let mainWindow = null;
|
||||
|
||||
// Launching the app again (e.g. `whatsapp` in a terminal) should focus the
|
||||
// window we already have instead of starting a second client.
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
function isWhatsAppUrl(rawUrl) {
|
||||
try {
|
||||
const url = new URL(rawUrl);
|
||||
@@ -176,10 +184,16 @@ function createWindow() {
|
||||
|
||||
downloadToast.setWindow(win);
|
||||
|
||||
mainWindow = win;
|
||||
|
||||
// Keep WhatsApp notifying while another app has focus.
|
||||
notifications.install(win);
|
||||
|
||||
win.on('closed', () => {
|
||||
if (mainWindow === win) {
|
||||
mainWindow = null;
|
||||
}
|
||||
|
||||
downloadToast.closeAll();
|
||||
});
|
||||
|
||||
@@ -209,6 +223,20 @@ function createWindow() {
|
||||
return win;
|
||||
}
|
||||
|
||||
app.on('second-instance', () => {
|
||||
if (!mainWindow || mainWindow.isDestroyed()) {
|
||||
createWindow();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
});
|
||||
|
||||
app.whenReady().then(() => {
|
||||
const whatsappSession = session.fromPartition(PARTITION);
|
||||
|
||||
@@ -241,10 +269,12 @@ app.whenReady().then(() => {
|
||||
downloadToast.registerIpc();
|
||||
notifications.registerIpc();
|
||||
|
||||
if (!mainWindow) {
|
||||
createWindow();
|
||||
}
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
if (!mainWindow) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "whatsapp-desktop",
|
||||
"version": "1.0.8",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "whatsapp-desktop",
|
||||
"version": "1.0.8",
|
||||
"version": "1.1.0",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"electron": "latest",
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "whatsapp-desktop",
|
||||
"version": "1.0.8",
|
||||
"version": "1.1.0",
|
||||
"description": "Unofficial WhatsApp Web desktop client for Linux",
|
||||
"private": true,
|
||||
"author": {
|
||||
@@ -40,6 +40,7 @@
|
||||
],
|
||||
"linux": {
|
||||
"category": "Network;InstantMessaging",
|
||||
"executableName": "whatsapp",
|
||||
"icon": "build/icons",
|
||||
"syncDesktopName": true,
|
||||
"target": [
|
||||
|
||||
Reference in new issue
Block a user