diff --git a/plugins/navigation/back.js b/plugins/navigation/back.js index 6d0d0a2a..4c3e00dc 100644 --- a/plugins/navigation/back.js +++ b/plugins/navigation/back.js @@ -4,7 +4,10 @@ const { injectCSS, listenAction } = require("../utils"); const { ACTIONS, CHANNEL } = require("./actions.js"); function handle(win) { - injectCSS(win.webContents, path.join(__dirname, "style.css")); + injectCSS(win.webContents, path.join(__dirname, "style.css"), () => { + win.webContents.send("navigation-css-ready"); + }); + listenAction(CHANNEL, (event, action) => { switch (action) { case ACTIONS.NEXT: diff --git a/plugins/navigation/front.js b/plugins/navigation/front.js index 92bc1325..d89c9891 100644 --- a/plugins/navigation/front.js +++ b/plugins/navigation/front.js @@ -1,15 +1,19 @@ +const { ipcRenderer } = require("electron"); + const { ElementFromFile, templatePath } = require("../utils"); function run() { - const forwardButton = ElementFromFile( - templatePath(__dirname, "forward.html") - ); - const backButton = ElementFromFile(templatePath(__dirname, "back.html")); - const menu = document.querySelector("ytmusic-pivot-bar-renderer"); + ipcRenderer.on("navigation-css-ready", () => { + const forwardButton = ElementFromFile( + templatePath(__dirname, "forward.html") + ); + const backButton = ElementFromFile(templatePath(__dirname, "back.html")); + const menu = document.querySelector("ytmusic-pivot-bar-renderer"); - if (menu) { - menu.prepend(backButton, forwardButton); - } + if (menu) { + menu.prepend(backButton, forwardButton); + } + }); } module.exports = run; diff --git a/plugins/navigation/templates/back.html b/plugins/navigation/templates/back.html index 2a675163..b872ada5 100644 --- a/plugins/navigation/templates/back.html +++ b/plugins/navigation/templates/back.html @@ -20,7 +20,7 @@ preserveAspectRatio="xMidYMid meet" focusable="false" class="style-scope iron-icon" - style="pointer-events: none; display: block; width: 100%; height: 100%;" + style="pointer-events: none; display: block; width: 100%; height: 100%" > { }); }; -module.exports.injectCSS = (webContents, filepath) => { - webContents.on("did-finish-load", () => { - webContents.insertCSS(fs.readFileSync(filepath, "utf8")); +module.exports.injectCSS = (webContents, filepath, cb = undefined) => { + webContents.on("did-finish-load", async () => { + await webContents.insertCSS(fs.readFileSync(filepath, "utf8")); + if (cb) { + cb(); + } }); };