aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared/src
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-02-28 01:13:06 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-03-06 18:56:49 +0100
commit2a5f7e3fecc98debea2b3408662d402a1e1681a0 (patch)
tree39b363cd8453007a8b6537e01813e0c8e61fe46c /packages/shared/src
parentfix(service-preload): Browser view canvas background (diff)
downloadsophie-2a5f7e3fecc98debea2b3408662d402a1e1681a0.tar.gz
sophie-2a5f7e3fecc98debea2b3408662d402a1e1681a0.tar.zst
sophie-2a5f7e3fecc98debea2b3408662d402a1e1681a0.zip
feat: Handle service load failures
Adds a "failed" state for services where the BrowserView and WebContents should be left around to keep history and allow people to navigate back. Access to the browser history otherwise doesn't seem possible (see https://github.com/electron/electron/issues/26727 and https://github.com/electron/electron/issues/7186), so destroying BrowserView and managing our own history is not possible. Also keep https://github.com/electron/electron/issues/24113 in mind. Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/shared/src')
-rw-r--r--packages/shared/src/stores/ServiceBase.ts62
1 files changed, 48 insertions, 14 deletions
diff --git a/packages/shared/src/stores/ServiceBase.ts b/packages/shared/src/stores/ServiceBase.ts
index cde403b..4a17bc5 100644
--- a/packages/shared/src/stores/ServiceBase.ts
+++ b/packages/shared/src/stores/ServiceBase.ts
@@ -23,20 +23,54 @@ import { IAnyModelType, Instance, types } from 'mobx-state-tree';
23import ServiceSettingsBase from './ServiceSettingsBase'; 23import ServiceSettingsBase from './ServiceSettingsBase';
24 24
25export function defineServiceModel<TS extends IAnyModelType>(settings: TS) { 25export function defineServiceModel<TS extends IAnyModelType>(settings: TS) {
26 return types.model('Service', { 26 return types
27 id: types.identifier, 27 .model('Service', {
28 settings, 28 id: types.identifier,
29 currentUrl: types.maybe(types.string), 29 settings,
30 canGoBack: false, 30 currentUrl: types.maybe(types.string),
31 canGoForward: false, 31 canGoBack: false,
32 title: types.maybe(types.string), 32 canGoForward: false,
33 state: types.optional( 33 title: types.maybe(types.string),
34 types.enumeration('ServiceState', ['loading', 'loaded', 'crashed']), 34 state: types.optional(
35 'loading', 35 types.union(
36 ), 36 types.model({
37 directMessageCount: 0, 37 type: types.literal('initializing'),
38 indirectMessageCount: 0, 38 }),
39 }); 39 types.model({
40 type: types.literal('loading'),
41 }),
42 types.model({
43 type: types.literal('loaded'),
44 }),
45 types.model({
46 type: types.literal('failed'),
47 errorCode: types.integer,
48 errorDesc: types.string,
49 }),
50 types.model({
51 type: types.literal('crashed'),
52 reason: types.string,
53 exitCode: types.integer,
54 }),
55 ),
56 { type: 'initializing' },
57 ),
58 directMessageCount: 0,
59 indirectMessageCount: 0,
60 })
61 .views((self) => ({
62 get loading(): boolean {
63 return (
64 self.state.type === 'initializing' || self.state.type === 'loading'
65 );
66 },
67 get failed(): boolean {
68 return self.state.type === 'failed';
69 },
70 get crashed(): boolean {
71 return self.state.type === 'crashed';
72 },
73 }));
40} 74}
41 75
42const ServiceBase = /* @__PURE__ */ (() => 76const ServiceBase = /* @__PURE__ */ (() =>