From 2dac3328f82176b867426d8f2a100337f9d7da5b Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 2 Mar 2024 18:32:46 -0700 Subject: [PATCH] Disables external plugin download ui on web app and shows a message. Untested --- packages/ui-services/src/UseCase/IsWebApp.ts | 10 ++++++++++ .../src/WebApplication/WebApplicationInterface.ts | 1 + packages/ui-services/src/index.ts | 1 + .../src/javascripts/Application/Dependencies/Types.ts | 1 + .../Application/Dependencies/WebDependencies.ts | 5 +++++ .../web/src/javascripts/Application/WebApplication.ts | 5 +++++ .../Plugins/InstallCustom/InstallCustomPlugin.tsx | 7 +++++-- 7 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 packages/ui-services/src/UseCase/IsWebApp.ts diff --git a/packages/ui-services/src/UseCase/IsWebApp.ts b/packages/ui-services/src/UseCase/IsWebApp.ts new file mode 100644 index 00000000000..329e4ef80e9 --- /dev/null +++ b/packages/ui-services/src/UseCase/IsWebApp.ts @@ -0,0 +1,10 @@ +import { Result, SyncUseCaseInterface } from '@standardnotes/domain-core' +import { Environment } from '@standardnotes/models' + +export class IsWebApp implements SyncUseCaseInterface { + constructor(private environment: Environment) {} + + execute(): Result { + return Result.ok(this.environment === Environment.Web) + } +} diff --git a/packages/ui-services/src/WebApplication/WebApplicationInterface.ts b/packages/ui-services/src/WebApplication/WebApplicationInterface.ts index f232d13a59f..0078a6c9645 100644 --- a/packages/ui-services/src/WebApplication/WebApplicationInterface.ts +++ b/packages/ui-services/src/WebApplication/WebApplicationInterface.ts @@ -26,6 +26,7 @@ export interface WebApplicationInterface extends ApplicationInterface { handleReceivedLinkEvent(item: { link: string; title: string }): Promise handleOpenFilePreviewEvent(item: { id: string }): void isNativeMobileWeb(): boolean + isWebApp(): boolean handleAndroidBackButtonPressed(): void addAndroidBackHandlerEventListener(listener: () => boolean): (() => void) | undefined setAndroidBackHandlerFallbackListener(listener: () => boolean): void diff --git a/packages/ui-services/src/index.ts b/packages/ui-services/src/index.ts index ed05b5614cf..dc9a1d41343 100644 --- a/packages/ui-services/src/index.ts +++ b/packages/ui-services/src/index.ts @@ -37,6 +37,7 @@ export * from './UseCase/IsGlobalSpellcheckEnabled' export * from './UseCase/IsNativeMobileWeb' export * from './UseCase/IsMobileDevice' export * from './UseCase/IsNativeIOS' +export * from './UseCase/IsWebApp' export * from './UseCase/GetItemTags' export * from './Theme/ThemeManager' diff --git a/packages/web/src/javascripts/Application/Dependencies/Types.ts b/packages/web/src/javascripts/Application/Dependencies/Types.ts index 12cb179f85a..0fed71dd3fc 100644 --- a/packages/web/src/javascripts/Application/Dependencies/Types.ts +++ b/packages/web/src/javascripts/Application/Dependencies/Types.ts @@ -48,6 +48,7 @@ export const Web_TYPES = { IsMobileDevice: Symbol.for('IsMobileDevice'), IsNativeIOS: Symbol.for('IsNativeIOS'), IsNativeMobileWeb: Symbol.for('IsNativeMobileWeb'), + IsWebApp: Symbol.for('IsWebApp'), IsTabletOrMobileScreen: Symbol.for('IsTabletOrMobileScreen'), LoadPurchaseFlowUrl: Symbol.for('LoadPurchaseFlowUrl'), OpenSubscriptionDashboard: Symbol.for('OpenSubscriptionDashboard'), diff --git a/packages/web/src/javascripts/Application/Dependencies/WebDependencies.ts b/packages/web/src/javascripts/Application/Dependencies/WebDependencies.ts index 8d2ba4b8074..4a541083b31 100644 --- a/packages/web/src/javascripts/Application/Dependencies/WebDependencies.ts +++ b/packages/web/src/javascripts/Application/Dependencies/WebDependencies.ts @@ -8,6 +8,7 @@ import { IsMobileDevice, IsNativeIOS, IsNativeMobileWeb, + IsWebApp, KeyboardService, PluginsService, RouteService, @@ -84,6 +85,10 @@ export class WebDependencies extends DependencyContainer { return new IsNativeMobileWeb(application.environment) }) + this.bind(Web_TYPES.IsWebApp, () => { + return new IsWebApp(application.environment) + }) + this.bind(Web_TYPES.IsGlobalSpellcheckEnabled, () => { return new IsGlobalSpellcheckEnabled(application.preferences) }) diff --git a/packages/web/src/javascripts/Application/WebApplication.ts b/packages/web/src/javascripts/Application/WebApplication.ts index 3b2d380e5a9..7576fd9fb64 100644 --- a/packages/web/src/javascripts/Application/WebApplication.ts +++ b/packages/web/src/javascripts/Application/WebApplication.ts @@ -37,6 +37,7 @@ import { IsMobileDevice, IsNativeIOS, IsNativeMobileWeb, + IsWebApp, KeyboardService, PluginsServiceInterface, RouteServiceInterface, @@ -675,4 +676,8 @@ export class WebApplication extends SNApplication implements WebApplicationInter get isNativeMobileWebUseCase(): IsNativeMobileWeb { return this.deps.get(Web_TYPES.IsNativeMobileWeb) } + + get isWebAppUseCase(): IsWebApp { + return this.deps.get(Web_TYPES.IsWebApp) + } } diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/Plugins/InstallCustom/InstallCustomPlugin.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/Plugins/InstallCustom/InstallCustomPlugin.tsx index 7df79f760fa..9abcb99cf24 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/Plugins/InstallCustom/InstallCustomPlugin.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/Plugins/InstallCustom/InstallCustomPlugin.tsx @@ -19,6 +19,8 @@ const InstallCustomPlugin: FunctionComponent = ({ className = '' }) => { const confirmableEnd = useRef(null) + const isWebApp = useState(application.isWebApp()); + useEffect(() => { if (confirmablePlugin) { confirmableEnd.current?.scrollIntoView({ behavior: 'smooth' }) @@ -47,7 +49,8 @@ const InstallCustomPlugin: FunctionComponent = ({ className = '' }) => {
{ setCustomUrl(value) @@ -56,7 +59,7 @@ const InstallCustomPlugin: FunctionComponent = ({ className = '' }) => {