美化
This commit is contained in:
+29
-12
@@ -29,8 +29,8 @@ function createFloatingWindow(): void {
|
||||
const { width } = screen.getPrimaryDisplay().workAreaSize
|
||||
|
||||
floatingWindow = new BrowserWindow({
|
||||
width: 240,
|
||||
height: 210,
|
||||
width: 260,
|
||||
height: 160,
|
||||
x: width - 100,
|
||||
y: 20,
|
||||
frame: false,
|
||||
@@ -92,15 +92,23 @@ function createSettingsWindow(): void {
|
||||
}
|
||||
|
||||
function createChatWindow(initialText?: string): void {
|
||||
console.log('createChatWindow called with initialText:', initialText)
|
||||
|
||||
// If chat window already exists, focus it and send new text if provided
|
||||
if (chatWindow && !chatWindow.isDestroyed()) {
|
||||
console.log('Chat window already exists, focusing and sending text')
|
||||
chatWindow.focus()
|
||||
if (initialText) {
|
||||
chatWindow.webContents.send('set-initial-text', initialText)
|
||||
// Add a small delay to ensure the renderer is ready
|
||||
setTimeout(() => {
|
||||
chatWindow?.webContents.send('set-initial-text', initialText)
|
||||
console.log('Sent initial text to existing window:', initialText)
|
||||
}, 100)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
console.log('Creating new chat window')
|
||||
chatWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
@@ -122,8 +130,16 @@ function createChatWindow(initialText?: string): void {
|
||||
|
||||
// Send initial text after page loads
|
||||
if (initialText) {
|
||||
console.log('Setting up did-finish-load listener for initial text')
|
||||
chatWindow.webContents.once('did-finish-load', () => {
|
||||
chatWindow?.webContents.send('set-initial-text', initialText)
|
||||
console.log('Chat window did-finish-load event fired')
|
||||
// Add a small delay to ensure React components are mounted
|
||||
setTimeout(() => {
|
||||
if (chatWindow && !chatWindow.isDestroyed()) {
|
||||
console.log('Sending initial text to new window:', initialText)
|
||||
chatWindow.webContents.send('set-initial-text', initialText)
|
||||
}
|
||||
}, 200)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -338,15 +354,16 @@ function registerGlobalShortcuts(): void {
|
||||
|
||||
const registered = globalShortcut.register(shortcut, () => {
|
||||
if (floatingWindow && !floatingWindow.isDestroyed()) {
|
||||
// Get clipboard text for selected text
|
||||
const selectedText = clipboard.readText('selection')
|
||||
const text = selectedText || clipboard.readText()
|
||||
// Read clipboard content (user should copy text with Command+C first)
|
||||
// We only read the main clipboard, not the selection clipboard
|
||||
const text = clipboard.readText()
|
||||
|
||||
if (text && text.trim()) {
|
||||
// Send event to renderer to show prompt
|
||||
floatingWindow.webContents.send('show-text-prompt', text.trim())
|
||||
floatingWindow.focus()
|
||||
}
|
||||
console.log('Command+K pressed, clipboard content:', text?.substring(0, 50))
|
||||
|
||||
// Always send the event to toggle action menu
|
||||
// Pass clipboard text (empty string if clipboard is empty)
|
||||
floatingWindow.webContents.send('show-text-prompt', text || '')
|
||||
floatingWindow.focus()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user