* Update search in new window function to also copy original query text to new window search input (#2637)

This commit is contained in:
PikachuEXE 2022-09-30 05:22:28 +08:00 committed by GitHub
parent b62e5b65fa
commit 21371eec1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 10 deletions

View File

@ -170,7 +170,13 @@ function runApp() {
} }
} }
async function createWindow({ replaceMainWindow = true, windowStartupUrl = null, showWindowNow = false } = { }) { async function createWindow(
{
replaceMainWindow = true,
windowStartupUrl = null,
showWindowNow = false,
searchQueryText = null
} = { }) {
// Syncing new window background to theme choice. // Syncing new window background to theme choice.
const windowBackground = await baseHandlers.settings._findTheme().then(({ value }) => { const windowBackground = await baseHandlers.settings._findTheme().then(({ value }) => {
switch (value) { switch (value) {
@ -302,6 +308,12 @@ function runApp() {
.replace(/\\/g, '\\\\') .replace(/\\/g, '\\\\')
} }
if (typeof searchQueryText === 'string' && searchQueryText.length > 0) {
ipcMain.once('searchInputHandlingReady', () => {
newWindow.webContents.send('updateSearchInputText', searchQueryText)
})
}
// Show when loaded // Show when loaded
newWindow.once('ready-to-show', () => { newWindow.once('ready-to-show', () => {
if (newWindow.isVisible()) { if (newWindow.isVisible()) {
@ -445,11 +457,12 @@ function runApp() {
return powerSaveBlocker.start('prevent-display-sleep') return powerSaveBlocker.start('prevent-display-sleep')
}) })
ipcMain.on(IpcChannels.CREATE_NEW_WINDOW, (_e, { windowStartupUrl = null } = { }) => { ipcMain.on(IpcChannels.CREATE_NEW_WINDOW, (_e, { windowStartupUrl = null, searchQueryText = null } = { }) => {
createWindow({ createWindow({
replaceMainWindow: false, replaceMainWindow: false,
showWindowNow: true, showWindowNow: true,
windowStartupUrl: windowStartupUrl windowStartupUrl: windowStartupUrl,
searchQueryText: searchQueryText
}) })
}) })

View File

@ -160,6 +160,7 @@ export default Vue.extend({
this.setupListenersToSyncWindows() this.setupListenersToSyncWindows()
this.activateKeyboardShortcuts() this.activateKeyboardShortcuts()
this.openAllLinksExternally() this.openAllLinksExternally()
this.enableSetSearchQueryText()
this.enableOpenUrl() this.enableOpenUrl()
this.watchSystemTheme() this.watchSystemTheme()
await this.checkExternalPlayer() await this.checkExternalPlayer()
@ -408,7 +409,8 @@ export default Vue.extend({
this.openInternalPath({ this.openInternalPath({
path, path,
query, query,
doCreateNewWindow doCreateNewWindow,
searchQueryText: searchQuery
}) })
break break
} }
@ -467,7 +469,7 @@ export default Vue.extend({
}) })
}, },
openInternalPath: function({ path, doCreateNewWindow, query = {} }) { openInternalPath: function({ path, doCreateNewWindow, query = {}, searchQueryText = null }) {
if (process.env.IS_ELECTRON && doCreateNewWindow) { if (process.env.IS_ELECTRON && doCreateNewWindow) {
const { ipcRenderer } = require('electron') const { ipcRenderer } = require('electron')
@ -477,7 +479,8 @@ export default Vue.extend({
`#${path}?${(new URLSearchParams(query)).toString()}` `#${path}?${(new URLSearchParams(query)).toString()}`
].join('') ].join('')
ipcRenderer.send(IpcChannels.CREATE_NEW_WINDOW, { ipcRenderer.send(IpcChannels.CREATE_NEW_WINDOW, {
windowStartupUrl: newWindowStartupURL windowStartupUrl: newWindowStartupURL,
searchQueryText
}) })
} else { } else {
// Web // Web
@ -488,6 +491,16 @@ export default Vue.extend({
} }
}, },
enableSetSearchQueryText: function () {
ipcRenderer.on('updateSearchInputText', (event, searchQueryText) => {
if (searchQueryText) {
this.$refs.topNav.updateSearchInputText(searchQueryText)
}
})
ipcRenderer.send('searchInputHandlingReady')
},
enableOpenUrl: function () { enableOpenUrl: function () {
ipcRenderer.on('openUrl', (event, url) => { ipcRenderer.on('openUrl', (event, url) => {
if (url) { if (url) {

View File

@ -264,6 +264,10 @@ export default Vue.extend({
this.visibleDataList = visList this.visibleDataList = visList
}, },
updateInputData: function(text) {
this.inputData = text
},
...mapActions([ ...mapActions([
'getYoutubeUrlInfo' 'getYoutubeUrlInfo'
]) ])

View File

@ -140,7 +140,8 @@ export default Vue.extend({
this.openInternalPath({ this.openInternalPath({
path: `/search/${encodeURIComponent(searchQuery)}`, path: `/search/${encodeURIComponent(searchQuery)}`,
query, query,
doCreateNewWindow doCreateNewWindow,
searchQueryText: searchQuery
}) })
break break
} }
@ -179,7 +180,8 @@ export default Vue.extend({
type: this.searchSettings.type, type: this.searchSettings.type,
duration: this.searchSettings.duration duration: this.searchSettings.duration
}, },
doCreateNewWindow doCreateNewWindow,
searchQueryText: query
}) })
} }
} }
@ -300,7 +302,7 @@ export default Vue.extend({
this.$store.commit('toggleSideNav') this.$store.commit('toggleSideNav')
}, },
openInternalPath: function({ path, doCreateNewWindow, query = {} }) { openInternalPath: function({ path, doCreateNewWindow, query = {}, searchQueryText = null }) {
if (process.env.IS_ELECTRON && doCreateNewWindow) { if (process.env.IS_ELECTRON && doCreateNewWindow) {
const { ipcRenderer } = require('electron') const { ipcRenderer } = require('electron')
@ -310,7 +312,8 @@ export default Vue.extend({
`#${path}?${(new URLSearchParams(query)).toString()}` `#${path}?${(new URLSearchParams(query)).toString()}`
].join('') ].join('')
ipcRenderer.send(IpcChannels.CREATE_NEW_WINDOW, { ipcRenderer.send(IpcChannels.CREATE_NEW_WINDOW, {
windowStartupUrl: newWindowStartupURL windowStartupUrl: newWindowStartupURL,
searchQueryText
}) })
} else { } else {
// Web // Web
@ -335,6 +338,9 @@ export default Vue.extend({
hideFilters: function () { hideFilters: function () {
this.showFilters = false this.showFilters = false
}, },
updateSearchInputText: function(text) {
this.$refs.searchInput.updateInputData(text)
},
...mapActions([ ...mapActions([
'showToast', 'showToast',
'getYoutubeUrlInfo', 'getYoutubeUrlInfo',