Initial commit
No files matched your search
@@ -0,0 +1,2 @@
|
||||
dist/
|
||||
node_modules/
|
||||
|
After Width: | Height: | Size: 121 KiB |
|
After Width: | Height: | Size: 8.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
@@ -0,0 +1,135 @@
|
||||
|
||||
const {
|
||||
app,
|
||||
BrowserWindow,
|
||||
shell,
|
||||
session
|
||||
} = require('electron');
|
||||
|
||||
const path = require('node:path');
|
||||
|
||||
const WHATSAPP_URL = 'https://web.whatsapp.com/';
|
||||
const PARTITION = 'persist:whatsapp';
|
||||
|
||||
function isWhatsAppUrl(rawUrl) {
|
||||
try {
|
||||
const url = new URL(rawUrl);
|
||||
|
||||
return (
|
||||
url.protocol === 'https:' &&
|
||||
url.hostname === 'web.whatsapp.com'
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isExternalUrl(rawUrl) {
|
||||
try {
|
||||
const url = new URL(rawUrl);
|
||||
return url.protocol === 'https:';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
const win = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 850,
|
||||
minWidth: 750,
|
||||
minHeight: 550,
|
||||
title: 'WhatsApp Desktop',
|
||||
icon: path.join(__dirname, 'build', 'icon.png'),
|
||||
autoHideMenuBar: true,
|
||||
backgroundColor: '#111b21',
|
||||
webPreferences: {
|
||||
partition: PARTITION,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
sandbox: true,
|
||||
webSecurity: true,
|
||||
devTools: false
|
||||
}
|
||||
});
|
||||
|
||||
// Identify as Chromium rather than Electron.
|
||||
const chromeVersion = process.versions.chrome;
|
||||
|
||||
win.webContents.setUserAgent(
|
||||
`Mozilla/5.0 (X11; Linux x86_64) ` +
|
||||
`AppleWebKit/537.36 (KHTML, like Gecko) ` +
|
||||
`Chrome/${chromeVersion} Safari/537.36`
|
||||
);
|
||||
|
||||
// Block navigation outside WhatsApp Web.
|
||||
win.webContents.on('will-navigate', (event, url) => {
|
||||
if (!isWhatsAppUrl(url)) {
|
||||
event.preventDefault();
|
||||
|
||||
if (isExternalUrl(url)) {
|
||||
shell.openExternal(url);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Prevent new Electron windows.
|
||||
win.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (isExternalUrl(url) && !isWhatsAppUrl(url)) {
|
||||
shell.openExternal(url);
|
||||
}
|
||||
|
||||
return { action: 'deny' };
|
||||
});
|
||||
|
||||
// Disable downloads by default.
|
||||
win.webContents.session.on('will-download', (event) => {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
// Load WhatsApp Web.
|
||||
win.loadURL(WHATSAPP_URL);
|
||||
|
||||
return win;
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
const whatsappSession = session.fromPartition(PARTITION);
|
||||
|
||||
// Only allow notifications from WhatsApp Web.
|
||||
whatsappSession.setPermissionRequestHandler(
|
||||
(_webContents, permission, callback, details) => {
|
||||
const trusted = isWhatsAppUrl(
|
||||
details.requestingUrl || ''
|
||||
);
|
||||
|
||||
callback(
|
||||
trusted &&
|
||||
permission === 'notifications'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
whatsappSession.setPermissionCheckHandler(
|
||||
(_webContents, permission, requestingOrigin) => {
|
||||
return (
|
||||
permission === 'notifications' &&
|
||||
isWhatsAppUrl(requestingOrigin)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
createWindow();
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
{
|
||||
"name": "whatsapp-desktop",
|
||||
"version": "1.0.0",
|
||||
"description": "Unofficial WhatsApp Web desktop client for Linux",
|
||||
"private": true,
|
||||
"author": {
|
||||
"name": "Zoe",
|
||||
"email": "jouw-email@example.com"
|
||||
},
|
||||
"homepage": "https://web.whatsapp.com/",
|
||||
"license": "MIT",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "electron .",
|
||||
"build": "electron-builder --linux deb AppImage",
|
||||
"build:deb": "electron-builder --linux deb",
|
||||
"build:appimage": "electron-builder --linux AppImage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "latest",
|
||||
"electron-builder": "latest"
|
||||
},
|
||||
"build": {
|
||||
"appId": "nl.zoe.whatsappdesktop",
|
||||
"productName": "WhatsApp Desktop",
|
||||
"asar": true,
|
||||
"directories": {
|
||||
"output": "dist",
|
||||
"buildResources": "build"
|
||||
},
|
||||
"files": [
|
||||
"main.js",
|
||||
"package.json",
|
||||
"build/icon.png"
|
||||
],
|
||||
"linux": {
|
||||
"category": "Network;InstantMessaging",
|
||||
"icon": "build/icons",
|
||||
"target": [
|
||||
"deb",
|
||||
"AppImage"
|
||||
]
|
||||
},
|
||||
"deb": {
|
||||
"priority": "optional"
|
||||
}
|
||||
}
|
||||
}
|
||||