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 (
|
return (
|
||||||
<Card
|
<a href={url} target="_blank" rel="noreferrer">
|
||||||
className="max-w-[300px] truncate flex items-center bg-link-preview dark:bg-link-preview-dark p-3 transition-colors cursor-pointer"
|
<Card className="max-w-[300px] truncate flex items-center bg-link-preview dark:bg-link-preview-dark p-3 transition-colors cursor-pointer">
|
||||||
onClick={() => {
|
{metadata.favicon && (
|
||||||
window.electron.openInChrome(url);
|
<img
|
||||||
}}
|
src={metadata.favicon}
|
||||||
>
|
alt="Site favicon"
|
||||||
{metadata.favicon && (
|
className="w-4 h-4 mr-2"
|
||||||
<img
|
onError={(e) => {
|
||||||
src={metadata.favicon}
|
e.currentTarget.style.display = 'none';
|
||||||
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>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
<div className="flex-1 min-w-0">
|
||||||
{metadata.image && (
|
<h4 className="text-sm font-medium truncate">{metadata.title || url}</h4>
|
||||||
<img
|
{metadata.description && (
|
||||||
src={metadata.image}
|
<p className="text-xs text-gray-500 truncate">{metadata.description}</p>
|
||||||
alt="Preview"
|
)}
|
||||||
className="w-16 h-16 object-cover rounded ml-3"
|
</div>
|
||||||
onError={(e) => {
|
{metadata.image && (
|
||||||
e.currentTarget.style.display = 'none';
|
<img
|
||||||
}}
|
src={metadata.image}
|
||||||
/>
|
alt="Preview"
|
||||||
)}
|
className="w-16 h-16 object-cover rounded ml-3"
|
||||||
</Card>
|
onError={(e) => {
|
||||||
|
e.currentTarget.style.display = 'none';
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
</a>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,12 +234,14 @@ export default function Settings() {
|
|||||||
Add
|
Add
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<a
|
||||||
onClick={() => window.electron.openInChrome(EXTENSIONS_SITE_LINK)}
|
href={EXTENSIONS_SITE_LINK}
|
||||||
|
target="_blank"
|
||||||
className="text-indigo-500 hover:text-indigo-600 text-sm"
|
className="text-indigo-500 hover:text-indigo-600 text-sm"
|
||||||
|
rel="noreferrer"
|
||||||
>
|
>
|
||||||
Browse
|
Browse
|
||||||
</button>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</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.
|
// Load the index.html of the app.
|
||||||
const queryParam = query ? `?initialQuery=${encodeURIComponent(query)}` : '';
|
const queryParam = query ? `?initialQuery=${encodeURIComponent(query)}` : '';
|
||||||
const { screen } = require('electron');
|
const { screen } = require('electron');
|
||||||
|
|||||||
Reference in New Issue
Block a user