-
Notifications
You must be signed in to change notification settings - Fork 125
/
index.js
185 lines (153 loc) · 4.95 KB
/
index.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
global.errorReporter = require('./lib/error_reporter');
require('./lib/object_extras');
require('./lib/dominate');
require('./lib/alertify');
require('./lib/node_lib');
require('./lib/sidebar_resize');
require('./lib/query_tab_resizer');
require('./lib/widgets/generic_table');
require('./lib/psql_runner');
require('./lib/sql_importer');
require('./lib/pg_dump_runner');
require('./lib/sql_exporter');
require('./lib/pg_type_names');
require('./lib/sql_snippets');
require('./lib/resizable_columns');
require('./app');
global.Pane = require('./app/views/panes/all');
require('./app/connection');
require('./app/view_helpers');
require('./app/db_screen');
require('./app/login_components/heroku_client');
require('./app/login_components/login_postgres_url_form');
require('./app/login_components/login_standard_form');
require('./app/login_screen');
require('./app/help_screen');
require('./app/views/db_screen_view');
require('./app/views/snippets');
global.Dialog = require('./app/views/dialogs/all');
global.Model = require('./app/models/all');
require('./app/controllers/import_controller');
require('./app/controllers/export_controller');
require('./app/controllers/updates_controller');
require('./app/controllers/server_controller');
require('./app/views/history_window');
var CliUtil = require('./lib/cli_util');
var electronRemote = require('@electron/remote');
global.$u = window.$u = window.jQuery;
/*
global.$ = function (selector) {
return document.querySelector(selector);
};
*/
global.$dom = function(tags) { return global.DOMinate(tags)[0]; };
require('./app/utils');
// eslint-disable-next-line
function reloadCss() {
var queryString = '?reload=' + new Date().getTime();
global.$u('link[rel="stylesheet"]').each(function () {
this.href = this.href.replace(/\?.*|$/, queryString);
});
}
//var gui = require('nw.gui');
//global.gui = gui;
global.electron = require('electron');
electron.ipcRenderer.on('open-file', function(event, message) {
console.log('open-file', event, message);
});
electron.ipcRenderer.on('open-url', function(event, url) {
CliUtil.resolveArg(url, (resultUrl) => {
console.log('CliUtil.resolveArg', resultUrl);
App.openConnection(resultUrl);
});
});
$(window).on('window-ready', () => {
electron.ipcRenderer.send('main-window-ready', {});
});
require('./app/top_menu');
var cliArgs = electronRemote.process.argv;
if (cliArgs.length > 2) {
var connectionStr = cliArgs[2];
if (connectionStr.startsWith("postgres://") || connectionStr.startsWith("postgresql://")) {
App.cliConnectString = connectionStr;
} else {
$u.alertError(`Can't recognize argument ${cliArgs[2]}`, {
detail: `Expected:\n postgres://user@server/dbname \n postgresql://user@server/dbname`
});
}
}
$(document).ready(function() {
global.App.init();
//renderHome();
$(window).bind('resize', function () {
global.App.setSizes();
});
$u.makeDroppable(document.body, function (path) {
var importer = new ImportController();
importer.filename = path;
importer.showImportDialog();
});
window.Mousetrap.bind("down", function () {
GenericTable.keyPressed('down');
return false;
});
window.Mousetrap.bind("up", function () {
GenericTable.keyPressed('up');
return false;
});
window.Mousetrap.bind(["backspace", "del"], function () {
GenericTable.keyPressed('backspace');
});
electron.ipcRenderer.on('Snippet.insert', function(event, message) {
console.log('Snippet.insert', event, message);
Pane.Content.insertSnippet(message);
});
setTimeout(function () {
console.log("Checking updates info");
(new UpdatesController).checkUpdates();
}, 10000);
/*
var win = gui.Window.get();
win.focus();
win.on('closed', function() {
if (global.App.snippersWin) {
global.App.snippersWin.close();
}
if (global.App.historyWin) {
global.App.historyWin.close();
}
});
*/
var windowEvents = {
focus: () => {
document.body.classList.remove('unfocused');
App.isFocused = true;
},
blur: () => {
document.body.classList.add('unfocused');
App.isFocused = false;
}
};
var mainWindow = electronRemote.app.mainWindow;
mainWindow.on('focus', windowEvents.focus);
mainWindow.on('blur', windowEvents.blur);
// used when we reload app, usually for development
window.addEventListener('beforeunload', () => {
mainWindow.removeListener('focus', windowEvents.focus);
mainWindow.removeListener('blur', windowEvents.blur);
});
if (mainWindow.isFocused()) {
windowEvents.focus();
} else {
windowEvents.blur();
}
if (electronRemote.systemPreferences && electronRemote.systemPreferences.subscribeNotification) {
electronRemote.systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => {
if (electronRemote.systemPreferences.isDarkMode()) {
document.body.classList.add('dark-mode');
} else {
document.body.classList.remove('dark-mode');
}
});
}
});