Skip to content

Commit

Permalink
Fixed Desktop Integration for AppImage
Browse files Browse the repository at this point in the history
  • Loading branch information
cstayyab committed Mar 21, 2020
1 parent 65f0723 commit 0a58fd6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
- Added initial support to for Bot (Not yet functional)
- Updated All Dependencies
- Removed System Integration support for AppImage because the option has been depcecated
- Added Snap Support
- Added Snap Support
0.1.6
- Fixed Desktop Integration for AppImages with custom approach
64 changes: 61 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const dns = require("dns");
const Store = require('electron-store')
const fs = require('fs')
const getPortSync = require('get-port-sync');
const createDesktopShortcut = require('create-desktop-shortcuts');
const homedir = require('os').homedir();


var trayIcon;
Expand All @@ -23,7 +25,6 @@ let customeTitle = "WALC"

let preventTitleChange = true


// set user agent manually
const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36'
// Keep a global reference of the window object, if you don't, the window will
Expand All @@ -39,7 +40,44 @@ try {
}
catch (e) { console.log(e) }


const shortcutDir = path.join(homedir, ".local/share/applications")
//Create Desktop Shortcut for AppImage
function integrateToDesktop(win) {
const iconDir = path.join(homedir, ".local/share/WALC")
const iconPath = path.join(iconDir, "logo256x56.png")
fs.mkdirSync(shortcutDir, { recursive: true });
fs.mkdirSync(iconDir, { recursive: true });
fs.copyFileSync(path.join(__dirname, "icons/logo256x256.png"), iconPath)
const shortcutCreated = createDesktopShortcut({
onlyCurrentOS: true,
customLogger: (msg, error) => {
dialog.showMessageBoxSync(win, {
type: 'error',
buttons: ['OK'],
title: 'Desktop Integration',
message: msg
})
},
"linux": {
filePath: process.env.APPIMAGE,
outputPath: shortcutDir,
name: 'WALC',
description: 'WALC - unofficial WhatsApp Linux Client',
icon: iconPath,
type: 'Application',
terminal: false,
chmod: true
}
})
if(shortcutCreated) {
dialog.showMessageBoxSync(win, {
type: 'info',
buttons: ['OK'],
title: 'Desktop Integration',
message: "WALC has successfully been integrated to your Applications."
})
}
}


//Default Settings
Expand Down Expand Up @@ -81,6 +119,14 @@ const settingsMenu = [{
settings.set('multiInstance.value', menuItem.checked)
preventExit = true;
},
},
{
label: "Update Desktop Integration",
type: 'normal',
checked: settings.get('multiInstance.value'),
click: (menuItem, window, e) => {
integrateToDesktop(window)
},
}
]
const windowMenu = [{
Expand Down Expand Up @@ -288,7 +334,6 @@ function createWindow() {
trayIcon.setContextMenu(Menu.buildFromTemplate(hideMenu))



win.on('close', e => {
e.preventDefault();
if (settings.get('askOnExit.value') && preventExit) {
Expand Down Expand Up @@ -321,6 +366,19 @@ function createWindow() {
require('electron').shell.openExternal(url);
})

if (process.env.APPIMAGE !== undefined && !fs.existsSync(path.join(shortcutDir, "WALC.desktop"))) {
//Desktop Integration of AppImage
integrate = dialog.showMessageBoxSync(win, {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Desktop Integration',
message: "Do you want to integrate WALC to your Applications?"
})

if (integrate == 0) {
integrateToDesktop(win)
}
}

}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "walc",
"version": "0.1.5",
"version": "0.1.6",
"description": "A WhatsApp Desktop client for linux systems. This is an unofficial client. Use https://web.whatsapp.com for official web client as official desktop client for linux does not exist.",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -53,6 +53,7 @@
"homepage": "https://github.com/cstayyab/WALC#readme",
"dependencies": {
"@pedroslopez/moduleraid": "^4.1.0",
"create-desktop-shortcuts": "^1.0.2",
"electron-store": "^5.1.1",
"electron-updater": "^4.2.5",
"get-port-sync": "^1.0.0",
Expand Down

0 comments on commit 0a58fd6

Please sign in to comment.