本文整理匯總了TypeScript中electron.shell.openExternalSync方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript shell.openExternalSync方法的具體用法?TypeScript shell.openExternalSync怎麽用?TypeScript shell.openExternalSync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類electron.shell
的用法示例。
在下文中一共展示了shell.openExternalSync方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: click
export const setDefaultApplicationMenu = () => {
if (v8Util.getHiddenValue<boolean>(global, 'applicationMenuSet')) return
const helpMenu: Electron.MenuItemConstructorOptions = {
role: 'help',
submenu: [
{
label: 'Learn More',
click () {
shell.openExternalSync('https://electronjs.org')
}
},
{
label: 'Documentation',
click () {
shell.openExternalSync(
`https://github.com/electron/electron/tree/v${process.versions.electron}/docs#readme`
)
}
},
{
label: 'Community Discussions',
click () {
shell.openExternalSync('https://discuss.atom.io/c/electron')
}
},
{
label: 'Search Issues',
click () {
shell.openExternalSync('https://github.com/electron/electron/issues')
}
}
]
}
const macAppMenu: Electron.MenuItemConstructorOptions = { role: 'appMenu' }
const template: Electron.MenuItemConstructorOptions[] = [
...(isMac ? [macAppMenu] : []),
{ role: 'fileMenu' },
{ role: 'editMenu' },
{ role: 'viewMenu' },
{ role: 'windowMenu' },
helpMenu
]
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}
示例2: BrowserWindow
webContents.on('new-window', (event: Event, url, frameName, _disposition, options) => {
event.preventDefault();
if (url === 'about:blank') {
if (frameName !== 'about:blank') {
// Voice/video call popup
options.show = true;
options.titleBarStyle = 'default';
options.webPreferences.nodeIntegration = false;
options.webPreferences.preload = path.join(__dirname, 'browser-call.js');
(event as any).newGuest = new BrowserWindow(options);
}
} else {
if (url.startsWith(trackingUrlPrefix)) {
url = new URL(url).searchParams.get('u')!;
}
shell.openExternalSync(url);
}
});
示例3: URL
webContents.on('will-navigate', (event, url) => {
const isMessengerDotCom = (url: string): boolean => {
const {hostname} = new URL(url);
return hostname.endsWith('.messenger.com');
};
const isTwoFactorAuth = (url: string): boolean => {
const twoFactorAuthURL = 'https://www.facebook.com/checkpoint/start';
return url.startsWith(twoFactorAuthURL);
};
const isWorkChat = (url: string): boolean => {
const {hostname, pathname} = new URL(url);
if (hostname === 'work.facebook.com' || hostname === 'work.workplace.com') {
return true;
}
if (
// Example: https://company-name.facebook.com/login or
// https://company-name.workplace.com/login
(hostname.endsWith('.facebook.com') || hostname.endsWith('.workplace.com')) &&
(pathname.startsWith('/login') || pathname.startsWith('/chat'))
) {
return true;
}
if (hostname === 'login.microsoftonline.com') {
return true;
}
return false;
};
if (isMessengerDotCom(url) || isTwoFactorAuth(url) || isWorkChat(url)) {
return;
}
event.preventDefault();
shell.openExternalSync(url);
});
示例4:
const openLinkExternally = (e: Event) => {
e.preventDefault()
shell.openExternalSync(url)
}