-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8787b5c
Showing
31 changed files
with
7,878 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* text=auto | ||
*.js text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
/dist | ||
/assets/generated |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
Oops, something went wrong.