Skip to content

Commit c3dc1f3

Browse files
author
Involvex
committed
feat: enhance screenshot functionality to trigger auto-generation of prompts and handle errors in main process
1 parent e7f84b3 commit c3dc1f3

2 files changed

Lines changed: 42 additions & 26 deletions

File tree

App.tsx

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ const Header = memo<{
8484
</svg>
8585
<div className="absolute -top-0.5 -right-0.5 w-1.5 h-1.5 bg-green-400 rounded-full opacity-0 group-hover:opacity-100 transition-opacity animate-pulse"></div>
8686
</button>
87-
8887
<button
8988
onClick={onTakeScreenshot}
9089
className="group relative p-2 text-gray-400 hover:text-cyan-400 transition-all duration-300 hover:bg-gray-700/50 rounded-lg border border-gray-700/50 hover:border-cyan-500/50 hover:shadow-md hover:shadow-cyan-500/10 touch-manipulation"
@@ -96,31 +95,33 @@ const Header = memo<{
9695
</svg>
9796
<div className="absolute -top-0.5 -right-0.5 w-1.5 h-1.5 bg-blue-400 rounded-full opacity-0 group-hover:opacity-100 transition-opacity animate-pulse"></div>
9897
</button>
99-
100-
<button
101-
onClick={onOpenSettings}
102-
className="group relative p-2 text-gray-400 hover:text-cyan-400 transition-all duration-300 hover:bg-gray-700/50 rounded-lg border border-gray-700/50 hover:border-cyan-500/50 hover:shadow-md hover:shadow-cyan-500/10 touch-manipulation"
103-
title="Settings"
104-
>
105-
<svg className="w-5 h-5 transition-transform group-hover:scale-110 group-hover:rotate-45" fill="none" stroke="currentColor" viewBox="0 0 24 24">
106-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
107-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
108-
</svg>
109-
<div className="absolute -top-0.5 -right-0.5 w-1.5 h-1.5 bg-purple-400 rounded-full opacity-0 group-hover:opacity-100 transition-opacity animate-pulse"></div>
110-
</button>
111-
112-
{/* Close button - only show in Electron app */}
113-
{window.electronAPI && onCloseApp && (
114-
<button
115-
onClick={onCloseApp}
116-
className="group relative p-2 text-gray-400 hover:text-red-400 transition-all duration-300 hover:bg-gray-700/50 rounded-lg border border-gray-700/50 hover:border-red-500/50 hover:shadow-md hover:shadow-red-500/10 touch-manipulation"
117-
title="Close Application"
118-
>
119-
<svg className="w-5 h-5 transition-transform group-hover:scale-110" fill="none" stroke="currentColor" viewBox="0 0 24 24">
120-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
121-
</svg>
122-
<div className="absolute -top-0.5 -right-0.5 w-1.5 h-1.5 bg-red-400 rounded-full opacity-0 group-hover:opacity-100 transition-opacity animate-pulse"></div>
123-
</button>
98+
{/* Hide settings button in web version */}
99+
{window.electronAPI && (
100+
<>
101+
<button
102+
onClick={onOpenSettings}
103+
className="group relative p-2 text-gray-400 hover:text-cyan-400 transition-all duration-300 hover:bg-gray-700/50 rounded-lg border border-gray-700/50 hover:border-cyan-500/50 hover:shadow-md hover:shadow-cyan-500/10 touch-manipulation"
104+
title="Settings"
105+
>
106+
<svg className="w-5 h-5 transition-transform group-hover:scale-110 group-hover:rotate-45" fill="none" stroke="currentColor" viewBox="0 0 24 24">
107+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
108+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
109+
</svg>
110+
<div className="absolute -top-0.5 -right-0.5 w-1.5 h-1.5 bg-purple-400 rounded-full opacity-0 group-hover:opacity-100 transition-opacity animate-pulse"></div>
111+
</button>
112+
{onCloseApp && (
113+
<button
114+
onClick={onCloseApp}
115+
className="group relative p-2 text-gray-400 hover:text-red-400 transition-all duration-300 hover:bg-gray-700/50 rounded-lg border border-gray-700/50 hover:border-red-500/50 hover:shadow-md hover:shadow-red-500/10 touch-manipulation"
116+
title="Close Application"
117+
>
118+
<svg className="w-5 h-5 transition-transform group-hover:scale-110" fill="none" stroke="currentColor" viewBox="0 0 24 24">
119+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
120+
</svg>
121+
<div className="absolute -top-0.5 -right-0.5 w-1.5 h-1.5 bg-red-400 rounded-full opacity-0 group-hover:opacity-100 transition-opacity animate-pulse"></div>
122+
</button>
123+
)}
124+
</>
124125
)}
125126
</div>
126127
</div>
@@ -820,6 +821,13 @@ function App() {
820821
onCloseApp={handleCloseApp}
821822
/>
822823
<main className="flex-grow container mx-auto px-2 sm:px-4 lg:px-8 py-4 sm:py-6 lg:py-8 flex flex-col items-center">
824+
{/* Web version header for GitHub Pages */}
825+
{!window.electronAPI && (
826+
<div className="w-full max-w-6xl mx-auto mb-4 p-3 sm:p-4 bg-gradient-to-r from-cyan-700/20 to-purple-700/20 border border-cyan-400/30 rounded-lg text-center">
827+
<h2 className="text-lg sm:text-xl font-bold text-cyan-300 mb-1">Get your own AI-powered chat generator!</h2>
828+
<a href="https://github.com/involvex/new-world-chat-ai" target="_blank" rel="noopener noreferrer" className="text-cyan-400 hover:text-purple-400 underline font-semibold">Visit the GitHub repo</a>
829+
</div>
830+
)}
823831
<div className="w-full max-w-6xl bg-gray-800/50 rounded-xl shadow-2xl p-3 sm:p-4 lg:p-6 border border-gray-700 hover-scale">
824832

825833
{!screenshotUrl ? (

electron/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,17 @@ ipcMain.handle('quit-app', () => {
697697
ipcMain.handle('take-screenshot', async () => {
698698
try {
699699
const screenshotDataUrl = await captureScreenshot();
700+
// Send screenshot to renderer and trigger auto-generation, just like the hotkey
701+
if (mainWindow) {
702+
mainWindow.webContents.send('hotkey-screenshot-captured', screenshotDataUrl);
703+
mainWindow.webContents.send('auto-generate-prompts', screenshotDataUrl);
704+
}
700705
return { success: true, dataUrl: screenshotDataUrl };
701706
} catch (error) {
702707
console.error('Screenshot capture failed:', error);
708+
if (mainWindow) {
709+
mainWindow.webContents.send('hotkey-screenshot-error', error.message);
710+
}
703711
return { success: false, error: error.message };
704712
}
705713
});

0 commit comments

Comments
 (0)