-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove search module and add baidu analyze
- Loading branch information
Showing
7 changed files
with
120 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import path from 'path'; | ||
import { app, BrowserWindow, shell } from 'electron'; | ||
import { resolveHtmlPath, getAssetPath } from './util'; | ||
|
||
const createDashboardWindow = async () => { | ||
const newDashboardWindow = new BrowserWindow({ | ||
show: false, | ||
center: true, | ||
autoHideMenuBar: true, | ||
width: 1560, | ||
height: 900, | ||
icon: getAssetPath('icon.png'), | ||
webPreferences: { | ||
nodeIntegration: true, | ||
contextIsolation: true, | ||
webSecurity: false, | ||
navigateOnDragDrop: true, | ||
preload: app.isPackaged | ||
? path.join(__dirname, 'preload.js') | ||
: path.join(__dirname, '../../.erb/dll/preload.js'), | ||
}, | ||
}); | ||
|
||
if (process.platform === 'darwin') { | ||
app.dock.setIcon(getAssetPath('icon.png')); | ||
app.dock.bounce(); | ||
} | ||
|
||
newDashboardWindow.loadURL(resolveHtmlPath('dashboard.html')); | ||
newDashboardWindow.on('close', (event) => { | ||
newDashboardWindow.hide(); | ||
event.preventDefault(); | ||
}); | ||
// 当窗口准备好时,最大化窗口 | ||
newDashboardWindow.webContents.on('did-finish-load', () => { | ||
newDashboardWindow.show(); | ||
}); | ||
newDashboardWindow.webContents.setWindowOpenHandler( | ||
(data: { url: string }) => { | ||
shell.openExternal(data.url); | ||
return { action: 'deny' }; | ||
}, | ||
); | ||
newDashboardWindow.webContents.on('will-navigate', (event, url) => { | ||
// 判断链接是否为本地文件 | ||
if (!url.startsWith('file://')) { | ||
event.preventDefault(); | ||
shell.openExternal(url); // 打开默认浏览器并跳转到该链接 | ||
} | ||
}); | ||
return newDashboardWindow; | ||
}; | ||
|
||
export default createDashboardWindow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
const baiduAnalyticsRenderer = (siteId: string, initCallback: any) => { | ||
if (!(siteId && typeof siteId === 'string')) { | ||
throw new TypeError(`require siteId`); | ||
} | ||
|
||
// 添加默认行为避免报错 | ||
window._hmt = window._hmt || []; | ||
|
||
window.electron.ipcRenderer.on( | ||
'baidu-analytics-electron-reply', | ||
(_, { text }) => { | ||
window._hmt = window._hmt || []; | ||
|
||
if (initCallback && typeof initCallback === 'function') { | ||
initCallback(window._hmt); | ||
} | ||
|
||
const hm = document.createElement('script'); | ||
hm.text = text; | ||
|
||
const head = document.getElementsByTagName('head')[0]; | ||
head.appendChild(hm); | ||
}, | ||
); | ||
|
||
window.electron.ipcRenderer.sendMessage( | ||
'baidu-analytics-electron-message', | ||
siteId, | ||
); | ||
}; | ||
|
||
export default baiduAnalyticsRenderer; |
Oops, something went wrong.