Skip to content

Commit 06ca3e4

Browse files
authored
feat: support opening in browser for desktop (#778)
Co-authored-by: rick <[email protected]>
1 parent 1093622 commit 06ca3e4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

console/atest-desktop/preload.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ window.addEventListener('DOMContentLoaded', () => {
2727
for (const dependency of ['chrome', 'node', 'electron']) {
2828
replaceText(`${dependency}-version`, process.versions[dependency])
2929
}
30+
31+
const items = document.getElementsByTagName('a')
32+
for (const e of items) {
33+
if (e.href === 'https://github.com/LinuxSuRen/api-testing') {
34+
const openButton = document.createElement('button');
35+
openButton.style = 'margin-left: 10px; margin-bottom: 5px;';
36+
openButton.innerText = 'Open in Browser';
37+
openButton.onclick = () => {
38+
ipcRenderer.invoke('getHomePage').then((homePage) => {
39+
if (homePage) {
40+
ipcRenderer.invoke('openWithExternalBrowser', homePage);
41+
}
42+
})
43+
};
44+
e.parentNode.insertBefore(openButton, e.nextSibling);
45+
return
46+
}
47+
};
3048
})
3149

3250
contextBridge.exposeInMainWorld('electronAPI', {

0 commit comments

Comments
 (0)