From 098d6f9bb1fd26f2d192db497992ab95b258ce55 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sun, 27 Feb 2022 01:52:55 +0100 Subject: feat: Location bar actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The buttons and the text field in the location bar shall now affect the BrowserView of the loaded service. Some error handling is still needed, e.g., when loading a web page fails due to a DNS error. Signed-off-by: Kristóf Marussy --- packages/renderer/src/stores/Service.ts | 46 +++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'packages/renderer/src/stores/Service.ts') diff --git a/packages/renderer/src/stores/Service.ts b/packages/renderer/src/stores/Service.ts index c2c938a..7878ea0 100644 --- a/packages/renderer/src/stores/Service.ts +++ b/packages/renderer/src/stores/Service.ts @@ -18,12 +18,54 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { defineServiceModel } from '@sophie/shared'; +import { defineServiceModel, ServiceAction } from '@sophie/shared'; import { Instance } from 'mobx-state-tree'; +import getEnv from '../env/getEnv'; + import ServiceSettings from './ServiceSettings'; -const Service = defineServiceModel(ServiceSettings); +const Service = defineServiceModel(ServiceSettings).actions((self) => ({ + dispatch(serviceAction: ServiceAction): void { + getEnv(self).dispatchMainAction({ + action: 'dispatch-service-action', + serviceId: self.id, + serviceAction, + }); + }, + goBack(): void { + this.dispatch({ + action: 'back', + }); + }, + goForward(): void { + this.dispatch({ + action: 'forward', + }); + }, + reload(ignoreCache = false): void { + this.dispatch({ + action: 'reload', + ignoreCache, + }); + }, + stop(): void { + this.dispatch({ + action: 'stop', + }); + }, + go(url: string): void { + this.dispatch({ + action: 'go', + url, + }); + }, + goHome(): void { + this.dispatch({ + action: 'go-home', + }); + }, +})); /* eslint-disable-next-line @typescript-eslint/no-redeclare -- -- cgit v1.2.3-54-g00ecf