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 WHATSAPP_ORIGIN = new URL(WHATSAPP_URL).origin;
|
||||||
const PARTITION = 'persist:whatsapp';
|
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) {
|
function isWhatsAppUrl(rawUrl) {
|
||||||
try {
|
try {
|
||||||
const url = new URL(rawUrl);
|
const url = new URL(rawUrl);
|
||||||
@@ -176,10 +184,16 @@ function createWindow() {
|
|||||||
|
|
||||||
downloadToast.setWindow(win);
|
downloadToast.setWindow(win);
|
||||||
|
|
||||||
|
mainWindow = win;
|
||||||
|
|
||||||
// Keep WhatsApp notifying while another app has focus.
|
// Keep WhatsApp notifying while another app has focus.
|
||||||
notifications.install(win);
|
notifications.install(win);
|
||||||
|
|
||||||
win.on('closed', () => {
|
win.on('closed', () => {
|
||||||
|
if (mainWindow === win) {
|
||||||
|
mainWindow = null;
|
||||||
|
}
|
||||||
|
|
||||||
downloadToast.closeAll();
|
downloadToast.closeAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -209,6 +223,20 @@ function createWindow() {
|
|||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.on('second-instance', () => {
|
||||||
|
if (!mainWindow || mainWindow.isDestroyed()) {
|
||||||
|
createWindow();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mainWindow.isMinimized()) {
|
||||||
|
mainWindow.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
mainWindow.show();
|
||||||
|
mainWindow.focus();
|
||||||
|
});
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
const whatsappSession = session.fromPartition(PARTITION);
|
const whatsappSession = session.fromPartition(PARTITION);
|
||||||
|
|
||||||
@@ -241,10 +269,12 @@ app.whenReady().then(() => {
|
|||||||
downloadToast.registerIpc();
|
downloadToast.registerIpc();
|
||||||
notifications.registerIpc();
|
notifications.registerIpc();
|
||||||
|
|
||||||
|
if (!mainWindow) {
|
||||||
createWindow();
|
createWindow();
|
||||||
|
}
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
if (BrowserWindow.getAllWindows().length === 0) {
|
if (!mainWindow) {
|
||||||
createWindow();
|
createWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "whatsapp-desktop",
|
"name": "whatsapp-desktop",
|
||||||
"version": "1.0.8",
|
"version": "1.1.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "whatsapp-desktop",
|
"name": "whatsapp-desktop",
|
||||||
"version": "1.0.8",
|
"version": "1.1.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "latest",
|
"electron": "latest",
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "whatsapp-desktop",
|
"name": "whatsapp-desktop",
|
||||||
"version": "1.0.8",
|
"version": "1.1.0",
|
||||||
"description": "Unofficial WhatsApp Web desktop client for Linux",
|
"description": "Unofficial WhatsApp Web desktop client for Linux",
|
||||||
"private": true,
|
"private": true,
|
||||||
"author": {
|
"author": {
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
],
|
],
|
||||||
"linux": {
|
"linux": {
|
||||||
"category": "Network;InstantMessaging",
|
"category": "Network;InstantMessaging",
|
||||||
|
"executableName": "whatsapp",
|
||||||
"icon": "build/icons",
|
"icon": "build/icons",
|
||||||
"syncDesktopName": true,
|
"syncDesktopName": true,
|
||||||
"target": [
|
"target": [
|
||||||
|
|||||||
Reference in new issue
Block a user