Skip to content

Commit

Permalink
feat: ux element when window becomes unresponsive
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias committed Jan 21, 2022
1 parent 6ccaf4f commit 04d48ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,9 @@
"clearCustomIpfsBinarySuccess": {
"title": "Clear custom IPFS binary",
"message": "The custom IPFS binary was cleared. To start using the bundled IPFS version, IPFS needs to be restarted first."
},
"unresponsiveWindowDialog": {
"title": "IPFS Desktop became unresponsive",
"message": "Do you wish to forcefully reload the app?"
}
}
18 changes: 16 additions & 2 deletions src/webui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ const { URL } = require('url')
const toUri = require('multiaddr-to-uri')
const serve = require('electron-serve')
const os = require('os')
const i18n = require('i18next')
const openExternal = require('./open-external')
const logger = require('../common/logger')
const store = require('../common/store')
const dock = require('../utils/dock')
const { VERSION, ELECTRON_VERSION } = require('../common/consts')
const createToggler = require('../utils/create-toggler')
const { showDialog } = require('../dialogs')

serve({ scheme: 'webui', directory: join(__dirname, '../../assets/webui') })

Expand Down Expand Up @@ -43,8 +45,20 @@ const createWindow = () => {
logger.error(`[web ui] render-process-gone: ${reason}, code: ${exitCode}`)
})

window.webContents.on('unresponsive', () => {
logger.error('[web ui] the webui became unresponsive')
window.webContents.on('unresponsive', async () => {
const opt = showDialog({
title: i18n.t('unresponsiveWindowDialog.title'),
message: i18n.t('unresponsiveWindowDialog.message'),
buttons: [
i18n.t('ok'),
i18n.t('cancel')
]
})

if (opt === 0) {
window.webContents.forcefullyCrashRenderer()
window.webContents.reload()
}
})

window.on('resize', () => {
Expand Down

0 comments on commit 04d48ea

Please sign in to comment.