mirror of
https://github.com/yang991178/fluent-reader.git
synced 2025-04-27 00:18:48 +02:00
webview error description
This commit is contained in:
parent
9f85be51dc
commit
cfed0ac06d
@ -62,6 +62,13 @@ const utilsBridge = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addWebviewErrorListener: (callback: (reason: string) => any) => {
|
||||||
|
ipcRenderer.removeAllListeners("webview-error")
|
||||||
|
ipcRenderer.on("webview-error", (_, reason) => {
|
||||||
|
callback(reason)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
writeClipboard: (text: string) => {
|
writeClipboard: (text: string) => {
|
||||||
ipcRenderer.invoke("write-clipboard", text)
|
ipcRenderer.invoke("write-clipboard", text)
|
||||||
},
|
},
|
||||||
|
@ -27,6 +27,7 @@ type ArticleState = {
|
|||||||
loadWebpage: boolean
|
loadWebpage: boolean
|
||||||
loaded: boolean
|
loaded: boolean
|
||||||
error: boolean
|
error: boolean
|
||||||
|
errorDescription: string
|
||||||
}
|
}
|
||||||
|
|
||||||
class Article extends React.Component<ArticleProps, ArticleState> {
|
class Article extends React.Component<ArticleProps, ArticleState> {
|
||||||
@ -39,9 +40,11 @@ class Article extends React.Component<ArticleProps, ArticleState> {
|
|||||||
loadWebpage: this.props.source.openTarget === SourceOpenTarget.Webpage,
|
loadWebpage: this.props.source.openTarget === SourceOpenTarget.Webpage,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
error: false,
|
error: false,
|
||||||
|
errorDescription: "",
|
||||||
}
|
}
|
||||||
window.utils.addWebviewContextListener(this.contextMenuHandler)
|
window.utils.addWebviewContextListener(this.contextMenuHandler)
|
||||||
window.utils.addWebviewKeydownListener(this.keyDownHandler)
|
window.utils.addWebviewKeydownListener(this.keyDownHandler)
|
||||||
|
window.utils.addWebviewErrorListener(this.webviewError)
|
||||||
}
|
}
|
||||||
|
|
||||||
getFontSize = () => {
|
getFontSize = () => {
|
||||||
@ -132,8 +135,8 @@ class Article extends React.Component<ArticleProps, ArticleState> {
|
|||||||
webviewLoaded = () => {
|
webviewLoaded = () => {
|
||||||
this.setState({loaded: true})
|
this.setState({loaded: true})
|
||||||
}
|
}
|
||||||
webviewError = () => {
|
webviewError = (reason: string) => {
|
||||||
this.setState({error: true})
|
this.setState({error: true, errorDescription: reason})
|
||||||
}
|
}
|
||||||
webviewReload = () => {
|
webviewReload = () => {
|
||||||
if (this.webview) {
|
if (this.webview) {
|
||||||
@ -149,7 +152,6 @@ class Article extends React.Component<ArticleProps, ArticleState> {
|
|||||||
webview.focus()
|
webview.focus()
|
||||||
this.setState({loaded: false, error: false})
|
this.setState({loaded: false, error: false})
|
||||||
webview.addEventListener("did-stop-loading", this.webviewLoaded)
|
webview.addEventListener("did-stop-loading", this.webviewLoaded)
|
||||||
webview.addEventListener("did-fail-load", this.webviewError)
|
|
||||||
let card = document.querySelector(`#refocus div[data-iid="${this.props.item._id}"]`) as HTMLElement
|
let card = document.querySelector(`#refocus div[data-iid="${this.props.item._id}"]`) as HTMLElement
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (card) card.scrollIntoViewIfNeeded()
|
if (card) card.scrollIntoViewIfNeeded()
|
||||||
@ -247,6 +249,7 @@ class Article extends React.Component<ArticleProps, ArticleState> {
|
|||||||
<small>{intl.get("article.error")}</small>
|
<small>{intl.get("article.error")}</small>
|
||||||
<small><Link onClick={this.webviewReload}>{intl.get("article.reload")}</Link></small>
|
<small><Link onClick={this.webviewReload}>{intl.get("article.reload")}</Link></small>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
<span style={{fontSize: 11}}>{this.state.errorDescription}</span>
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
</FocusZone>
|
</FocusZone>
|
||||||
|
@ -82,6 +82,11 @@ export function setUtilsListeners(manager: WindowManager) {
|
|||||||
|
|
||||||
app.on("web-contents-created", (_, contents) => {
|
app.on("web-contents-created", (_, contents) => {
|
||||||
if (contents.getType() === "webview") {
|
if (contents.getType() === "webview") {
|
||||||
|
contents.on("did-fail-load", (event, code, desc, validated, isMainFrame) => {
|
||||||
|
if (isMainFrame && manager.hasWindow()) {
|
||||||
|
manager.mainWindow.webContents.send("webview-error", desc)
|
||||||
|
}
|
||||||
|
})
|
||||||
contents.on("context-menu", (_, params) => {
|
contents.on("context-menu", (_, params) => {
|
||||||
if (params.selectionText && manager.hasWindow()) {
|
if (params.selectionText && manager.hasWindow()) {
|
||||||
manager.mainWindow.webContents.send("webview-context-menu", [params.x, params.y], params.selectionText)
|
manager.mainWindow.webContents.send("webview-context-menu", [params.x, params.y], params.selectionText)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user