-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
156 lines (136 loc) · 4.2 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
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
"use strict";
/* eslint no-undef:0 */
const { app, BrowserWindow, nativeImage, ipcMain } = require("electron");
const path = require("path");
const url = require("url");
const fs = require("fs");
const setupEvents = require("./installer/setup-events");
if (setupEvents.handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
return;
}
// Setup file handlers
let osxFile;
app.on("open-file", (event, filePath) => {
if (win && win.webContents && !win.webContents.isLoading()) {
win.webContents.send("file-found", filePath);
} else {
osxFile = filePath;
}
});
let win;
let image = createNativeImage("./img/icon.png");
if (app.dock) {
app.dock.setIcon(image);
}
function createNativeImage(relativePath) {
return nativeImage.createFromPath(path.join(__dirname, relativePath));
}
function setThumbarState(state) {
if (!win) {
return;
}
if (state == "ended") {
win.setThumbarButtons([]);
return;
}
let buttons = [];
buttons.push({
tooltip: "Chanson précédente",
icon: path.join(__dirname, "img", "electron", "previous-song.png"),
click() {
win.webContents.send("request-video-action", "previous-song");
},
});
if (state == "play") {
buttons.push({
tooltip: "Pause",
icon: path.join(__dirname, "img", "electron", "pause.png"),
click() {
win.webContents.send("request-video-action", "pause");
}
});
} else {
buttons.push({
tooltip: "Jouer",
icon: path.join(__dirname, "img", "electron", "play.png"),
click() {
win.webContents.send("request-video-action", "play");
},
});
}
buttons.push({
tooltip: "Prochaine chanson",
icon: path.join(__dirname, "img", "electron", "next-song.png"),
click() {
win.webContents.send("request-video-action", "next-song");
},
});
win.setThumbarButtons(buttons);
}
function onMediaStateChange(event, state) {
if (app.dock) {
let badge;
switch (state) {
case "pause":
badge = "⏸";
break;
case "play":
badge = "▶";
break;
case "ended":
badge = "";
break;
}
app.dock.setBadge(badge);
}
if (win.setThumbarButtons) {
setThumbarState(state);
}
}
function createWindow() {
win = new BrowserWindow({
width: 800,
height: 600,
minWidth: 290,
minHeight: 290,
icon: __dirname + "/img/icon.png",
title: "Zikalizer",
hasShadow: true,
frame: false,
center: true,
titleBarStyle: "hidden-inset"
});
win.setMenu(null);
// win.toggleDevTools();
win.loadURL(url.format({
pathname: path.join(__dirname, "./index.html"),
protocol: "file:",
slashes: true,
}));
win.webContents.once("did-stop-loading", () => {
if (process.platform == "win32") {
let fileDesc = fs.lstatSync(process.argv[process.argv.length - 1]);
if (fileDesc.isFile()) {
var openedFilePath = process.argv[process.argv.length - 1];
win.webContents.send("file-found", openedFilePath);
}
} else if (osxFile) {
win.webContents.send("file-found", osxFile);
}
ipcMain.on("add-recent-file", (_, mediaPath) => app.addRecentDocument(mediaPath));
ipcMain.on("media-state-change", onMediaStateChange);
});
// Close handler
win.on("closed", () => {
win = null;
ipcMain.removeAllListeners("add-recent-file");
ipcMain.removeAllListeners("media-state-change");
if (app.dock) {
app.dock.setBadge("");
}
});
}
app.on("ready", createWindow);
app.on("window-all-closed", () => app.quit());
app.on("activate", () => (win === null) ? createWindow() : 0);