Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow searching FreeTube through the command line #4675

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,11 @@ function runApp() {
}

function baseUrl(arg) {
// freetube.exe s="query"
if (arg.startsWith('s=')) {
return `https://www.youtube.com/results?search_query=${encodeURIComponent(arg.substring(2))}`
}

let newArg = arg.replace('freetube://', '')
// add support for authority free url
.replace('freetube:', '')
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export default defineComponent({
enableSetSearchQueryText: function () {
ipcRenderer.on(IpcChannels.UPDATE_SEARCH_INPUT_TEXT, (event, searchQueryText) => {
if (searchQueryText) {
this.$refs.topNav.updateSearchInputText(searchQueryText)
this.$refs.topNav.updateSearchInputText({ detail: { query: searchQueryText } })
}
})

Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/top-nav/top-nav-events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const events = new EventTarget()
export default events
10 changes: 8 additions & 2 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineComponent } from 'vue'
import { mapActions } from 'vuex'
import FtInput from '../ft-input/ft-input.vue'
import FtProfileSelector from '../ft-profile-selector/ft-profile-selector.vue'
import TopNavEvents from './top-nav-events'
import debounce from 'lodash.debounce'

import { IpcChannels, MOBILE_WIDTH_THRESHOLD } from '../../../constants'
Expand Down Expand Up @@ -134,6 +135,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 (queryText, { event }) {
Expand Down Expand Up @@ -342,8 +348,8 @@ export default defineComponent({
navigate: function (route) {
this.$router.push('/' + route)
},
updateSearchInputText: function (text) {
this.$refs.searchInput.updateInputData(text)
updateSearchInputText: function ({ detail: { query } }) {
Copy link

@Heptonius Heptonius Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me start with saying I have no position in the FreeTube project, but there is one note from me.

If the interface of the updateSearchInputText function should be changed - it's now object instead of string - the function should probably be renamed to better signify the use case.

Maybe a different question. Does the interface need to change at all? The underlying this.$refs.searchInput.updateInputData function expects string as well. Maybe for the use case as event handlers, the updateSearchInputText could be wrapped in a handler and called with the query the handler receives.

Also in following file, the updateSearchInputText is still used in the unchanched way. https://github.com/ChunkyProgrammer/FreeTube/blob/5c6abd99e53ea7edc6c24c0a3b5dc3530cc6e7c5/src/renderer/App.js#L473

this.$refs.searchInput.updateInputData(query)
},
...mapActions([
'getYoutubeUrlInfo',
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/views/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} 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'
import { SEARCH_CHAR_LIMIT } from '../../../constants'

export default defineComponent({
Expand Down Expand Up @@ -55,11 +56,14 @@ export default defineComponent({
// react to route changes...

const query = this.$route.params.query
TopNavEvents.dispatchEvent(new CustomEvent('updateSearchInput', { detail: { query } }))

let features = this.$route.query.features
// if page gets refreshed and there's only one feature then it will be a string
if (typeof features === 'string') {
features = [features]
}

const searchSettings = {
sortBy: this.$route.query.sortBy,
time: this.$route.query.time,
Expand All @@ -80,7 +84,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 } }))

let features = this.$route.query.features
// if page gets refreshed and there's only one feature then it will be a string
Expand All @@ -97,7 +104,7 @@ export default defineComponent({
}

const payload = {
query: this.query,
query,
options: {},
searchSettings: this.searchSettings
}
Expand Down
Loading