本文整理汇总了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)
}