Skip to content

Commit d464c17

Browse files
authored
Merge pull request #114 from manojVivek/browser-extension
Browser extension, app support #78
2 parents 1f4a9c2 + d739dd3 commit d464c17

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

desktop-app/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/entitlements.mac.plist

desktop-app/app/main.dev.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import installExtension, {
2323
REDUX_DEVTOOLS,
2424
} from 'electron-devtools-installer';
2525
import devtron from 'devtron';
26+
import fs from 'fs';
2627

2728
const path = require('path');
2829

@@ -41,6 +42,7 @@ export default class AppUpdater {
4142
}
4243

4344
let mainWindow = null;
45+
let urlToOpen = null;
4446

4547
let httpAuthCallbacks = {};
4648

@@ -67,11 +69,44 @@ const installExtensions = async () => {
6769
}
6870
};
6971

72+
const openUrl = url => {
73+
mainWindow.webContents.send(
74+
'address-change',
75+
url.replace('responsively://', '')
76+
);
77+
mainWindow.show();
78+
};
79+
7080
/**
7181
* Add event listeners...
7282
*/
7383

84+
app.on('will-finish-launching', () => {
85+
if (['win32', 'darwin'].includes(process.platform)) {
86+
if (process.argv.length >= 2) {
87+
app.setAsDefaultProtocolClient('responsively', process.execPath, [
88+
path.resolve(process.argv[1]),
89+
]);
90+
} else {
91+
app.setAsDefaultProtocolClient('responsively');
92+
}
93+
}
94+
});
95+
96+
app.on('open-url', async (event, url) => {
97+
log.info('Open-url', url);
98+
if (mainWindow) {
99+
openUrl(url);
100+
} else {
101+
urlToOpen = url;
102+
}
103+
});
104+
74105
app.on('window-all-closed', () => {
106+
if (process.env.NODE_ENV === 'development') {
107+
['win32', 'darwin'].includes(process.platform) &&
108+
app.removeAsDefaultProtocolClient('responsively');
109+
}
75110
// Respect the OSX convention of having the application in memory even
76111
// after all windows have been closed
77112
if (process.platform !== 'darwin') {
@@ -144,6 +179,10 @@ const createWindow = async () => {
144179
});
145180

146181
mainWindow.once('ready-to-show', () => {
182+
if (urlToOpen) {
183+
openUrl(urlToOpen);
184+
urlToOpen = null;
185+
}
147186
mainWindow.show();
148187
});
149188

desktop-app/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@
9797
"category": "public.app-category.developer-tools",
9898
"entitlements": "build/entitlements.mac.plist",
9999
"entitlementsInherit": "build/entitlements.mac.plist",
100+
"extendInfo": {
101+
"CFBundleURLTypes": [
102+
{
103+
"CFBundleURLSchemes": [
104+
"responsively"
105+
],
106+
"CFBundleURLName": "app.responsively"
107+
}
108+
]
109+
},
100110
"icon": "resources/icon.icns",
101111
"target": [
102112
"dmg"

0 commit comments

Comments
 (0)