aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/stores/Service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/stores/Service.ts')
-rw-r--r--packages/main/src/stores/Service.ts26
1 files changed, 25 insertions, 1 deletions
diff --git a/packages/main/src/stores/Service.ts b/packages/main/src/stores/Service.ts
index 1d46dc9..8ba8098 100644
--- a/packages/main/src/stores/Service.ts
+++ b/packages/main/src/stores/Service.ts
@@ -25,6 +25,7 @@ import {
25 defineServiceModel, 25 defineServiceModel,
26 ServiceAction, 26 ServiceAction,
27 type ServiceStateSnapshotIn, 27 type ServiceStateSnapshotIn,
28 type BrowserViewBounds,
28} from '@sophie/shared'; 29} from '@sophie/shared';
29import { type Instance, getSnapshot, cast, flow } from 'mobx-state-tree'; 30import { type Instance, getSnapshot, cast, flow } from 'mobx-state-tree';
30 31
@@ -41,8 +42,18 @@ const Service = defineServiceModel(ServiceSettings)
41 .volatile( 42 .volatile(
42 (): { 43 (): {
43 serviceView: ServiceView | undefined; 44 serviceView: ServiceView | undefined;
45 x: number;
46 y: number;
47 width: number;
48 height: number;
49 hasBounds: boolean;
44 } => ({ 50 } => ({
45 serviceView: undefined, 51 serviceView: undefined,
52 x: 0,
53 y: 0,
54 width: 0,
55 height: 0,
56 hasBounds: false,
46 }), 57 }),
47 ) 58 )
48 .views((self) => ({ 59 .views((self) => ({
@@ -59,10 +70,20 @@ const Service = defineServiceModel(ServiceSettings)
59 })) 70 }))
60 .views((self) => ({ 71 .views((self) => ({
61 get shouldBeVisible(): boolean { 72 get shouldBeVisible(): boolean {
62 return self.shouldBeLoaded && !self.hasError; 73 // Do not attach service views for which we don't know the appropriate frame size,
74 // because they will just appear in a random location until the frame size is determined.
75 return self.shouldBeLoaded && !self.hasError && self.hasBounds;
63 }, 76 },
64 })) 77 }))
65 .actions((self) => ({ 78 .actions((self) => ({
79 setBrowserViewBounds(bounds: BrowserViewBounds): void {
80 self.x = bounds.x;
81 self.y = bounds.y;
82 self.width = bounds.width;
83 self.height = bounds.height;
84 self.hasBounds = true;
85 self.serviceView?.updateBounds();
86 },
66 setServiceView(serviceView: ServiceView | undefined): void { 87 setServiceView(serviceView: ServiceView | undefined): void {
67 self.serviceView = serviceView; 88 self.serviceView = serviceView;
68 }, 89 },
@@ -263,6 +284,9 @@ const Service = defineServiceModel(ServiceSettings)
263 .actions((self) => ({ 284 .actions((self) => ({
264 dispatch(action: ServiceAction): void { 285 dispatch(action: ServiceAction): void {
265 switch (action.action) { 286 switch (action.action) {
287 case 'set-browser-view-bounds':
288 self.setBrowserViewBounds(action.browserViewBounds);
289 break;
266 case 'back': 290 case 'back':
267 self.goBack(); 291 self.goBack();
268 break; 292 break;