Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disables external plugin download ui on web app and shows a message. … #2855

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/ui-services/src/UseCase/IsWebApp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
import { Environment } from '@standardnotes/models'

export class IsWebApp implements SyncUseCaseInterface<boolean> {
constructor(private environment: Environment) {}

execute(): Result<boolean> {
return Result.ok(this.environment === Environment.Web)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface WebApplicationInterface extends ApplicationInterface {
handleReceivedLinkEvent(item: { link: string; title: string }): Promise<void>
handleOpenFilePreviewEvent(item: { id: string }): void
isNativeMobileWeb(): boolean
isWebApp(): boolean
handleAndroidBackButtonPressed(): void
addAndroidBackHandlerEventListener(listener: () => boolean): (() => void) | undefined
setAndroidBackHandlerFallbackListener(listener: () => boolean): void
Expand Down
1 change: 1 addition & 0 deletions packages/ui-services/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IsMobileDevice,
IsNativeIOS,
IsNativeMobileWeb,
IsWebApp,
KeyboardService,
PluginsService,
RouteService,
Expand Down Expand Up @@ -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)
})
Expand Down
5 changes: 5 additions & 0 deletions packages/web/src/javascripts/Application/WebApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
IsMobileDevice,
IsNativeIOS,
IsNativeMobileWeb,
IsWebApp,
KeyboardService,
PluginsServiceInterface,
RouteServiceInterface,
Expand Down Expand Up @@ -675,4 +676,8 @@ export class WebApplication extends SNApplication implements WebApplicationInter
get isNativeMobileWebUseCase(): IsNativeMobileWeb {
return this.deps.get<IsNativeMobileWeb>(Web_TYPES.IsNativeMobileWeb)
}

get isWebAppUseCase(): IsWebApp {
return this.deps.get<IsWebApp>(Web_TYPES.IsWebApp)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const InstallCustomPlugin: FunctionComponent<Props> = ({ className = '' }) => {

const confirmableEnd = useRef<HTMLDivElement>(null)

const isWebApp = useState(application.isWebApp());

useEffect(() => {
if (confirmablePlugin) {
confirmableEnd.current?.scrollIntoView({ behavior: 'smooth' })
Expand Down Expand Up @@ -47,7 +49,8 @@ const InstallCustomPlugin: FunctionComponent<Props> = ({ className = '' }) => {
<PreferencesSegment>
<div>
<DecoratedInput
placeholder={'Enter Plugin URL'}
disabled = {isWebApp}
placeholder={(isWebApp) ? 'Web App External Plugin Downloads Not Supported' : 'Enter Plugin URL'}
value={customUrl}
onChange={(value) => {
setCustomUrl(value)
Expand All @@ -56,7 +59,7 @@ const InstallCustomPlugin: FunctionComponent<Props> = ({ className = '' }) => {
</div>
<Button
hidden={customUrl.length === 0}
disabled={customUrl.length === 0}
disabled={customUrl.length === 0 || isWebApp}
className="mt-4 min-w-20"
primary
label="Install"
Expand Down