From d739dd3c998144ce8198bf94b78e3a714af6656e Mon Sep 17 00:00:00 2001
From: Manoj Vivek
Date: Mon, 25 May 2020 19:37:11 +0530
Subject: [PATCH] Browser extension, app support #78
---
desktop-app/.prettierignore | 1 +
desktop-app/app/main.dev.js | 39 +++++++++++++++++++++++++++++++++++++
desktop-app/package.json | 10 ++++++++++
3 files changed, 50 insertions(+)
create mode 100644 desktop-app/.prettierignore
diff --git a/desktop-app/.prettierignore b/desktop-app/.prettierignore
new file mode 100644
index 000000000..644f1a15a
--- /dev/null
+++ b/desktop-app/.prettierignore
@@ -0,0 +1 @@
+build/entitlements.mac.plist
diff --git a/desktop-app/app/main.dev.js b/desktop-app/app/main.dev.js
index ebb96c723..c1ba09c76 100644
--- a/desktop-app/app/main.dev.js
+++ b/desktop-app/app/main.dev.js
@@ -23,6 +23,7 @@ import installExtension, {
REDUX_DEVTOOLS,
} from 'electron-devtools-installer';
import devtron from 'devtron';
+import fs from 'fs';
const path = require('path');
@@ -41,6 +42,7 @@ export default class AppUpdater {
}
let mainWindow = null;
+let urlToOpen = null;
let httpAuthCallbacks = {};
@@ -67,11 +69,44 @@ const installExtensions = async () => {
}
};
+const openUrl = url => {
+ mainWindow.webContents.send(
+ 'address-change',
+ url.replace('responsively://', '')
+ );
+ mainWindow.show();
+};
+
/**
* Add event listeners...
*/
+app.on('will-finish-launching', () => {
+ if (['win32', 'darwin'].includes(process.platform)) {
+ if (process.argv.length >= 2) {
+ app.setAsDefaultProtocolClient('responsively', process.execPath, [
+ path.resolve(process.argv[1]),
+ ]);
+ } else {
+ app.setAsDefaultProtocolClient('responsively');
+ }
+ }
+});
+
+app.on('open-url', async (event, url) => {
+ log.info('Open-url', url);
+ if (mainWindow) {
+ openUrl(url);
+ } else {
+ urlToOpen = url;
+ }
+});
+
app.on('window-all-closed', () => {
+ if (process.env.NODE_ENV === 'development') {
+ ['win32', 'darwin'].includes(process.platform) &&
+ app.removeAsDefaultProtocolClient('responsively');
+ }
// Respect the OSX convention of having the application in memory even
// after all windows have been closed
if (process.platform !== 'darwin') {
@@ -144,6 +179,10 @@ const createWindow = async () => {
});
mainWindow.once('ready-to-show', () => {
+ if (urlToOpen) {
+ openUrl(urlToOpen);
+ urlToOpen = null;
+ }
mainWindow.show();
});
diff --git a/desktop-app/package.json b/desktop-app/package.json
index 33659dda0..1c75b7d90 100644
--- a/desktop-app/package.json
+++ b/desktop-app/package.json
@@ -97,6 +97,16 @@
"category": "public.app-category.developer-tools",
"entitlements": "build/entitlements.mac.plist",
"entitlementsInherit": "build/entitlements.mac.plist",
+ "extendInfo": {
+ "CFBundleURLTypes": [
+ {
+ "CFBundleURLSchemes": [
+ "responsively"
+ ],
+ "CFBundleURLName": "app.responsively"
+ }
+ ]
+ },
"icon": "resources/icon.icns",
"target": [
"dmg"