mirror of
https://github.com/jely2002/youtube-dl-gui.git
synced 2021-11-01 22:46:21 +03:00
feat: add download & add video shortcuts (#101)
This commit is contained in:
12
main.js
12
main.js
@@ -1,4 +1,4 @@
|
||||
const { app, BrowserWindow, ipcMain, dialog, Menu, shell, clipboard } = require('electron');
|
||||
const { app, BrowserWindow, ipcMain, dialog, Menu, shell, clipboard, globalShortcut } = require('electron');
|
||||
const Environment = require('./modules/Environment');
|
||||
const path = require('path');
|
||||
const QueryManager = require("./modules/QueryManager");
|
||||
@@ -64,7 +64,15 @@ function startCriticalHandlers(env) {
|
||||
if(appStarting) {
|
||||
appStarting = false;
|
||||
|
||||
//
|
||||
globalShortcut.register('Shift+CommandOrControl+V', async () => {
|
||||
win.webContents.send("addShortcut", clipboard.readText());
|
||||
});
|
||||
|
||||
globalShortcut.register('Shift+CommandOrControl+D', async () => {
|
||||
win.webContents.send("downloadShortcut");
|
||||
});
|
||||
|
||||
// Restore the videos from last session
|
||||
ipcMain.handle("restoreTaskList", () => {
|
||||
taskList.restore()
|
||||
});
|
||||
|
||||
@@ -56,7 +56,9 @@ contextBridge.exposeInMainWorld(
|
||||
"updateGlobalButtons",
|
||||
"updateLinkPlaceholder",
|
||||
"totalSize",
|
||||
"binaryLock"
|
||||
"binaryLock",
|
||||
"addShortcut",
|
||||
"downloadShortcut"
|
||||
];
|
||||
if (validChannels.includes(channel)) {
|
||||
ipcRenderer.on(channel, (event, arg) => {
|
||||
|
||||
@@ -38,6 +38,15 @@ async function init() {
|
||||
linkCopied = args.copied;
|
||||
});
|
||||
|
||||
// Verify the url when the addShortcut gets used
|
||||
window.main.receive("addShortcut", (link) => {
|
||||
verifyURL(link);
|
||||
})
|
||||
|
||||
window.main.receive("downloadShortcut", () => {
|
||||
$('#downloadBtn').click();
|
||||
})
|
||||
|
||||
//Init the when done dropdown
|
||||
$('.dropdown-toggle').dropdown();
|
||||
const availableOptions = await window.main.invoke('getDoneActions');
|
||||
@@ -88,7 +97,7 @@ async function init() {
|
||||
//Add url when user presses enter, but prevent default behavior
|
||||
$(document).on("keydown", "form", function(event) {
|
||||
if(event.key == "Enter") {
|
||||
verifyURL();
|
||||
verifyURL($('#add-url').val());
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
@@ -96,7 +105,7 @@ async function init() {
|
||||
|
||||
//Add url when user press on the + button
|
||||
$('#add-url-btn').on('click', () => {
|
||||
verifyURL();
|
||||
verifyURL($('#add-url').val());
|
||||
});
|
||||
|
||||
$('body').on('click', '#install-btn', () => {
|
||||
@@ -401,8 +410,7 @@ async function init() {
|
||||
});
|
||||
}
|
||||
|
||||
function verifyURL() {
|
||||
const value = $('#add-url').val()
|
||||
function verifyURL(value) {
|
||||
if (linkCopied && (value == null || value.length === 0)) {
|
||||
parseURL($('#add-url').prop('placeholder'));
|
||||
$('#url-form').trigger('reset');
|
||||
|
||||
Reference in New Issue
Block a user