Skip to content

Commit 8787b5c

Browse files
committed
Initial commit - app + 4 plugins
0 parents  commit 8787b5c

31 files changed

+7878
-0
lines changed

.editorconfig

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
*.js text eol=lf

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
/dist
3+
/assets/generated

assets/youtube-music.png

48.8 KB
Loading

index.js

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
"use strict";
2+
const path = require("path");
3+
4+
const electron = require("electron");
5+
const isDev = require("electron-is-dev");
6+
7+
const { setApplicationMenu } = require("./menu");
8+
const { getEnabledPlugins, store } = require("./store");
9+
const { fileExists, injectCSS } = require("./plugins/utils");
10+
11+
const app = electron.app;
12+
13+
// Adds debug features like hotkeys for triggering dev tools and reload
14+
require("electron-debug")();
15+
16+
// Prevent window being garbage collected
17+
let mainWindow;
18+
19+
let icon = "assets/youtube-music.png";
20+
if (process.platform == "win32") {
21+
icon = "assets/generated/icon.ico";
22+
} else if (process.platform == "darwin") {
23+
icon = "assets/generated/icon.icns";
24+
}
25+
26+
function onClosed() {
27+
// Dereference the window
28+
// For multiple windows store them in an array
29+
mainWindow = null;
30+
}
31+
32+
function createMainWindow() {
33+
const windowSize = store.get("window-size");
34+
const windowMaximized = store.get("window-maximized");
35+
36+
const win = new electron.BrowserWindow({
37+
icon : icon,
38+
width : windowSize.width,
39+
height : windowSize.height,
40+
backgroundColor: "#000",
41+
show : false,
42+
webPreferences : {
43+
nodeIntegration: false,
44+
preload : path.join(__dirname, "preload.js")
45+
},
46+
frame : false,
47+
titleBarStyle: "hiddenInset"
48+
});
49+
if (windowMaximized) {
50+
win.maximize();
51+
}
52+
53+
win.webContents.loadURL(store.get("url"));
54+
win.on("closed", onClosed);
55+
56+
injectCSS(win.webContents, path.join(__dirname, "youtube-music.css"));
57+
win.webContents.on("did-finish-load", () => {
58+
if (isDev) {
59+
console.log("did finish load");
60+
win.webContents.openDevTools();
61+
}
62+
});
63+
64+
getEnabledPlugins().forEach(plugin => {
65+
console.log("Loaded plugin - " + plugin);
66+
const pluginPath = path.join(__dirname, "plugins", plugin, "back.js");
67+
fileExists(pluginPath, () => {
68+
const handle = require(pluginPath);
69+
handle(win);
70+
});
71+
});
72+
73+
win.webContents.on("did-navigate-in-page", () => {
74+
const url = win.webContents.getURL();
75+
if (url.startsWith("https://music.youtube.com")) {
76+
store.set("url", url);
77+
}
78+
});
79+
80+
win.on("move", () => {
81+
let position = win.getPosition();
82+
store.set("window-position", { x: position[0], y: position[1] });
83+
});
84+
85+
win.on("resize", () => {
86+
const windowSize = win.getSize();
87+
88+
store.set("window-maximized", win.isMaximized());
89+
if (!win.isMaximized()) {
90+
store.set("window-size", { width: windowSize[0], height: windowSize[1] });
91+
}
92+
});
93+
94+
win.once("ready-to-show", () => {
95+
win.show();
96+
});
97+
98+
return win;
99+
}
100+
101+
app.on("window-all-closed", () => {
102+
if (process.platform !== "darwin") {
103+
app.quit();
104+
}
105+
106+
// Unregister all shortcuts.
107+
electron.globalShortcut.unregisterAll();
108+
});
109+
110+
app.on("activate", () => {
111+
// On OS X it's common to re-create a window in the app when the
112+
// dock icon is clicked and there are no other windows open.
113+
if (mainWindow === null) {
114+
mainWindow = createMainWindow();
115+
} else if (!mainWindow.isVisible()) {
116+
mainWindow.show();
117+
}
118+
});
119+
120+
app.on("ready", () => {
121+
setApplicationMenu();
122+
mainWindow = createMainWindow();
123+
124+
// Optimized for Mac OS X
125+
if (process.platform === "darwin") {
126+
var forceQuit = false;
127+
app.on("before-quit", () => {
128+
forceQuit = true;
129+
});
130+
mainWindow.on("close", event => {
131+
if (!forceQuit) {
132+
event.preventDefault();
133+
mainWindow.hide();
134+
}
135+
});
136+
}
137+
});

license

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) th-ch <[email protected]> (https://github.com/th-ch/youtube-music)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

menu.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const { app, Menu } = require("electron");
2+
3+
const { getAllPlugins } = require("./plugins/utils");
4+
const { isPluginEnabled, enablePlugin, disablePlugin } = require("./store");
5+
6+
module.exports.setApplicationMenu = () => {
7+
const menuTemplate = [
8+
{
9+
label : "Plugins",
10+
submenu: getAllPlugins().map(plugin => {
11+
return {
12+
label : plugin,
13+
type : "checkbox",
14+
checked: isPluginEnabled(plugin),
15+
click : item => {
16+
if (item.checked) {
17+
enablePlugin(plugin);
18+
} else {
19+
disablePlugin(plugin);
20+
}
21+
}
22+
};
23+
})
24+
}
25+
];
26+
27+
if (process.platform === "darwin") {
28+
const name = app.getName();
29+
menuTemplate.unshift({
30+
label : name,
31+
submenu: [
32+
{ role: "about" },
33+
{ type: "separator" },
34+
{ role: "hide" },
35+
{ role: "hideothers" },
36+
{ role: "unhide" },
37+
{ type: "separator" },
38+
{
39+
label : "Select All",
40+
accelerator: "CmdOrCtrl+A",
41+
selector : "selectAll:"
42+
},
43+
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
44+
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
45+
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
46+
{ type: "separator" },
47+
{ role: "minimize" },
48+
{ role: "close" },
49+
{ role: "quit" }
50+
]
51+
});
52+
}
53+
54+
const menu = Menu.buildFromTemplate(menuTemplate);
55+
Menu.setApplicationMenu(menu);
56+
};

0 commit comments

Comments
 (0)