diff options
Diffstat (limited to 'packages/main')
-rw-r--r-- | packages/main/src/infrastructure/electron/impl/ElectronServiceView.ts | 12 | ||||
-rw-r--r-- | packages/main/src/infrastructure/electron/types.ts | 4 | ||||
-rw-r--r-- | packages/main/src/stores/MainStore.ts | 21 | ||||
-rw-r--r-- | packages/main/src/stores/Service.ts | 60 |
4 files changed, 93 insertions, 4 deletions
diff --git a/packages/main/src/infrastructure/electron/impl/ElectronServiceView.ts b/packages/main/src/infrastructure/electron/impl/ElectronServiceView.ts index 6ff8e21..e5fdf11 100644 --- a/packages/main/src/infrastructure/electron/impl/ElectronServiceView.ts +++ b/packages/main/src/infrastructure/electron/impl/ElectronServiceView.ts | |||
@@ -105,6 +105,18 @@ export default class ElectronServiceView implements ServiceView { | |||
105 | this.browserView.webContents.goForward(); | 105 | this.browserView.webContents.goForward(); |
106 | } | 106 | } |
107 | 107 | ||
108 | reload(ignoreCache: boolean): void { | ||
109 | if (ignoreCache) { | ||
110 | this.browserView.webContents.reloadIgnoringCache(); | ||
111 | } else { | ||
112 | this.browserView.webContents.reload(); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | stop(): void { | ||
117 | this.browserView.webContents.stop(); | ||
118 | } | ||
119 | |||
108 | setBounds(bounds: BrowserViewBounds): void { | 120 | setBounds(bounds: BrowserViewBounds): void { |
109 | this.browserView.setBounds(bounds); | 121 | this.browserView.setBounds(bounds); |
110 | } | 122 | } |
diff --git a/packages/main/src/infrastructure/electron/types.ts b/packages/main/src/infrastructure/electron/types.ts index 9f03214..63974ce 100644 --- a/packages/main/src/infrastructure/electron/types.ts +++ b/packages/main/src/infrastructure/electron/types.ts | |||
@@ -61,6 +61,10 @@ export interface ServiceView { | |||
61 | 61 | ||
62 | goForward(): void; | 62 | goForward(): void; |
63 | 63 | ||
64 | reload(ignoreCache: boolean): void; | ||
65 | |||
66 | stop(): void; | ||
67 | |||
64 | setBounds(bounds: BrowserViewBounds): void; | 68 | setBounds(bounds: BrowserViewBounds): void; |
65 | 69 | ||
66 | dispose(): void; | 70 | dispose(): void; |
diff --git a/packages/main/src/stores/MainStore.ts b/packages/main/src/stores/MainStore.ts index cb4f4c9..bf351d7 100644 --- a/packages/main/src/stores/MainStore.ts +++ b/packages/main/src/stores/MainStore.ts | |||
@@ -74,9 +74,6 @@ const MainStore = types | |||
74 | }, | 74 | }, |
75 | dispatch(action: Action): void { | 75 | dispatch(action: Action): void { |
76 | switch (action.action) { | 76 | switch (action.action) { |
77 | case 'reload-all-services': | ||
78 | // TODO | ||
79 | break; | ||
80 | case 'set-browser-view-bounds': | 77 | case 'set-browser-view-bounds': |
81 | this.setBrowserViewBounds(action.browserViewBounds); | 78 | this.setBrowserViewBounds(action.browserViewBounds); |
82 | break; | 79 | break; |
@@ -89,6 +86,24 @@ const MainStore = types | |||
89 | case 'set-show-location-bar': | 86 | case 'set-show-location-bar': |
90 | self.settings.setShowLocationBar(action.showLocationBar); | 87 | self.settings.setShowLocationBar(action.showLocationBar); |
91 | break; | 88 | break; |
89 | case 'reload-all-services': | ||
90 | // TODO | ||
91 | break; | ||
92 | case 'dispatch-service-action': { | ||
93 | const { serviceId, serviceAction } = action; | ||
94 | const service = self.shared.servicesById.get(serviceId); | ||
95 | if (service === undefined) { | ||
96 | log.error( | ||
97 | 'No such service', | ||
98 | serviceId, | ||
99 | 'to dispatch action', | ||
100 | serviceAction, | ||
101 | ); | ||
102 | } else { | ||
103 | service.dispatch(serviceAction); | ||
104 | } | ||
105 | break; | ||
106 | } | ||
92 | default: | 107 | default: |
93 | log.error('Unknown action to dispatch', action); | 108 | log.error('Unknown action to dispatch', action); |
94 | break; | 109 | break; |
diff --git a/packages/main/src/stores/Service.ts b/packages/main/src/stores/Service.ts index abef7c2..cbd8662 100644 --- a/packages/main/src/stores/Service.ts +++ b/packages/main/src/stores/Service.ts | |||
@@ -19,14 +19,17 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | import type { UnreadCount } from '@sophie/service-shared'; | 21 | import type { UnreadCount } from '@sophie/service-shared'; |
22 | import { defineServiceModel } from '@sophie/shared'; | 22 | import { defineServiceModel, ServiceAction } from '@sophie/shared'; |
23 | import { Instance, getSnapshot } from 'mobx-state-tree'; | 23 | import { Instance, getSnapshot } from 'mobx-state-tree'; |
24 | 24 | ||
25 | import type { ServiceView } from '../infrastructure/electron/types'; | 25 | import type { ServiceView } from '../infrastructure/electron/types'; |
26 | import { getLogger } from '../utils/log'; | ||
26 | 27 | ||
27 | import ServiceSettings from './ServiceSettings'; | 28 | import ServiceSettings from './ServiceSettings'; |
28 | import type ServiceConfig from './config/ServiceConfig'; | 29 | import type ServiceConfig from './config/ServiceConfig'; |
29 | 30 | ||
31 | const log = getLogger('Service'); | ||
32 | |||
30 | const Service = defineServiceModel(ServiceSettings) | 33 | const Service = defineServiceModel(ServiceSettings) |
31 | .views((self) => ({ | 34 | .views((self) => ({ |
32 | get config(): ServiceConfig { | 35 | get config(): ServiceConfig { |
@@ -87,6 +90,61 @@ const Service = defineServiceModel(ServiceSettings) | |||
87 | setServiceView(serviceView: ServiceView | undefined): void { | 90 | setServiceView(serviceView: ServiceView | undefined): void { |
88 | self.serviceView = serviceView; | 91 | self.serviceView = serviceView; |
89 | }, | 92 | }, |
93 | goBack(): void { | ||
94 | self.serviceView?.goBack(); | ||
95 | }, | ||
96 | goForward(): void { | ||
97 | self.serviceView?.goForward(); | ||
98 | }, | ||
99 | reload(ignoreCache = false): void { | ||
100 | if (self.serviceView === undefined) { | ||
101 | this.startedLoading(); | ||
102 | } else { | ||
103 | self.serviceView?.reload(ignoreCache); | ||
104 | } | ||
105 | }, | ||
106 | stop(): void { | ||
107 | self.serviceView?.stop(); | ||
108 | }, | ||
109 | go(url: string): void { | ||
110 | if (self.serviceView === undefined) { | ||
111 | self.currentUrl = url; | ||
112 | this.startedLoading(); | ||
113 | } else { | ||
114 | self.serviceView?.loadURL(url).catch((error) => { | ||
115 | log.warn('Error while loading', url, error); | ||
116 | this.crashed(); | ||
117 | }); | ||
118 | } | ||
119 | }, | ||
120 | goHome(): void { | ||
121 | this.go(self.settings.url); | ||
122 | }, | ||
123 | dispatch(action: ServiceAction): void { | ||
124 | switch (action.action) { | ||
125 | case 'back': | ||
126 | this.goBack(); | ||
127 | break; | ||
128 | case 'forward': | ||
129 | this.goForward(); | ||
130 | break; | ||
131 | case 'reload': | ||
132 | this.reload(action.ignoreCache); | ||
133 | break; | ||
134 | case 'stop': | ||
135 | this.stop(); | ||
136 | break; | ||
137 | case 'go-home': | ||
138 | this.goHome(); | ||
139 | break; | ||
140 | case 'go': | ||
141 | this.go(action.url); | ||
142 | break; | ||
143 | default: | ||
144 | log.error('Unknown action to dispatch', action); | ||
145 | break; | ||
146 | } | ||
147 | }, | ||
90 | })); | 148 | })); |
91 | 149 | ||
92 | /* | 150 | /* |