From f931092b965470527c423df218ef8fdcf58e19c1 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Fri, 17 Sep 2021 07:03:25 +0800 Subject: [PATCH] * Implement setting for disabling external link opening (#1427) * * Implement setting for disabling external link opening * * Implement setting for disabling external link opening in dropdown * * Place proper tooltip content on setting tooltip * Implement "open link after prompt" * Fix new setting placement and long translation entry value issue * fix via increasing width instead of truncating text * * Access new perference via computed property * ~ Move the code comment back to original place * * Update prompt to show URL * Fix missing :key for element with v-for * Do Nothing > No Action * $ Use shortcut to preference value in conditional statements * Update translation text * move and update tooltip text * Rename "Open Link After Prompt" > "Ask Before Opening Link" Also fix the translation value --- src/renderer/App.js | 44 ++++++++++++++++++- src/renderer/App.vue | 8 ++++ .../components/ft-prompt/ft-prompt.js | 4 ++ .../components/ft-prompt/ft-prompt.vue | 9 ++++ .../general-settings/general-settings.js | 20 ++++++++- .../general-settings/general-settings.sass | 9 ++++ .../general-settings/general-settings.vue | 8 ++++ src/renderer/store/modules/settings.js | 1 + static/locales/en-US.yaml | 12 ++++- 9 files changed, 111 insertions(+), 4 deletions(-) diff --git a/src/renderer/App.js b/src/renderer/App.js index d4b97d6d..c5b1115e 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -40,7 +40,14 @@ export default Vue.extend({ blogBannerMessage: '', latestBlogUrl: '', updateChangelog: '', - changeLogTitle: '' + changeLogTitle: '', + + lastExternalLinkToBeOpened: '', + showExternalLinkOpeningPrompt: false, + externalLinkOpeningPromptValues: [ + 'yes', + 'no' + ] } }, computed: { @@ -96,6 +103,17 @@ export default Vue.extend({ }, defaultInvidiousInstance: function () { return this.$store.getters.getDefaultInvidiousInstance + }, + + externalLinkOpeningPromptNames: function () { + return [ + this.$t('Yes'), + this.$t('No') + ] + }, + + externalLinkHandling: function () { + return this.$store.getters.getExternalLinkHandling } }, watch: { @@ -309,8 +327,18 @@ export default Vue.extend({ if (isYoutubeLink) { this.handleYoutubeLink(el.href) + } else if (this.externalLinkHandling === 'doNothing') { + // Let user know opening external link is disabled via setting + this.showToast({ + message: this.$t('External link opening has been disabled in the general settings') + }) + } else if (this.externalLinkHandling === 'openLinkAfterPrompt') { + // Storing the URL is necessary as + // there is no other way to pass the URL to click callback + this.lastExternalLinkToBeOpened = el.href + this.showExternalLinkOpeningPrompt = true } else { - // Open links externally by default + // Open links externally this.openExternalLink(el.href) } }) @@ -408,6 +436,18 @@ export default Vue.extend({ ipcRenderer.send('appReady') }, + handleExternalLinkOpeningPromptAnswer: function (option) { + this.showExternalLinkOpeningPrompt = false + + if (option === 'yes' && this.lastExternalLinkToBeOpened.length > 0) { + // Maybe user should be notified + // if `lastExternalLinkToBeOpened` is empty + + // Open links externally + this.openExternalLink(this.lastExternalLinkToBeOpened) + } + }, + ...mapMutations([ 'setInvidiousInstancesList' ]), diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 9187a759..0e5d5db1 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -57,6 +57,14 @@ /> + { return [] } + }, optionNames: { type: Array, default: () => { return [] } diff --git a/src/renderer/components/ft-prompt/ft-prompt.vue b/src/renderer/components/ft-prompt/ft-prompt.vue index 1c2830fd..da993727 100644 --- a/src/renderer/components/ft-prompt/ft-prompt.vue +++ b/src/renderer/components/ft-prompt/ft-prompt.vue @@ -8,6 +8,15 @@

{{ label }}

+

+ + {{ extraLabel }} + +

+