fix: screenshot privacy setting not working on app relaunch (#1900)

This commit is contained in:
Aman Harwara
2022-10-28 19:31:15 +05:30
committed by GitHub
parent 9ac5bd0c27
commit 5a6f4fb35c
5 changed files with 34 additions and 0 deletions

View File

@@ -220,10 +220,12 @@ export class MobileDevice implements MobileDeviceInterface {
hideMobileInterfaceFromScreenshots(): void { hideMobileInterfaceFromScreenshots(): void {
hide() hide()
this.setAndroidScreenshotPrivacy(true)
} }
stopHidingMobileInterfaceFromScreenshots(): void { stopHidingMobileInterfaceFromScreenshots(): void {
show() show()
this.setAndroidScreenshotPrivacy(false)
} }
async getAllRawStorageKeyValues() { async getAllRawStorageKeyValues() {

View File

@@ -261,6 +261,14 @@ export class WebApplication extends SNApplication implements WebApplicationInter
setViewportHeightWithFallback() setViewportHeightWithFallback()
} }
handleInitialMobileScreenshotPrivacy(): void {
if (this.protections.getMobileScreenshotPrivacyEnabled()) {
this.mobileDevice().hideMobileInterfaceFromScreenshots()
} else {
this.mobileDevice().stopHidingMobileInterfaceFromScreenshots()
}
}
async handleMobileLosingFocusEvent(): Promise<void> { async handleMobileLosingFocusEvent(): Promise<void> {
if (this.protections.getMobileScreenshotPrivacyEnabled()) { if (this.protections.getMobileScreenshotPrivacyEnabled()) {
this.mobileDevice().stopHidingMobileInterfaceFromScreenshots() this.mobileDevice().stopHidingMobileInterfaceFromScreenshots()

View File

@@ -150,6 +150,7 @@ export class ViewControllerManager implements InternalEventHandlerInterface {
this.toastService = new ToastService() this.toastService = new ToastService()
this.applicationEventObserver = new ApplicationEventObserver( this.applicationEventObserver = new ApplicationEventObserver(
application,
application.routeService, application.routeService,
this.purchaseFlowController, this.purchaseFlowController,
this.accountMenuController, this.accountMenuController,

View File

@@ -26,8 +26,10 @@ import { SyncStatusController } from '@/Controllers/SyncStatusController'
import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenuPane' import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenuPane'
import { ApplicationEventObserver } from './ApplicationEventObserver' import { ApplicationEventObserver } from './ApplicationEventObserver'
import { WebApplication } from '@/Application/Application'
describe('ApplicationEventObserver', () => { describe('ApplicationEventObserver', () => {
let application: WebApplication
let routeService: RouteServiceInterface let routeService: RouteServiceInterface
let purchaseFlowController: PurchaseFlowController let purchaseFlowController: PurchaseFlowController
let accountMenuController: AccountMenuController let accountMenuController: AccountMenuController
@@ -40,6 +42,7 @@ describe('ApplicationEventObserver', () => {
const createObserver = () => const createObserver = () =>
new ApplicationEventObserver( new ApplicationEventObserver(
application,
routeService, routeService,
purchaseFlowController, purchaseFlowController,
accountMenuController, accountMenuController,
@@ -52,6 +55,8 @@ describe('ApplicationEventObserver', () => {
) )
beforeEach(() => { beforeEach(() => {
application = {} as jest.Mocked<WebApplication>
routeService = {} as jest.Mocked<RouteServiceInterface> routeService = {} as jest.Mocked<RouteServiceInterface>
routeService.getRoute = jest.fn().mockReturnValue({ routeService.getRoute = jest.fn().mockReturnValue({
type: RouteType.None, type: RouteType.None,
@@ -223,4 +228,15 @@ describe('ApplicationEventObserver', () => {
expect(syncStatusController.update).toHaveBeenCalled() expect(syncStatusController.update).toHaveBeenCalled()
}) })
}) })
describe('Upon Database Loaded', () => {
it('should handle mobile screenshot privacy setting', async () => {
application.isNativeMobileWeb = jest.fn().mockReturnValue(true)
application.handleInitialMobileScreenshotPrivacy = jest.fn()
await createObserver().handle(ApplicationEvent.LocalDataLoaded)
expect(application.handleInitialMobileScreenshotPrivacy).toHaveBeenCalled()
})
})
}) })

View File

@@ -20,9 +20,11 @@ import { SyncStatusController } from '@/Controllers/SyncStatusController'
import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenuPane' import { AccountMenuPane } from '@/Components/AccountMenu/AccountMenuPane'
import { EventObserverInterface } from './EventObserverInterface' import { EventObserverInterface } from './EventObserverInterface'
import { WebApplication } from '@/Application/Application'
export class ApplicationEventObserver implements EventObserverInterface { export class ApplicationEventObserver implements EventObserverInterface {
constructor( constructor(
private application: WebApplication,
private routeService: RouteServiceInterface, private routeService: RouteServiceInterface,
private purchaseFlowController: PurchaseFlowController, private purchaseFlowController: PurchaseFlowController,
private accountMenuController: AccountMenuController, private accountMenuController: AccountMenuController,
@@ -89,6 +91,11 @@ export class ApplicationEventObserver implements EventObserverInterface {
case ApplicationEvent.SyncStatusChanged: case ApplicationEvent.SyncStatusChanged:
this.syncStatusController.update(this.syncClient.getSyncStatus()) this.syncStatusController.update(this.syncClient.getSyncStatus())
break break
case ApplicationEvent.LocalDataLoaded:
if (this.application.isNativeMobileWeb()) {
this.application.handleInitialMobileScreenshotPrivacy()
}
break
} }
} }