From ab8a1d703d8eba54a09b26f81dbb3e7b507ed655 Mon Sep 17 00:00:00 2001 From: Adler Luiz Date: Tue, 25 Aug 2020 03:02:33 -0300 Subject: [PATCH] :sparkles: Add dialog box when copy link from youtube --- main.js | 34 ++++++++++++++++++++++++++++---- src/locales/en.json | 4 +++- src/locales/pt.json | 4 +++- src/locales/scaffold.json | 4 +++- src/pages/settings/settings.html | 21 ++++++++++++++++++++ src/pages/settings/settings.js | 16 +++++++++++++++ src/utils/defaultSettings.js | 2 ++ 7 files changed, 78 insertions(+), 7 deletions(-) diff --git a/main.js b/main.js index a0bea27e5..b43a37f73 100644 --- a/main.js +++ b/main.js @@ -11,6 +11,7 @@ const { nativeTheme, screen, shell, + dialog, } = require('electron') const path = require('path') const isDev = require('electron-is-dev') @@ -1601,14 +1602,39 @@ function createWindow() { if (settingsProvider.get('settings-clipboard-read')) { clipboardWatcher = ClipboardWatcher({ watchDelay: 1000, - onImageChange: function (nativeImage) {}, - onTextChange: function (text) { + onTextChange: (text) => { let regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/ let match = text.match(regExp) if (match && match[2].length == 11) { let videoId = match[2] - logDebug('Video readed from clipboard: ' + videoId) - loadMusicByVideoId(videoId) + + if ( + settingsProvider.get( + 'settings-clipboard-always-ask-read' + ) + ) { + let options = { + type: 'question', + buttons: ['Yes', 'No'], + defaultId: 0, + title: 'YouTube Music Desktop', + message: `Want to play this link?\n\n${text}`, + } + + dialog + .showMessageBox(mainWindow, options) + .then((success) => { + if (success.response == 0) { + loadMusicByVideoId(videoId) + } + }) + } else { + loadMusicByVideoId(videoId) + } + writeLog({ + type: 'info', + data: 'Video readed from clipboard: ' + videoId, + }) } }, }) diff --git a/src/locales/en.json b/src/locales/en.json index 82bfae6a1..b0e35651c 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1,4 +1,5 @@ { + "ALWAYS_ASK_WHEN_READ_LINK": "Always ask when read link", "DOUBLE_CLICK_TO_RESET_POSITION": "Double Click to Reset Position", "LABEL_ALSO": "Also", "LABEL_AUDIO": "Audio", @@ -92,5 +93,6 @@ "ADD_TO_LIBRARY": "Add to library", "ADD_TO_PLAYLIST": "Add to playlist", "SKIP_TRACK_MARKED_DISLIKED": "Skip tracks marked as 'Disliked'", - "SKIP_TRACK_SHORTER_THAN": "Skip tracks shorter than" + "SKIP_TRACK_SHORTER_THAN": "Skip tracks shorter than", + "WANT_PLAY_THIS_LINK": "Want to play this link?" } diff --git a/src/locales/pt.json b/src/locales/pt.json index 7c9825f23..0e2c218b8 100644 --- a/src/locales/pt.json +++ b/src/locales/pt.json @@ -1,4 +1,5 @@ { + "ALWAYS_ASK_WHEN_READ_LINK": "Sempre perguntar ao ler link", "DOUBLE_CLICK_TO_RESET_POSITION": "Clique duplo para resetar a posição", "LABEL_ALSO": "Também", "LABEL_AUDIO": "Áudio", @@ -92,5 +93,6 @@ "ADD_TO_LIBRARY": "Adicionar à biblioteca", "ADD_TO_PLAYLIST": "Adicionar à playlist", "SKIP_TRACK_MARKED_DISLIKED": "Pular faixas marcadas como 'Não gostei'", - "SKIP_TRACK_SHORTER_THAN": "Pular faixas mais curtas que" + "SKIP_TRACK_SHORTER_THAN": "Pular faixas mais curtas que", + "WANT_PLAY_THIS_LINK": "Deseja executar este link?" } diff --git a/src/locales/scaffold.json b/src/locales/scaffold.json index 82bfae6a1..b0e35651c 100644 --- a/src/locales/scaffold.json +++ b/src/locales/scaffold.json @@ -1,4 +1,5 @@ { + "ALWAYS_ASK_WHEN_READ_LINK": "Always ask when read link", "DOUBLE_CLICK_TO_RESET_POSITION": "Double Click to Reset Position", "LABEL_ALSO": "Also", "LABEL_AUDIO": "Audio", @@ -92,5 +93,6 @@ "ADD_TO_LIBRARY": "Add to library", "ADD_TO_PLAYLIST": "Add to playlist", "SKIP_TRACK_MARKED_DISLIKED": "Skip tracks marked as 'Disliked'", - "SKIP_TRACK_SHORTER_THAN": "Skip tracks shorter than" + "SKIP_TRACK_SHORTER_THAN": "Skip tracks shorter than", + "WANT_PLAY_THIS_LINK": "Want to play this link?" } diff --git a/src/pages/settings/settings.html b/src/pages/settings/settings.html index c9ba632ae..dbdb278c0 100644 --- a/src/pages/settings/settings.html +++ b/src/pages/settings/settings.html @@ -761,6 +761,27 @@ + + + + + + +
+ +
+ + { ipc.send('switch-clipboard-watcher') + checkClipboardWatcherStatus() }) initElement('titlebar-type', 'change', showRelaunchButton) initElement('settings-custom-css-page', 'click') @@ -148,6 +162,8 @@ document.addEventListener('DOMContentLoaded', function () { initElement('settings-continue-where-left-of', 'click') initElement('settings-skip-track-disliked', 'click') + + initElement('settings-clipboard-always-ask-read', 'click') mInit() document.getElementById('content').classList.remove('hide') diff --git a/src/utils/defaultSettings.js b/src/utils/defaultSettings.js index 9311cd127..931d7fc0d 100644 --- a/src/utils/defaultSettings.js +++ b/src/utils/defaultSettings.js @@ -92,3 +92,5 @@ settingsProvider.setInitialValue('settings-shortcut-buttons', { settingsProvider.setInitialValue('settings-skip-track-disliked', false) settingsProvider.setInitialValue('settings-skip-track-shorter-than', '0') + +settingsProvider.setInitialValue('settings-clipboard-always-ask-read', true)