diff --git a/package.json b/package.json index c76c25e2..2119ecb5 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "prune": "ts-prune", "mmjstool": "mmjstool", "i18n-extract": "npm run mmjstool -- i18n extract-desktop", - "postinstall": "node scripts/patch_macos_notification_state.js && electron-builder install-app-deps" + "postinstall": "node scripts/postinstall.js && electron-builder install-app-deps" }, "jest": { "clearMocks": true, diff --git a/scripts/patch_macos_notification_state.js b/scripts/patch_macos_notification_state.js deleted file mode 100644 index 799f1e61..00000000 --- a/scripts/patch_macos_notification_state.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -const fs = require('fs'); - -const jq = require('node-jq'); - -jq.run( - '.scripts.install = "node-gyp rebuild"', - './node_modules/macos-notification-state/package.json', -).then((result) => { - fs.writeFileSync( - './node_modules/macos-notification-state/package.json', - result, - ); -}); diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 00000000..b0e73d9d --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,52 @@ +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +const fs = require('fs'); +const jq = require('node-jq'); +const path = require('path'); + +// Patch the macos-notification-state library so we can build correctly +jq.run( + '.scripts.install = "node-gyp rebuild"', + './node_modules/macos-notification-state/package.json', +).then((result) => { + fs.writeFileSync( + './node_modules/macos-notification-state/package.json', + result, + ); +}); + +// For linux dev, drop a desktop shortcut so deep linking works correctly +if (process.platform === 'linux') { + const xdgDir = path.resolve(process.env.HOME, '.local/share/applications'); + if (fs.existsSync(xdgDir) && !fs.existsSync(path.resolve(xdgDir, 'mattermost-desktop-dev.desktop'))) { + fs.writeFileSync( + path.resolve(xdgDir, 'mattermost-desktop-dev.desktop'), +`[Desktop Entry] +Name=Mattermost.Dev +Exec=${path.resolve(process.cwd(), 'node_modules/electron/dist/electron')} ${path.resolve(process.cwd(), 'dist')} %U +Terminal=false +Type=Application +Icon=mattermost-desktop +StartupWMClass=Mattermost +Comment=Mattermost +MimeType=x-scheme-handler/mattermost-dev; +Categories=contrib/net; +` + ); + + const defaultsListPath = path.resolve(xdgDir, 'defaults.list'); + if (!fs.existsSync(defaultsListPath)) { + fs.writeFileSync(defaultsListPath, '[Default Applications]\n'); + } + fs.appendFileSync(defaultsListPath, 'x-scheme-handler/mattermost-dev=mattermost-desktop-dev.desktop\n'); + + const mimeCachePath = path.resolve(xdgDir, 'mimeinfo.cache'); + if (!fs.existsSync(mimeCachePath)) { + fs.writeFileSync(mimeCachePath, '[MIME Cache]\n'); + } + fs.appendFileSync(mimeCachePath, 'x-scheme-handler/mattermost-dev=mattermost-desktop-dev.desktop\n'); + + console.log('NOTE: You may need to log in and out of your session to ensure that deep linking works correctly.'); + } +} diff --git a/src/main/app/initialize.ts b/src/main/app/initialize.ts index a6c364c4..201e633a 100644 --- a/src/main/app/initialize.ts +++ b/src/main/app/initialize.ts @@ -236,7 +236,7 @@ function initializeBeforeAppReady() { AllowProtocolDialog.init(); if (isDev && process.env.NODE_ENV !== 'test') { - app.setAsDefaultProtocolClient('mattermost-dev'); + app.setAsDefaultProtocolClient('mattermost-dev', process.execPath, [path.resolve(process.cwd(), 'dist/')]); } else if (mainProtocol) { app.setAsDefaultProtocolClient(mainProtocol); }