Skip to content

Commit

Permalink
✨ Add dialog box when copy link from youtube
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerluiz committed Aug 25, 2020
1 parent 2dcc7fd commit ab8a1d7
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 7 deletions.
34 changes: 30 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
nativeTheme,
screen,
shell,
dialog,
} = require('electron')
const path = require('path')
const isDev = require('electron-is-dev')
Expand Down Expand Up @@ -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,
})
}
},
})
Expand Down
4 changes: 3 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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?"
}
4 changes: 3 additions & 1 deletion src/locales/pt.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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?"
}
4 changes: 3 additions & 1 deletion src/locales/scaffold.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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?"
}
21 changes: 21 additions & 0 deletions src/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,27 @@
</div>
</td>
</tr>
<tr id="clipboard-always-ask-read">
<td>
<span
class="settings-item-child"
></span>
<span
i18n="i18n_ALWAYS_ASK_WHEN_READ_LINK"
></span>
</td>
<td class="right">
<div class="switch">
<label>
<input
type="checkbox"
id="settings-clipboard-always-ask-read"
/>
<span class="lever"></span>
</label>
</div>
</td>
</tr>
<tr>
<td>
<span
Expand Down
16 changes: 16 additions & 0 deletions src/pages/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ function checkCompanionStatus() {
}
}

function checkClipboardWatcherStatus() {
if (settingsProvider.get('settings-clipboard-read')) {
document
.getElementById('clipboard-always-ask-read')
.classList.remove('hide')
} else {
document
.getElementById('clipboard-always-ask-read')
.classList.add('hide')
}
}

function checkWindows10ServiceStatus() {
if (settingsProvider.get('settings-windows10-media-service')) {
document.getElementById('windows-10-show-info').classList.remove('hide')
Expand All @@ -96,6 +108,7 @@ function checkWindows10ServiceStatus() {
}

checkCompanionStatus()
checkClipboardWatcherStatus()
checkWindows10ServiceStatus()

document.addEventListener('DOMContentLoaded', function () {
Expand All @@ -120,6 +133,7 @@ document.addEventListener('DOMContentLoaded', function () {
initElement('settings-app-language', 'change', showRelaunchButton)
initElement('settings-clipboard-read', 'click', () => {
ipc.send('switch-clipboard-watcher')
checkClipboardWatcherStatus()
})
initElement('titlebar-type', 'change', showRelaunchButton)
initElement('settings-custom-css-page', 'click')
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions src/utils/defaultSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit ab8a1d7

Please sign in to comment.