feat: cfg electron to open links in new window (#934)
Co-authored-by: Alex Hancock <alexhancock@block.xyz>
This commit is contained in:
@@ -116,38 +116,35 @@ export default function LinkPreview({ url }: LinkPreviewProps) {
|
||||
}
|
||||
|
||||
return (
|
||||
<Card
|
||||
className="max-w-[300px] truncate flex items-center bg-link-preview dark:bg-link-preview-dark p-3 transition-colors cursor-pointer"
|
||||
onClick={() => {
|
||||
window.electron.openInChrome(url);
|
||||
}}
|
||||
>
|
||||
{metadata.favicon && (
|
||||
<img
|
||||
src={metadata.favicon}
|
||||
alt="Site favicon"
|
||||
className="w-4 h-4 mr-2"
|
||||
onError={(e) => {
|
||||
e.currentTarget.style.display = 'none';
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">{metadata.title || url}</h4>
|
||||
{metadata.description && (
|
||||
<p className="text-xs text-gray-500 truncate">{metadata.description}</p>
|
||||
<a href={url} target="_blank" rel="noreferrer">
|
||||
<Card className="max-w-[300px] truncate flex items-center bg-link-preview dark:bg-link-preview-dark p-3 transition-colors cursor-pointer">
|
||||
{metadata.favicon && (
|
||||
<img
|
||||
src={metadata.favicon}
|
||||
alt="Site favicon"
|
||||
className="w-4 h-4 mr-2"
|
||||
onError={(e) => {
|
||||
e.currentTarget.style.display = 'none';
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{metadata.image && (
|
||||
<img
|
||||
src={metadata.image}
|
||||
alt="Preview"
|
||||
className="w-16 h-16 object-cover rounded ml-3"
|
||||
onError={(e) => {
|
||||
e.currentTarget.style.display = 'none';
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">{metadata.title || url}</h4>
|
||||
{metadata.description && (
|
||||
<p className="text-xs text-gray-500 truncate">{metadata.description}</p>
|
||||
)}
|
||||
</div>
|
||||
{metadata.image && (
|
||||
<img
|
||||
src={metadata.image}
|
||||
alt="Preview"
|
||||
className="w-16 h-16 object-cover rounded ml-3"
|
||||
onError={(e) => {
|
||||
e.currentTarget.style.display = 'none';
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -234,12 +234,14 @@ export default function Settings() {
|
||||
Add
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => window.electron.openInChrome(EXTENSIONS_SITE_LINK)}
|
||||
<a
|
||||
href={EXTENSIONS_SITE_LINK}
|
||||
target="_blank"
|
||||
className="text-indigo-500 hover:text-indigo-600 text-sm"
|
||||
rel="noreferrer"
|
||||
>
|
||||
Browse
|
||||
</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -171,6 +171,16 @@ const createChat = async (app, query?: string, dir?: string, version?: string) =
|
||||
},
|
||||
});
|
||||
|
||||
// Handle new window creation for links
|
||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||
// Open all links in external browser
|
||||
if (url.startsWith('http:') || url.startsWith('https:')) {
|
||||
require('electron').shell.openExternal(url);
|
||||
return { action: 'deny' };
|
||||
}
|
||||
return { action: 'allow' };
|
||||
});
|
||||
|
||||
// Load the index.html of the app.
|
||||
const queryParam = query ? `?initialQuery=${encodeURIComponent(query)}` : '';
|
||||
const { screen } = require('electron');
|
||||
|
||||
Reference in New Issue
Block a user