aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/stores/Service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/renderer/src/stores/Service.ts')
-rw-r--r--packages/renderer/src/stores/Service.ts190
1 files changed, 108 insertions, 82 deletions
diff --git a/packages/renderer/src/stores/Service.ts b/packages/renderer/src/stores/Service.ts
index e14d80b..4510ec0 100644
--- a/packages/renderer/src/stores/Service.ts
+++ b/packages/renderer/src/stores/Service.ts
@@ -24,92 +24,118 @@ import { Instance } from 'mobx-state-tree';
24import { getEnv } from './RendererEnv'; 24import { getEnv } from './RendererEnv';
25import ServiceSettings from './ServiceSettings'; 25import ServiceSettings from './ServiceSettings';
26 26
27const Service = defineServiceModel(ServiceSettings).actions((self) => { 27const Service = defineServiceModel(ServiceSettings)
28 function dispatch(serviceAction: ServiceAction): void { 28 .views((self) => ({
29 getEnv(self).dispatchMainAction({ 29 get canReconnectSecurely(): boolean {
30 action: 'dispatch-service-action', 30 const { currentUrl } = self;
31 serviceId: self.id, 31 if (currentUrl === undefined) {
32 serviceAction, 32 return false;
33 }); 33 }
34 } 34 try {
35 35 const { protocol } = new URL(currentUrl);
36 return { 36 return protocol === 'http:';
37 goBack(): void { 37 } catch {
38 dispatch({ 38 return false;
39 action: 'back',
40 });
41 },
42 goForward(): void {
43 dispatch({
44 action: 'forward',
45 });
46 },
47 reload(ignoreCache = false): void {
48 dispatch({
49 action: 'reload',
50 ignoreCache,
51 });
52 },
53 stop(): void {
54 dispatch({
55 action: 'stop',
56 });
57 },
58 go(url: string): void {
59 dispatch({
60 action: 'go',
61 url,
62 });
63 },
64 goHome(): void {
65 dispatch({
66 action: 'go-home',
67 });
68 },
69 temporarilyTrustCurrentCertificate(): void {
70 if (self.state.type !== 'certificateError') {
71 throw new Error('No certificate to accept');
72 } 39 }
73 dispatch({
74 action: 'temporarily-trust-current-certificate',
75 fingerprint: self.state.certificate.fingerprint,
76 });
77 },
78 openCurrentURLInExternalBrowser(): void {
79 dispatch({
80 action: 'open-current-url-in-external-browser',
81 });
82 },
83 followPopup(url: string): void {
84 dispatch({
85 action: 'follow-popup',
86 url,
87 });
88 },
89 openPopupInExternalBrowser(url: string): void {
90 dispatch({
91 action: 'open-popup-in-external-browser',
92 url,
93 });
94 },
95 openAllPopupsInExternalBrowser(): void {
96 dispatch({
97 action: 'open-all-popups-in-external-browser',
98 });
99 },
100 dismissPopup(url: string): void {
101 dispatch({
102 action: 'dismiss-popup',
103 url,
104 });
105 }, 40 },
106 dismissAllPopups(): void { 41 }))
107 dispatch({ 42 .actions((self) => {
108 action: 'dismiss-all-popups', 43 function dispatch(serviceAction: ServiceAction): void {
44 getEnv(self).dispatchMainAction({
45 action: 'dispatch-service-action',
46 serviceId: self.id,
47 serviceAction,
109 }); 48 });
49 }
50
51 return {
52 goBack(): void {
53 dispatch({
54 action: 'back',
55 });
56 },
57 goForward(): void {
58 dispatch({
59 action: 'forward',
60 });
61 },
62 reload(ignoreCache = false): void {
63 dispatch({
64 action: 'reload',
65 ignoreCache,
66 });
67 },
68 stop(): void {
69 dispatch({
70 action: 'stop',
71 });
72 },
73 go(url: string): void {
74 dispatch({
75 action: 'go',
76 url,
77 });
78 },
79 goHome(): void {
80 dispatch({
81 action: 'go-home',
82 });
83 },
84 temporarilyTrustCurrentCertificate(): void {
85 if (self.state.type !== 'certificateError') {
86 throw new Error('No certificate to accept');
87 }
88 dispatch({
89 action: 'temporarily-trust-current-certificate',
90 fingerprint: self.state.certificate.fingerprint,
91 });
92 },
93 openCurrentURLInExternalBrowser(): void {
94 dispatch({
95 action: 'open-current-url-in-external-browser',
96 });
97 },
98 followPopup(url: string): void {
99 dispatch({
100 action: 'follow-popup',
101 url,
102 });
103 },
104 openPopupInExternalBrowser(url: string): void {
105 dispatch({
106 action: 'open-popup-in-external-browser',
107 url,
108 });
109 },
110 openAllPopupsInExternalBrowser(): void {
111 dispatch({
112 action: 'open-all-popups-in-external-browser',
113 });
114 },
115 dismissPopup(url: string): void {
116 dispatch({
117 action: 'dismiss-popup',
118 url,
119 });
120 },
121 dismissAllPopups(): void {
122 dispatch({
123 action: 'dismiss-all-popups',
124 });
125 },
126 };
127 })
128 .actions((self) => ({
129 reconnectSecurely(): void {
130 const { currentUrl, canReconnectSecurely } = self;
131 if (currentUrl === undefined || !canReconnectSecurely) {
132 return;
133 }
134 const url = new URL(currentUrl);
135 url.protocol = 'https:';
136 self.go(url.toString());
110 }, 137 },
111 }; 138 }));
112});
113 139
114/* 140/*
115 eslint-disable-next-line @typescript-eslint/no-redeclare -- 141 eslint-disable-next-line @typescript-eslint/no-redeclare --