This repository has been archived by the owner on May 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
76 lines (63 loc) · 1.81 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
const electron = require('electron');
const config = require('./config');
const analytics = require('./app/main/analytics');
const auth = require('./app/main/auth');
global.servizi = {
handleOpenUrl: function handleOpenUrl(ev, url) {
const code = url.split('code=')[1];
// let token;
const tokenConfig = {
code,
redirect_uri: 'servizi://oauth/callback',
};
// Callbacks
// Save the access token
auth.oauthClient.authorizationCode.getToken(tokenConfig, (error, token) => {
// let message;
if (error) {
// message = error.message;
} else {
// message = auth.oauthClient.accessToken.create(token);
global.servizi.mainWindow.webContents.send('didAddAccount', {
redirect_uri: tokenConfig.redirect_uri,
token,
});
global.servizi.mainWindow.focus();
analytics.recordEvent(config.aws.eventNames.addAccount);
}
});
},
};
const shouldQuit = electron.app.makeSingleInstance((argv) => {
// Someone tried to run a second instance, we should focus our window.
if (global.servizi.mainWindow) {
if (global.servizi.mainWindow.isMinimized()) {
global.servizi.mainWindow.restore();
}
global.servizi.mainWindow.focus();
global.servizi.handleOpenUrl(null, argv[1]);
}
});
if (shouldQuit) {
electron.app.quit();
}
//
// imports
//
const appEvents = require('./app/main/app-events');
const ipcEvents = require('./app/main/ipc-events');
const settings = require('./app/main/settings');
require('./app/main/redux-store');
//
// vars
//
const app = electron.app;
global.servizi.database = require('./app/main/database');
//
// event listeners
//
ipcEvents.setupListeners();
appEvents.setupListeners();
if (!settings.getStoredSettings().fullPlayerUI && app.dock !== undefined) {
app.dock.hide();
}