From 5e5e6d2af2c087bc81bc50ed0e2aca9dcb1729b4 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Tue, 7 Nov 2023 22:53:14 -0500 Subject: [PATCH 1/2] Add command line arg to search FreeTube https://github.com/FreeTubeApp/FreeTube/issues/1619 --- src/main/index.js | 5 +++++ src/renderer/App.js | 2 +- src/renderer/components/top-nav/top-nav-events.js | 2 ++ src/renderer/components/top-nav/top-nav.js | 10 ++++++++-- src/renderer/views/Search/Search.js | 9 +++++++-- 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/renderer/components/top-nav/top-nav-events.js diff --git a/src/main/index.js b/src/main/index.js index 63e7abb15d78..da1752994404 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1116,6 +1116,11 @@ function runApp() { } function baseUrl(arg) { + // freetube.exe s="query" + if (arg.startsWith('s=')) { + return `https://www.youtube.com/results?search_query=${arg.substring(2)}` + } + let newArg = arg.replace('freetube://', '') // add support for authority free url .replace('freetube:', '') diff --git a/src/renderer/App.js b/src/renderer/App.js index 21db0394f2e9..004025fb855b 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -473,7 +473,7 @@ export default defineComponent({ enableSetSearchQueryText: function () { ipcRenderer.on('updateSearchInputText', (event, searchQueryText) => { if (searchQueryText) { - this.$refs.topNav.updateSearchInputText(searchQueryText) + this.$refs.topNav.updateSearchInputText({ detail: { query: searchQueryText } }) } }) diff --git a/src/renderer/components/top-nav/top-nav-events.js b/src/renderer/components/top-nav/top-nav-events.js new file mode 100644 index 000000000000..95b4ffbb1fe9 --- /dev/null +++ b/src/renderer/components/top-nav/top-nav-events.js @@ -0,0 +1,2 @@ +const events = new EventTarget() +export default events diff --git a/src/renderer/components/top-nav/top-nav.js b/src/renderer/components/top-nav/top-nav.js index 801bb2c92da6..dd06ec40ff88 100644 --- a/src/renderer/components/top-nav/top-nav.js +++ b/src/renderer/components/top-nav/top-nav.js @@ -3,6 +3,7 @@ import { mapActions } from 'vuex' import FtInput from '../ft-input/ft-input.vue' import FtSearchFilters from '../ft-search-filters/ft-search-filters.vue' import FtProfileSelector from '../ft-profile-selector/ft-profile-selector.vue' +import TopNavEvents from './top-nav-events' import debounce from 'lodash.debounce' import { IpcChannels } from '../../../constants' @@ -103,6 +104,11 @@ export default defineComponent({ }) this.debounceSearchResults = debounce(this.getSearchSuggestions, 200) + + TopNavEvents.addEventListener('updateSearchInput', this.updateSearchInputText) + }, + beforeDestroy: function () { + TopNavEvents.removeEventListener('updateSearchInput', this.updateSearchInputText) }, methods: { goToSearch: async function (query, { event }) { @@ -334,8 +340,8 @@ export default defineComponent({ hideFilters: function () { this.showFilters = false }, - updateSearchInputText: function (text) { - this.$refs.searchInput.updateInputData(text) + updateSearchInputText: function ({ detail: { query } }) { + this.$refs.searchInput.updateInputData(query) }, ...mapActions([ 'getYoutubeUrlInfo', diff --git a/src/renderer/views/Search/Search.js b/src/renderer/views/Search/Search.js index e888af50bff3..4bb5f85eac66 100644 --- a/src/renderer/views/Search/Search.js +++ b/src/renderer/views/Search/Search.js @@ -5,6 +5,7 @@ import FtElementList from '../../components/ft-element-list/ft-element-list.vue' import { copyToClipboard, searchFiltersMatch, showToast } from '../../helpers/utils' import { getLocalSearchContinuation, getLocalSearchResults } from '../../helpers/api/local' import { invidiousAPICall } from '../../helpers/api/invidious' +import TopNavEvents from '../../components/top-nav/top-nav-events' export default defineComponent({ name: 'Search', @@ -47,6 +48,7 @@ export default defineComponent({ // react to route changes... const query = this.$route.params.query + TopNavEvents.dispatchEvent(new CustomEvent('updateSearchInput', { detail: { query } })) const searchSettings = { sortBy: this.$route.query.sortBy, time: this.$route.query.time, @@ -66,7 +68,10 @@ export default defineComponent({ } }, mounted: function () { - this.query = this.$route.params.query + const query = this.$route.params.query + + this.query = query + TopNavEvents.dispatchEvent(new CustomEvent('updateSearchInput', { detail: { query } })) this.searchSettings = { sortBy: this.$route.query.sortBy, @@ -76,7 +81,7 @@ export default defineComponent({ } const payload = { - query: this.query, + query, options: {}, searchSettings: this.searchSettings } From d9747bc47682c7988ccb302d50581afbf4cf0fd5 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:38:57 -0500 Subject: [PATCH 2/2] url encode search query --- src/main/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/index.js b/src/main/index.js index c8d4a3a727df..c3cd0239926d 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1149,7 +1149,7 @@ function runApp() { function baseUrl(arg) { // freetube.exe s="query" if (arg.startsWith('s=')) { - return `https://www.youtube.com/results?search_query=${arg.substring(2)}` + return `https://www.youtube.com/results?search_query=${encodeURIComponent(arg.substring(2))}` } let newArg = arg.replace('freetube://', '')