Skip to content

Commit 288d29a

Browse files
committed
Postgres protocol
1 parent 95e7c7b commit 288d29a

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed

Info.plist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,16 @@
2121
<string>SQLDocument</string>
2222
</dict>
2323
</array>
24+
<key>CFBundleURLTypes</key>
25+
<array>
26+
<dict>
27+
<key>CFBundleURLName</key>
28+
<string>Postgres Database</string>
29+
<key>CFBundleURLSchemes</key>
30+
<array>
31+
<string>postgres</string>
32+
</array>
33+
</dict>
34+
</array>
2435
</dict>
2536
</plist>

mac_build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/bash -e
22
rm -rf .build
33
mkdir .build
44
npm install
@@ -13,6 +13,6 @@ cp -r css .build/
1313
cp -r node_modules .build/
1414

1515
cd .build
16-
electron-packager ./ "SQL Tabs" --platform=darwin --arch=x64 --electron-version=1.4.7 --icon logo.icns --asar --prune --extend-info ../Info.plist --extra-resource ../logo_sql.icns
16+
electron-packager ./ "SQL Tabs" --platform=darwin --arch=x64 --electron-version=1.4.7 --icon logo.icns --asar --prune --extend-info ../Info.plist --extra-resource ../logo_sql.icns --protocol postgres ---procol-name postgres
1717
cd ..
1818

main.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var app = electron.app;
2727
var BrowserWindow = electron.BrowserWindow;
2828

2929
var mainWindow = null;
30+
var urlToOpen = null;
3031
var files2open = [];
3132

3233
var createWindow = function(){
@@ -71,4 +72,31 @@ app.on('ready', function() {
7172
contents.on('did-finish-load', emit_open_file);
7273
}
7374
}
75+
if (urlToOpen) {
76+
mainWindow.webContents.on('did-finish-load', function () {
77+
mainWindow.webContents.send('open-url', urlToOpen);
78+
});
79+
}
80+
81+
if (!app.isDefaultProtocolClient('postgres')) {
82+
electron.dialog.showMessageBox({
83+
type: 'question',
84+
buttons: ['Yes', 'No'],
85+
cancelId: 1,
86+
message: 'Do you want to set SQL Tabs as the default postgres client?'
87+
}, function (button) {
88+
if (button === 0 ) {
89+
app.setAsDefaultProtocolClient('postgres');
90+
}
91+
})
92+
}
93+
});
94+
95+
app.on('open-url', function (ev, url) {
96+
ev.preventDefault();
97+
if (app.isReady()) {
98+
mainWindow.webContents.send('open-url', url);
99+
} else {
100+
urlToOpen = url;
101+
}
74102
});

src/Actions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ var Actions = {
8282
});
8383
},
8484

85-
newTab: function(script, filename){
85+
newTab: function(script, filename, connstr){
8686
AppDispatcher.dispatch({
8787
eventName: 'select-tab',
8888
key: 0,
8989
script: script,
90+
connstr: connstr,
9091
filename: filename,
9192
});
9293
},

src/App.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ require('electron').ipcRenderer.on('open-file', function(event, path) {
3636
}
3737
})
3838

39+
require('electron').ipcRenderer.on('open-url', function(event, url) {
40+
Actions.newTab(null, null, url);
41+
})
42+
3943
require('./Menu');
4044

4145
var mountNode = document.body;

src/Dispatcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ AppDispatcher.register( function(payload) {
6969
switch( payload.eventName ) {
7070
case 'select-tab':
7171
if (payload.key == 0) { // select tab 0 (+) means create a new tab
72-
var tabid = TabsStore.newTab();
72+
var tabid = TabsStore.newTab(payload.connstr);
7373
TabsStore.tmpScript = payload.script;
7474
TabsStore.trigger('change');
7575
if (payload.filename){

0 commit comments

Comments
 (0)