Skip to content

Commit

Permalink
Add command line arg to search FreeTube
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkyProgrammer committed Nov 8, 2023
1 parent 6bbf11f commit 5e5e6d2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:', '')
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } })
}
})

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 @@ -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'
Expand Down Expand Up @@ -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 }) {
Expand Down Expand Up @@ -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',
Expand Down
9 changes: 7 additions & 2 deletions src/renderer/views/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -76,7 +81,7 @@ export default defineComponent({
}

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

0 comments on commit 5e5e6d2

Please sign in to comment.