Skip to content

Commit

Permalink
Initial commit - app + 4 plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
th-ch committed Apr 19, 2019
0 parents commit 8787b5c
Show file tree
Hide file tree
Showing 31 changed files with 7,878 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
*.js text eol=lf
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
/dist
/assets/generated
Binary file added assets/youtube-music.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 137 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
"use strict";
const path = require("path");

const electron = require("electron");
const isDev = require("electron-is-dev");

const { setApplicationMenu } = require("./menu");
const { getEnabledPlugins, store } = require("./store");
const { fileExists, injectCSS } = require("./plugins/utils");

const app = electron.app;

// Adds debug features like hotkeys for triggering dev tools and reload
require("electron-debug")();

// Prevent window being garbage collected
let mainWindow;

let icon = "assets/youtube-music.png";
if (process.platform == "win32") {
icon = "assets/generated/icon.ico";
} else if (process.platform == "darwin") {
icon = "assets/generated/icon.icns";
}

function onClosed() {
// Dereference the window
// For multiple windows store them in an array
mainWindow = null;
}

function createMainWindow() {
const windowSize = store.get("window-size");
const windowMaximized = store.get("window-maximized");

const win = new electron.BrowserWindow({
icon : icon,
width : windowSize.width,
height : windowSize.height,
backgroundColor: "#000",
show : false,
webPreferences : {
nodeIntegration: false,
preload : path.join(__dirname, "preload.js")
},
frame : false,
titleBarStyle: "hiddenInset"
});
if (windowMaximized) {
win.maximize();
}

win.webContents.loadURL(store.get("url"));
win.on("closed", onClosed);

injectCSS(win.webContents, path.join(__dirname, "youtube-music.css"));
win.webContents.on("did-finish-load", () => {
if (isDev) {
console.log("did finish load");
win.webContents.openDevTools();
}
});

getEnabledPlugins().forEach(plugin => {
console.log("Loaded plugin - " + plugin);
const pluginPath = path.join(__dirname, "plugins", plugin, "back.js");
fileExists(pluginPath, () => {
const handle = require(pluginPath);
handle(win);
});
});

win.webContents.on("did-navigate-in-page", () => {
const url = win.webContents.getURL();
if (url.startsWith("https://music.youtube.com")) {
store.set("url", url);
}
});

win.on("move", () => {
let position = win.getPosition();
store.set("window-position", { x: position[0], y: position[1] });
});

win.on("resize", () => {
const windowSize = win.getSize();

store.set("window-maximized", win.isMaximized());
if (!win.isMaximized()) {
store.set("window-size", { width: windowSize[0], height: windowSize[1] });
}
});

win.once("ready-to-show", () => {
win.show();
});

return win;
}

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}

// Unregister all shortcuts.
electron.globalShortcut.unregisterAll();
});

app.on("activate", () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
mainWindow = createMainWindow();
} else if (!mainWindow.isVisible()) {
mainWindow.show();
}
});

app.on("ready", () => {
setApplicationMenu();
mainWindow = createMainWindow();

// Optimized for Mac OS X
if (process.platform === "darwin") {
var forceQuit = false;
app.on("before-quit", () => {
forceQuit = true;
});
mainWindow.on("close", event => {
if (!forceQuit) {
event.preventDefault();
mainWindow.hide();
}
});
}
});
21 changes: 21 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) th-ch <[email protected]> (https://github.com/th-ch/youtube-music)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
56 changes: 56 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const { app, Menu } = require("electron");

const { getAllPlugins } = require("./plugins/utils");
const { isPluginEnabled, enablePlugin, disablePlugin } = require("./store");

module.exports.setApplicationMenu = () => {
const menuTemplate = [
{
label : "Plugins",
submenu: getAllPlugins().map(plugin => {
return {
label : plugin,
type : "checkbox",
checked: isPluginEnabled(plugin),
click : item => {
if (item.checked) {
enablePlugin(plugin);
} else {
disablePlugin(plugin);
}
}
};
})
}
];

if (process.platform === "darwin") {
const name = app.getName();
menuTemplate.unshift({
label : name,
submenu: [
{ role: "about" },
{ type: "separator" },
{ role: "hide" },
{ role: "hideothers" },
{ role: "unhide" },
{ type: "separator" },
{
label : "Select All",
accelerator: "CmdOrCtrl+A",
selector : "selectAll:"
},
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ type: "separator" },
{ role: "minimize" },
{ role: "close" },
{ role: "quit" }
]
});
}

const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
};
Loading

0 comments on commit 8787b5c

Please sign in to comment.