* 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.
const windowBackground = await baseHandlers.settings._findTheme().then(({ value }) => {
switch (value) {
@ -302,6 +308,12 @@ function runApp() {
.replace(/\\/g, '\\\\')
}
if (typeof searchQueryText === 'string' && searchQueryText.length > 0) {
ipcMain.once('searchInputHandlingReady', () => {
newWindow.webContents.send('updateSearchInputText', searchQueryText)
})
}
// Show when loaded
newWindow.once('ready-to-show', () => {
if (newWindow.isVisible()) {
@ -445,11 +457,12 @@ function runApp() {
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({
replaceMainWindow: false,
showWindowNow: true,
windowStartupUrl: windowStartupUrl
windowStartupUrl: windowStartupUrl,
searchQueryText: searchQueryText
})
})

View File

@ -160,6 +160,7 @@ export default Vue.extend({
this.setupListenersToSyncWindows()
this.activateKeyboardShortcuts()
this.openAllLinksExternally()
this.enableSetSearchQueryText()
this.enableOpenUrl()
this.watchSystemTheme()
await this.checkExternalPlayer()
@ -408,7 +409,8 @@ export default Vue.extend({
this.openInternalPath({
path,
query,
doCreateNewWindow
doCreateNewWindow,
searchQueryText: searchQuery
})
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) {
const { ipcRenderer } = require('electron')
@ -477,7 +479,8 @@ export default Vue.extend({
`#${path}?${(new URLSearchParams(query)).toString()}`
].join('')
ipcRenderer.send(IpcChannels.CREATE_NEW_WINDOW, {
windowStartupUrl: newWindowStartupURL
windowStartupUrl: newWindowStartupURL,
searchQueryText
})
} else {
// 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 () {
ipcRenderer.on('openUrl', (event, url) => {
if (url) {

View File

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

View File

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