-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathmain.js
127 lines (111 loc) · 3.51 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
function isDev() {
return process.argv[2] == '--dev';
}
//if (process.platform == 'linux'){
// var mkdirp = require('mkdirp');
// mkdirp(process.env.HOME+'/.local/share/icons', function(err){console.log(err)});
// mkdirp(process.env.HOME+'/.local/share/applications');
// var fs = require('fs');
// fs.open(process.env.HOME+"/.local/share/applications/sqltabs.desktop", "wx", function(err){
// if (err){
// return;
// }
// fs.writeFile(process.env.HOME+"/.local/share/applications/sqltabs.desktop", "Icon=sqltabs", function(err) {
// if(err) {
// return console.log(err);
// }
// });
// });
// fs.open(process.env.HOME+"/.local/share/icons/sqltabs.png", "wx", function(err){
// if(err){
// return;
// }
// fs.createReadStream('logo.png').pipe(fs.createWriteStream(process.env.HOME+'/.local/share/icons/sqltabs.png'));
// });
//}
var electron = require('electron');
if (isDev()){
require('electron-reload')(__dirname);
}
var app = electron.app;
var BrowserWindow = electron.BrowserWindow;
var mainWindow = null;
var urlToOpen = null;
var files2open = [];
var createWindow = function(){
mainWindow = new BrowserWindow({
width: 800,
height: 600,
title: 'SQL Tabs',
webPreferences: {
nodeIntegration: true,
},
});
mainWindow.maximize();
if (isDev()){
mainWindow.toggleDevTools();
}
mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.on('closed', function() {
mainWindow = null;
});
}
app.on('window-all-closed', function() {
app.quit();
});
app.on('open-file', function(event, path){
event.preventDefault();
if (mainWindow != null){
var contents = mainWindow.webContents;
contents.send('open-file', path);
} else {
files2open.push(path);
}
});
app.on('ready', function() {
if (!isDev()){
const { autoUpdater } = require("electron-updater");
autoUpdater.checkForUpdatesAndNotify();
}
createWindow();
if (files2open.length != 0){
var contents = mainWindow.webContents;
for (var i in files2open){
var path = files2open[i];
var getEmitter = function(contents, path){
return function(){
contents.send('open-file', path);
}
}
var emit_open_file = getEmitter(contents, path);
contents.on('did-finish-load', emit_open_file);
}
}
if (urlToOpen) {
mainWindow.webContents.on('did-finish-load', function () {
mainWindow.webContents.send('open-url', urlToOpen);
});
}
//if (!app.isDefaultProtocolClient('postgres') && !config.getNoProtocolDialog()) {
// electron.dialog.showMessageBox({
// type: 'question',
// buttons: ['Yes', 'No'],
// cancelId: 1,
// message: 'Do you want to set SQL Tabs as the default postgres client?'
// }, function (button) {
// config.saveNoProtocolDialog(true); // prevent protocol dialog on next start even if No has bee chosen
// if (button === 0 ) {
// app.setAsDefaultProtocolClient('postgres');
// }
// })
//}
});
app.on('open-url', function (ev, url) {
ev.preventDefault();
if (app.isReady()) {
mainWindow.webContents.send('open-url', url);
} else {
urlToOpen = url;
}
});
console.log('init done');