Files
standardnotes-app/packages/web/src/javascripts/App.tsx
T
d7aca2c13a feat: mobile security prefs (#1496)
* feat: move mobile-specific security items to Web when rendered in WebView

* feat: better UI for biometrics section

* feat: move Multitasking Privacy section to WebView (mostly UI)

* feat: move Multitasking Privacy section to WebView (going to understand why in WebView multitasking privacy value is auto-changed after reopening the WebView)

* feat: store MultitaskingPrivacy value as "NonWrapped" so that it's the same both on mobile and WebView

* feat: open WebView correctly when "Storage Encryption" is disabled on mobile

* fix: remove unnecessary changes and comments

* chore: revert ios-related unneeded changes

* fix: let Android to correctly recognize the NativeMobileWeb environment when opening WebView on Android

* fix: correct styles for the selected state of Biometrics/Passcode options

* chore: code cleanup

* fix: store Multitasking/Screenshot Privacy in the `Default` storage value mode

* chore: remove comment

* fix: use application's method instead of directly updating Screenshot Privacy preference

* fix: remove unused variable

* fix: use methods from Application and MobileDeviceInterface in all places, remove duplicate code

* fix: hide Multitasking Privacy and Biometrics Lock in WebView

Co-authored-by: Aman Harwara
2022-09-14 13:07:10 +04:00

109 lines
3.2 KiB
TypeScript

'use strict'
import { disableIosTextFieldZoom } from '@/Utils'
declare global {
interface Window {
dashboardUrl?: string
defaultSyncServer: string
devAccountEmail?: string
devAccountPassword?: string
devAccountServer?: string
enabledUnfinishedFeatures: boolean
plansUrl?: string
purchaseUrl?: string
startApplication?: StartApplication
websocketUrl: string
electronAppVersion?: string
webClient?: DesktopManagerInterface
electronRemoteBridge?: unknown
reactNativeDevice?: WebDevice
application?: WebApplication
mainApplicationGroup?: ApplicationGroup
MSStream?: Record<string, unknown>
}
}
import { IsWebPlatform, WebAppVersion } from '@/Constants/Version'
import { DesktopManagerInterface, SNLog } from '@standardnotes/snjs'
import ApplicationGroupView from './Components/ApplicationGroupView/ApplicationGroupView'
import { WebDevice } from './Application/Device/WebDevice'
import { StartApplication } from './Application/Device/StartApplication'
import { ApplicationGroup } from './Application/ApplicationGroup'
import { WebOrDesktopDevice } from './Application/Device/WebOrDesktopDevice'
import { WebApplication } from './Application/Application'
import { createRoot, Root } from 'react-dom/client'
import { ElementIds } from './Constants/ElementIDs'
let keyCount = 0
const getKey = () => {
return keyCount++
}
const startApplication: StartApplication = async function startApplication(
defaultSyncServerHost: string,
device: WebOrDesktopDevice,
enableUnfinishedFeatures: boolean,
webSocketUrl: string,
) {
// eslint-disable-next-line no-console
SNLog.onLog = console.log
SNLog.onError = console.error
let root: Root
const onDestroy = () => {
const rootElement = document.getElementById(ElementIds.RootId) as HTMLElement
root.unmount()
rootElement.remove()
renderApp()
}
const renderApp = () => {
const rootElement = document.createElement('div')
rootElement.id = ElementIds.RootId
const appendedRootNode = document.body.appendChild(rootElement)
root = createRoot(appendedRootNode)
disableIosTextFieldZoom()
document.documentElement.style.setProperty('--viewport-height', `${window.innerHeight}px`)
root.render(
<ApplicationGroupView
key={getKey()}
server={defaultSyncServerHost}
device={device}
enableUnfinished={enableUnfinishedFeatures}
websocketUrl={webSocketUrl}
onDestroy={onDestroy}
/>,
)
}
const domReady = document.readyState === 'complete' || document.readyState === 'interactive'
if (domReady) {
renderApp()
} else {
window.addEventListener('DOMContentLoaded', function callback() {
renderApp()
window.removeEventListener('DOMContentLoaded', callback)
})
}
}
if (IsWebPlatform) {
const ReactNativeWebViewInitializationTimeout = 0
setTimeout(() => {
const device = window.reactNativeDevice || new WebDevice(WebAppVersion)
startApplication(window.defaultSyncServer, device, window.enabledUnfinishedFeatures, window.websocketUrl).catch(
console.error,
)
}, ReactNativeWebViewInitializationTimeout)
} else {
window.startApplication = startApplication
}