From 2a8d7ab0cb3dd2ecee5ced33e7e53b24fb86acb8 Mon Sep 17 00:00:00 2001 From: nklhrstv Date: Tue, 2 Nov 2021 18:34:20 +0200 Subject: [PATCH] handle core initialization error with a ui dialog --- src/App/App.js | 40 +++++++++-------- src/App/ErrorDialog/ErrorDialog.js | 42 ++++++++++++++++++ src/App/ErrorDialog/index.js | 5 +++ src/App/ErrorDialog/styles.less | 70 ++++++++++++++++++++++++++++++ src/App/styles.less | 2 +- 5 files changed, 141 insertions(+), 18 deletions(-) create mode 100644 src/App/ErrorDialog/ErrorDialog.js create mode 100644 src/App/ErrorDialog/index.js create mode 100644 src/App/ErrorDialog/styles.less diff --git a/src/App/App.js b/src/App/App.js index 08e7acc3b..b054c7fb2 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -7,6 +7,7 @@ const { Core, Shell, Chromecast, KeyboardShortcuts, ServicesProvider } = require const { NotFound } = require('stremio/routes'); const { ToastProvider, sanitizeLocationPath, CONSTANTS } = require('stremio/common'); const CoreEventsToaster = require('./CoreEventsToaster'); +const ErrorDialog = require('./ErrorDialog'); const routerViewsConfig = require('./routerViewsConfig'); const styles = require('./styles'); @@ -26,8 +27,7 @@ const App = () => { chromecast: new Chromecast(), keyboardShortcuts: new KeyboardShortcuts() }), []); - const [coreInitialized, setCoreInitialized] = React.useState(false); - const [shellInitialized, setShellInitialized] = React.useState(false); + const [initialized, setInitialized] = React.useState(false); React.useEffect(() => { let prevPath = window.location.hash.slice(1); const onLocationHashChange = () => { @@ -46,13 +46,16 @@ const App = () => { }, []); React.useEffect(() => { const onCoreStateChanged = () => { - setCoreInitialized(services.core.active); - if (services.core.error) { - alert(services.core.error); - } + setInitialized( + (services.core.active || services.core.error instanceof Error) && + (services.shell.active || services.shell.error instanceof Error) + ); }; const onShellStateChanged = () => { - setShellInitialized(services.shell.active || services.shell.error instanceof Error); + setInitialized( + (services.core.active || services.core.error instanceof Error) && + (services.shell.active || services.shell.error instanceof Error) + ); }; const onChromecastStateChange = () => { if (services.chromecast.active) { @@ -86,17 +89,20 @@ const App = () => { { - coreInitialized && shellInitialized ? - - - - + initialized ? + services.core.error instanceof Error ? + + : + + + + : -
+
} diff --git a/src/App/ErrorDialog/ErrorDialog.js b/src/App/ErrorDialog/ErrorDialog.js new file mode 100644 index 000000000..4026f4555 --- /dev/null +++ b/src/App/ErrorDialog/ErrorDialog.js @@ -0,0 +1,42 @@ +// Copyright (C) 2017-2020 Smart code 203358507 + +const React = require('react'); +const PropTypes = require('prop-types'); +const classnames = require('classnames'); +const { Button, Image } = require('stremio/common'); +const styles = require('./styles'); + +const ErrorDialog = ({ className }) => { + const reload = React.useCallback(() => { + window.location.reload(); + }, []); + const clearData = React.useCallback(() => { + window.localStorage.clear(); + }, []); + return ( +
+ {' +
Something went wrong!
+
+ + +
+
+ ); +}; + +ErrorDialog.displayName = 'ErrorDialog'; + +ErrorDialog.propTypes = { + className: PropTypes.string +}; + +module.exports = ErrorDialog; diff --git a/src/App/ErrorDialog/index.js b/src/App/ErrorDialog/index.js new file mode 100644 index 000000000..5f8f12af0 --- /dev/null +++ b/src/App/ErrorDialog/index.js @@ -0,0 +1,5 @@ +// Copyright (C) 2017-2020 Smart code 203358507 + +const ErrorDialog = require('./ErrorDialog'); + +module.exports = ErrorDialog; diff --git a/src/App/ErrorDialog/styles.less b/src/App/ErrorDialog/styles.less new file mode 100644 index 000000000..9c91f9e29 --- /dev/null +++ b/src/App/ErrorDialog/styles.less @@ -0,0 +1,70 @@ +// Copyright (C) 2017-2020 Smart code 203358507 + +@import (reference) '~@stremio/stremio-colors/less/stremio-colors.less'; + +.error-container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + + .error-image { + flex: none; + width: 12rem; + height: 12rem; + margin-bottom: 1rem; + object-fit: contain; + object-position: center; + opacity: 0.9; + } + + .error-message { + flex: none; + padding: 0 3rem; + font-size: 2rem; + max-height: 3.6em; + text-align: center; + color: @color-surface-light5-90; + } + + .buttons-container { + flex: none; + align-self: stretch; + margin: 0 2rem; + display: flex; + flex-direction: row; + flex-wrap: wrap; + align-items: center; + justify-content: center; + + .button-container { + flex-grow: 0; + flex-shrink: 1; + flex-basis: auto; + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + margin: 2rem 1rem 0; + padding: 0 1rem; + min-width: 8rem; + height: 3rem; + background-color: @color-accent3; + + &:hover { + background-color: @color-accent3-light1; + } + + .label { + flex-grow: 0; + flex-shrink: 1; + flex-basis: auto; + max-height: 2.4em; + font-size: 1.1rem; + font-weight: 500; + text-align: center; + color: @color-surface-light5-90; + } + } + } +} \ No newline at end of file diff --git a/src/App/styles.less b/src/App/styles.less index 517215630..c8027018a 100644 --- a/src/App/styles.less +++ b/src/App/styles.less @@ -104,7 +104,7 @@ html { height: 100%; } - .app-loader { + .loader-container, .error-container { width: 100%; height: 100%; background-color: @color-background-dark2;