From bd0e0b3473adde50855ff631d40085b31b15a60a Mon Sep 17 00:00:00 2001 From: Joery Date: Fri, 29 Jul 2022 02:17:58 +0200 Subject: [PATCH] dark mode --- index.js | 68 +++++++++++++++++----------- package.json | 7 +-- src/index.html | 4 +- src/mdc.scss | 6 --- src/script.ts | 35 ++++++++------- src/stylesheet.scss | 105 ++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 169 insertions(+), 56 deletions(-) diff --git a/index.js b/index.js index 7ebd19b..a483ab7 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ if (require('electron-squirrel-startup')) return app.quit(); -const { app, BrowserWindow, dialog, ipcMain, shell } = require('electron'); +const { app, BrowserWindow, dialog, ipcMain, shell, nativeTheme, webFrameMain } = require('electron'); const fs = require('fs'); const path = require('path'); const ytdl = require('ytdl-core'); @@ -10,7 +10,7 @@ const cp = require('child_process'); const ffmpegPath = require("ffmpeg-static-electron").path; -require("./updater") +require("./updater"); function createWindow () { @@ -26,7 +26,8 @@ function createWindow () icon: process.platform == "darwin" ? "./icon.icns" : "./icon.ico", title: "YouTube Downloader", maxHeight: 820, - autoHideMenuBar: true + autoHideMenuBar: true, + transparent: true }); win.loadFile('./app/index.html').then(() => @@ -51,6 +52,8 @@ function createWindow () { win.webContents.send("winFocus"); }); + + nativeTheme.themeSource = "system"; } app.whenReady().then(() => @@ -121,7 +124,7 @@ ipcMain.on("download", async (ev, url, type) => return; } lastPercent = curPercent; - ev.sender.send("percent", curPercent); + sendPercent(curPercent); }); @@ -152,7 +155,12 @@ ipcMain.on("download", async (ev, url, type) => { fs.rmSync(stream.path); - win.webContents.send("doneDownload", true); + if (!win.isFocused()) + { + win.flashFrame(true); + } + + doneDownload(true); ipcMain.once("doneDialogRes", (ev, res) => { @@ -165,35 +173,25 @@ ipcMain.on("download", async (ev, url, type) => }) .on("progress", (progress) => { - ev.sender.send("percent", Math.round(progress.percent)); + sendPercent(Math.round(progress.percent)); }) .save(fileName); - var test = cp.spawn(ffmpeg, [], { - windowsHide: true, - stdio: [ - /* Standard: stdin, stdout, stderr */ - 'inherit', 'inherit', 'inherit', - /* Custom: pipe:3, pipe:4, pipe:5 */ - 'pipe', 'pipe', 'pipe', - ], - }); return; } - win.webContents.send("doneDownload", true); + doneDownload(true); ipcMain.once("doneDialogRes", (ev, res) => { if (res) { - var fileLoc = path.parse(fileName).dir; - shell.openPath(fileLoc); + shell.showItemInFolder(fileName); } }); }); } else { - win.webContents.send("doneDownload"); + doneDownload(); } }); @@ -218,7 +216,7 @@ async function downloadVideoAndAudioHigh (ev, url, type, filters) function addToPercent (info) { doneBytes += info; - ev.sender.send("percent", Math.round(doneBytes / totalBytes * 100)); + sendPercent(Math.round(doneBytes / totalBytes * 100)); } function setMax (a, b, info3) { @@ -254,33 +252,51 @@ async function downloadVideoAndAudioHigh (ev, url, type, filters) fs.rmSync("./audio.mp3"); fs.rmSync("./video.mp4"); - win.webContents.send("doneDownload"); + doneDownload(); }) .on('end', function () { fs.rmSync("./audio.mp3"); fs.rmSync("./video.mp4"); - win.webContents.send("doneDownload", true); + doneDownload(true); + + if (!win.isFocused()) + { + win.flashFrame(true); + } ipcMain.once("doneDialogRes", (ev, res) => { if (res) { - var fileLoc = path.parse(fileName).dir; - shell.openPath(fileLoc); + shell.showItemInFolder(fileName); } }); }) .on("progress", (progress) => { - ev.sender.send("percent", Math.round(progress.percent)); + sendPercent(Math.round(progress.percent)); }) .save(fileName); } } } else { - win.webContents.send("doneDownload"); + doneDownload(); } +} + +function sendPercent (percent) +{ + var win = BrowserWindow.getAllWindows()[0]; + win.webContents.send("percent", percent); + win.setProgressBar(percent / 100); +} + +function doneDownload (isError) +{ + var win = BrowserWindow.getAllWindows()[0]; + win.setProgressBar(0); + win.webContents.send("doneDownload", isError); } \ No newline at end of file diff --git a/package.json b/package.json index b964f62..e4cc856 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "youtube-downloader", "productName": "YouTube Downloader", - "version": "1.0.0", + "version": "1.1.0", "description": "A standalone Youtube downloader", "main": "index.js", "repository": "https://github.com/Joery-M/YouTube-Downloader", @@ -47,7 +47,8 @@ "mac": { "category": "public.app-category.utilities", "icon": "./icon.icns", - "target": "pkg" + "target": "pkg", + "darkModeSupport": true } }, "config": { @@ -69,4 +70,4 @@ "webpack": "^5.74.0", "webpack-cli": "^4.10.0" } -} +} \ No newline at end of file diff --git a/src/index.html b/src/index.html index b35e312..72e4e47 100644 --- a/src/index.html +++ b/src/index.html @@ -16,7 +16,7 @@
@@ -104,7 +104,7 @@
-
Download done!
+
Download done!