Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #42 from nashaofu/dev
Browse files Browse the repository at this point in the history
修复优化网络错误问题
  • Loading branch information
nashaofu authored Jan 4, 2018
2 parents 9a56d4d + 6785b28 commit c023003
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
5 changes: 4 additions & 1 deletion app/dingtalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,12 @@ exports = module.exports = class DingTalk {
this.createContextMenu()
// 浏览器中打开链接
this.openURLEvent()
this.$window.webContents.on('did-fail-load', () => {
ipcMain.on('offline', () => {
this.$window.loadURL(`file://${__dirname}/window/error.html`)
})
ipcMain.on('online', () => {
this.$window.loadURL('https://im.dingtalk.com/')
})
// 加载URL地址
this.$window.loadURL('https://im.dingtalk.com/')
}
Expand Down
14 changes: 11 additions & 3 deletions app/window/js/error.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
const { ipcRenderer } = require('electron')
window.addEventListener('load', () => {
window.addEventListener('online', () => {
window.location.href = 'https://im.dingtalk.com/'
ipcRenderer.send('online')
})
document.querySelector('.error-container-retry').addEventListener('click', () => {
window.location.href = 'https://im.dingtalk.com/'
const $button = document.querySelector('.error-container-retry')
$button.addEventListener('click', () => {
if (!$button.disabled) {
$button.disabled = true
ipcRenderer.send('online')
}
})
if (navigator.onLine) {
ipcRenderer.send('online')
}
})
23 changes: 14 additions & 9 deletions app/window/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ class Injector {
window.addEventListener('load', () => {
this.injectCss()
this.injectJs()
if (!navigator.onLine && window.location.href === 'data:text/html,chromewebdata') {
ipcRenderer.send('offline')
}
})
}

// 注入CSS
injectCss () {
let filename = path.join(__dirname, '../css/css.css')
fs.readFile(filename, (err, css) => {
if (!err) {
const style = document.createElement('style')
const styleContent = document.createTextNode(css.toString())
style.appendChild(styleContent)
document.head.appendChild(style)
}
})
if (navigator.onLine) {
const filename = path.join(__dirname, '../css/css.css')
fs.readFile(filename, (err, css) => {
if (!err) {
const style = document.createElement('style')
const styleContent = document.createTextNode(css.toString())
style.appendChild(styleContent)
document.head.appendChild(style)
}
})
}
}

// 注入JS
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dingtalk",
"version": "1.4.4",
"version": "1.4.5",
"description": "钉钉linux桌面版",
"main": "./app/index.js",
"scripts": {
Expand Down

0 comments on commit c023003

Please sign in to comment.