mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 10:40:07 +08:00
冲突
This commit is contained in:
parent
d64b4f3210
commit
db394ea1c0
@ -64,11 +64,6 @@ export enum IpcChannel {
|
||||
Aes_Encrypt = 'aes:encrypt',
|
||||
Aes_Decrypt = 'aes:decrypt',
|
||||
|
||||
// search window
|
||||
SearchWindow_Open = 'search-window:open',
|
||||
SearchWindow_Close = 'search-window:close',
|
||||
SearchWindow_OpenUrl = 'search-window:open-url',
|
||||
|
||||
Gemini_UploadFile = 'gemini:upload-file',
|
||||
Gemini_Base64File = 'gemini:base64-file',
|
||||
Gemini_RetrieveFile = 'gemini:retrieve-file',
|
||||
|
||||
@ -24,7 +24,6 @@ import * as NutstoreService from './services/NutstoreService'
|
||||
import ObsidianVaultService from './services/ObsidianVaultService'
|
||||
import { ProxyConfig, proxyManager } from './services/ProxyManager'
|
||||
import { registerShortcuts, unregisterAllShortcuts } from './services/ShortcutService'
|
||||
import { searchService } from './services/SearchService'
|
||||
import { TrayService } from './services/TrayService'
|
||||
import { windowService } from './services/WindowService'
|
||||
import { getResourcePath } from './utils'
|
||||
@ -298,17 +297,6 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
||||
NutstoreService.getDirectoryContents(token, path)
|
||||
)
|
||||
|
||||
// search window
|
||||
ipcMain.handle(IpcChannel.SearchWindow_Open, async (_, uid: string) => {
|
||||
await searchService.openSearchWindow(uid)
|
||||
})
|
||||
ipcMain.handle(IpcChannel.SearchWindow_Close, async (_, uid: string) => {
|
||||
await searchService.closeSearchWindow(uid)
|
||||
})
|
||||
ipcMain.handle(IpcChannel.SearchWindow_OpenUrl, async (_, uid: string, url: string) => {
|
||||
return await searchService.openUrlInSearchWindow(uid, url)
|
||||
})
|
||||
|
||||
// 启动ASR服务器
|
||||
ipcMain.handle('start-asr-server', async () => {
|
||||
try {
|
||||
|
||||
@ -1,100 +0,0 @@
|
||||
import { BrowserWindow } from 'electron'
|
||||
import { join } from 'path'
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
import { isMac } from '@main/constant'
|
||||
|
||||
class SearchService {
|
||||
private searchWindows: Map<string, BrowserWindow> = new Map()
|
||||
|
||||
/**
|
||||
* 打开搜索窗口
|
||||
* @param uid 窗口唯一标识符
|
||||
*/
|
||||
public async openSearchWindow(uid: string): Promise<void> {
|
||||
// 如果窗口已经存在,则激活它
|
||||
if (this.searchWindows.has(uid)) {
|
||||
const existingWindow = this.searchWindows.get(uid)
|
||||
if (existingWindow && !existingWindow.isDestroyed()) {
|
||||
if (existingWindow.isMinimized()) {
|
||||
existingWindow.restore()
|
||||
}
|
||||
existingWindow.focus()
|
||||
return
|
||||
}
|
||||
// 如果窗口已销毁,则从Map中移除
|
||||
this.searchWindows.delete(uid)
|
||||
}
|
||||
|
||||
// 创建新窗口
|
||||
const searchWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
show: false,
|
||||
autoHideMenuBar: true,
|
||||
...(isMac ? { titleBarStyle: 'hidden' } : {}),
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
sandbox: false,
|
||||
webSecurity: false
|
||||
}
|
||||
})
|
||||
|
||||
// 设置窗口标题
|
||||
searchWindow.setTitle(`搜索窗口 - ${uid}`)
|
||||
|
||||
// 加载搜索页面
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
searchWindow.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/#/search?uid=${uid}`)
|
||||
} else {
|
||||
searchWindow.loadFile(join(__dirname, '../renderer/index.html'), {
|
||||
hash: `/search?uid=${uid}`
|
||||
})
|
||||
}
|
||||
|
||||
// 窗口准备好后显示
|
||||
searchWindow.once('ready-to-show', () => {
|
||||
searchWindow.show()
|
||||
})
|
||||
|
||||
// 窗口关闭时从Map中移除
|
||||
searchWindow.on('closed', () => {
|
||||
this.searchWindows.delete(uid)
|
||||
})
|
||||
|
||||
// 存储窗口引用
|
||||
this.searchWindows.set(uid, searchWindow)
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭搜索窗口
|
||||
* @param uid 窗口唯一标识符
|
||||
*/
|
||||
public async closeSearchWindow(uid: string): Promise<void> {
|
||||
const window = this.searchWindows.get(uid)
|
||||
if (window && !window.isDestroyed()) {
|
||||
window.close()
|
||||
}
|
||||
this.searchWindows.delete(uid)
|
||||
}
|
||||
|
||||
/**
|
||||
* 在搜索窗口中打开URL
|
||||
* @param uid 窗口唯一标识符
|
||||
* @param url 要打开的URL
|
||||
*/
|
||||
public async openUrlInSearchWindow(uid: string, url: string): Promise<boolean> {
|
||||
const window = this.searchWindows.get(uid)
|
||||
if (window && !window.isDestroyed()) {
|
||||
try {
|
||||
await window.loadURL(url)
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error(`Failed to load URL in search window: ${error}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export const searchService = new SearchService()
|
||||
5
src/preload/index.d.ts
vendored
5
src/preload/index.d.ts
vendored
@ -175,11 +175,6 @@ declare global {
|
||||
decryptToken: (token: string) => Promise<{ username: string; access_token: string }>
|
||||
getDirectoryContents: (token: string, path: string) => Promise<any>
|
||||
}
|
||||
searchWindow: {
|
||||
open: (uid: string) => Promise<void>
|
||||
close: (uid: string) => Promise<void>
|
||||
openUrl: (uid: string, url: string) => Promise<boolean>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,11 +169,6 @@ const api = {
|
||||
decryptToken: (token: string) => ipcRenderer.invoke(IpcChannel.Nutstore_DecryptToken, token),
|
||||
getDirectoryContents: (token: string, path: string) =>
|
||||
ipcRenderer.invoke(IpcChannel.Nutstore_GetDirectoryContents, token, path)
|
||||
},
|
||||
searchWindow: {
|
||||
open: (uid: string) => ipcRenderer.invoke(IpcChannel.SearchWindow_Open, uid),
|
||||
close: (uid: string) => ipcRenderer.invoke(IpcChannel.SearchWindow_Close, uid),
|
||||
openUrl: (uid: string, url: string) => ipcRenderer.invoke(IpcChannel.SearchWindow_OpenUrl, uid, url)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user