-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.js
84 lines (73 loc) · 2.62 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
var electron = require('electron');
var dbus = require('dbus-native');
var sessionBus = dbus.sessionBus();
var app = electron.app; // Module to control application life.
var BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
var globalShortcut = electron.globalShortcut;
const flashLoader = require('flash-player-loader');
for(const path of require('./pepper-paths.json')) {
flashLoader.addSource(path);
}
flashLoader.load();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
// don't quit until user explicitly asks for it
app.quit();
});
if(!app.requestSingleInstanceLock()) {
// We failed to get the single instance lock, so another instance is running
console.log("TIDAL is already running, focusing it");
app.quit();
}
app.on('second-instance', (commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window
if (mainWindow) {
if (mainWindow.isMinimized()) { mainWindow.restore(); }
mainWindow.focus();
}
return true;
});
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
frame: true,
icon: __dirname + "/icon.png",
autoHideMenuBar: true,
darkTheme: true,
plugin:true,
webPreferences: {
plugins: true
}
});
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/index.html', {userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"});
// Emitted when the window is closed.
mainWindow.on('closed', function() {
mainWindow = null;
});
console.log("APP READY")
// update window title from webview
electron.ipcMain.on("title", function(e, arg) {
mainWindow.setTitle(arg);
})
try{
// handle media keys (only works on GNOME, where it didn't before)
sessionBus.getService("org.gnome.SettingsDaemon").getInterface("/org/gnome/SettingsDaemon/MediaKeys", "org.gnome.SettingsDaemon.MediaKeys", function(err, interface) {
if(!err) {
interface.on("MediaPlayerKeyPressed", (n, keyName) => {
mainWindow.webContents.send('playback-control', keyName);
});
interface.GrabMediaPlayerKeys("tidal-music-player", 0);
} else {
console.log("Couldn't grab media keys, this system may be not running GNOME");
}
});
}catch(exception){
// ignore exception
}
});