feat: add download & add video shortcuts (#101)

This commit is contained in:
Jelle Glebbeek
2021-07-03 21:42:27 +02:00
parent 77d59f0e08
commit 67afddc995
3 changed files with 25 additions and 7 deletions

12
main.js
View File

@@ -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()
});

View File

@@ -56,7 +56,9 @@ contextBridge.exposeInMainWorld(
"updateGlobalButtons",
"updateLinkPlaceholder",
"totalSize",
"binaryLock"
"binaryLock",
"addShortcut",
"downloadShortcut"
];
if (validChannels.includes(channel)) {
ipcRenderer.on(channel, (event, arg) => {

View File

@@ -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');