From d425435c290a7e63c4e30a469da51f43be4db5cc Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 15 Mar 2022 00:15:31 +0100 Subject: feat: Open in external browser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kristóf Marussy --- .../src/components/locationBar/ExtraButtons.tsx | 52 ++++++++++++++++++++++ .../src/components/locationBar/LocationBar.tsx | 2 + .../components/locationBar/NavigationButtons.tsx | 2 +- packages/renderer/src/env/RendererEnv.ts | 25 ----------- packages/renderer/src/env/getEnv.ts | 34 -------------- packages/renderer/src/stores/GlobalSettings.ts | 3 +- packages/renderer/src/stores/RendererEnv.ts | 37 +++++++++++++++ packages/renderer/src/stores/RendererStore.ts | 3 +- packages/renderer/src/stores/Service.ts | 8 +++- 9 files changed, 100 insertions(+), 66 deletions(-) create mode 100644 packages/renderer/src/components/locationBar/ExtraButtons.tsx delete mode 100644 packages/renderer/src/env/RendererEnv.ts delete mode 100644 packages/renderer/src/env/getEnv.ts create mode 100644 packages/renderer/src/stores/RendererEnv.ts (limited to 'packages/renderer') diff --git a/packages/renderer/src/components/locationBar/ExtraButtons.tsx b/packages/renderer/src/components/locationBar/ExtraButtons.tsx new file mode 100644 index 0000000..4eaee29 --- /dev/null +++ b/packages/renderer/src/components/locationBar/ExtraButtons.tsx @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 Kristóf Marussy + * + * This file is part of Sophie. + * + * Sophie is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import IconOpenInBrowser from '@mui/icons-material/OpenInBrowser'; +import Box from '@mui/material/Box'; +import IconButton from '@mui/material/IconButton'; +import { observer } from 'mobx-react-lite'; +import React from 'react'; + +import type Service from '../../stores/Service'; + +function ExtraButtons({ + service, +}: { + service: Service | undefined; +}): JSX.Element { + return ( + + service?.openCurrentURLInExternalBrowser()} + > + + + + ); +} + +export default observer(ExtraButtons); diff --git a/packages/renderer/src/components/locationBar/LocationBar.tsx b/packages/renderer/src/components/locationBar/LocationBar.tsx index 0debaab..fc9c147 100644 --- a/packages/renderer/src/components/locationBar/LocationBar.tsx +++ b/packages/renderer/src/components/locationBar/LocationBar.tsx @@ -24,6 +24,7 @@ import React from 'react'; import { useStore } from '../StoreProvider'; +import ExtraButtons from './ExtraButtons'; import LocationTextField from './LocationTextField'; import NavigationButtons from './NavigationButtons'; @@ -49,6 +50,7 @@ function LocationBar(): JSX.Element { ); } diff --git a/packages/renderer/src/components/locationBar/NavigationButtons.tsx b/packages/renderer/src/components/locationBar/NavigationButtons.tsx index 5c5c959..9995a21 100644 --- a/packages/renderer/src/components/locationBar/NavigationButtons.tsx +++ b/packages/renderer/src/components/locationBar/NavigationButtons.tsx @@ -29,7 +29,7 @@ import IconButton from '@mui/material/IconButton'; import { observer } from 'mobx-react-lite'; import React from 'react'; -import Service from '../../stores/Service'; +import type Service from '../../stores/Service'; function NavigationButtons({ service, diff --git a/packages/renderer/src/env/RendererEnv.ts b/packages/renderer/src/env/RendererEnv.ts deleted file mode 100644 index ba4c43e..0000000 --- a/packages/renderer/src/env/RendererEnv.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2021-2022 Kristóf Marussy - * - * This file is part of Sophie. - * - * Sophie is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * SPDX-License-Identifier: AGPL-3.0-only - */ - -import type { Action } from '@sophie/shared'; - -export default interface RendererEnv { - dispatchMainAction(action: Action): void; -} diff --git a/packages/renderer/src/env/getEnv.ts b/packages/renderer/src/env/getEnv.ts deleted file mode 100644 index 4f7357a..0000000 --- a/packages/renderer/src/env/getEnv.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2022 Kristóf Marussy - * - * This file is part of Sophie. - * - * Sophie is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * SPDX-License-Identifier: AGPL-3.0-only - */ - -import { getEnv as getAnyEnv, IAnyStateTreeNode } from 'mobx-state-tree'; - -import type RendererEnv from './RendererEnv'; - -/** - * Gets a well-typed environment from `model`. - * - * Only useable inside state trees created by `createAndConnectRootStore`. - * - * @param model The state tree node. - */ -export default function getEnv(model: IAnyStateTreeNode): RendererEnv { - return getAnyEnv(model); -} diff --git a/packages/renderer/src/stores/GlobalSettings.ts b/packages/renderer/src/stores/GlobalSettings.ts index 79815ba..52971d4 100644 --- a/packages/renderer/src/stores/GlobalSettings.ts +++ b/packages/renderer/src/stores/GlobalSettings.ts @@ -21,8 +21,7 @@ import { defineGlobalSettingsModel, ThemeSource } from '@sophie/shared'; import { Instance } from 'mobx-state-tree'; -import getEnv from '../env/getEnv'; - +import { getEnv } from './RendererEnv'; import Service from './Service'; const GlobalSettings = defineGlobalSettingsModel(Service).actions((self) => ({ diff --git a/packages/renderer/src/stores/RendererEnv.ts b/packages/renderer/src/stores/RendererEnv.ts new file mode 100644 index 0000000..496ede6 --- /dev/null +++ b/packages/renderer/src/stores/RendererEnv.ts @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021-2022 Kristóf Marussy + * + * This file is part of Sophie. + * + * Sophie is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import type { Action } from '@sophie/shared'; +import { getEnv as getAnyEnv, IAnyStateTreeNode } from 'mobx-state-tree'; + +/** + * Gets a well-typed environment from `model`. + * + * Only useable inside state trees created by `createAndConnectRootStore`. + * + * @param model The state tree node. + */ +export function getEnv(model: IAnyStateTreeNode): RendererEnv { + return getAnyEnv(model); +} + +export default interface RendererEnv { + dispatchMainAction(action: Action): void; +} diff --git a/packages/renderer/src/stores/RendererStore.ts b/packages/renderer/src/stores/RendererStore.ts index 8f424f6..f48d484 100644 --- a/packages/renderer/src/stores/RendererStore.ts +++ b/packages/renderer/src/stores/RendererStore.ts @@ -21,11 +21,10 @@ import { BrowserViewBounds, SophieRenderer } from '@sophie/shared'; import { applySnapshot, applyPatch, Instance, types } from 'mobx-state-tree'; -import RendererEnv from '../env/RendererEnv'; -import getEnv from '../env/getEnv'; import { getLogger } from '../utils/log'; import GlobalSettings from './GlobalSettings'; +import RendererEnv, { getEnv } from './RendererEnv'; import Service from './Service'; import SharedStore from './SharedStore'; diff --git a/packages/renderer/src/stores/Service.ts b/packages/renderer/src/stores/Service.ts index 695cff4..c50e5bd 100644 --- a/packages/renderer/src/stores/Service.ts +++ b/packages/renderer/src/stores/Service.ts @@ -21,8 +21,7 @@ import { defineServiceModel, ServiceAction } from '@sophie/shared'; import { Instance } from 'mobx-state-tree'; -import getEnv from '../env/getEnv'; - +import { getEnv } from './RendererEnv'; import ServiceSettings from './ServiceSettings'; const Service = defineServiceModel(ServiceSettings).actions((self) => { @@ -76,6 +75,11 @@ const Service = defineServiceModel(ServiceSettings).actions((self) => { fingerprint: self.state.certificate.fingerprint, }); }, + openCurrentURLInExternalBrowser(): void { + dispatch({ + action: 'open-current-url-in-external-browser', + }); + }, }; }); -- cgit v1.2.3-54-g00ecf