Skip to content

Commit

Permalink
disable screenshots on desktop also (keybase#26986)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisnojima authored Jun 6, 2024
1 parent 8a112fb commit 5346b7f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
12 changes: 11 additions & 1 deletion shared/desktop/app/main-window.desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ let useNativeFrame = defaultUseNativeFrame
let isDarkMode = false
let darkModePreference: undefined | 'system' | 'alwaysDark' | 'alwaysLight'
let disableSpellCheck = false
let disableScreenshot = true

/**
* loads data that we normally save from configGuiSetValue. At this point the service might not exist so we must read it directly
Expand All @@ -132,6 +133,7 @@ const loadWindowState = () => {
useNativeFrame: unknown
ui: Partial<{
disableSpellCheck: unknown
disableScreenshot: unknown
darkMode: unknown
}>
windowState: unknown
Expand All @@ -143,8 +145,13 @@ const loadWindowState = () => {
typeof guiConfig?.useNativeFrame === 'boolean' ? guiConfig.useNativeFrame : useNativeFrame

if (guiConfig?.ui) {
const {darkMode, disableSpellCheck: _disableSpellCheck} = guiConfig.ui
const {
darkMode,
disableSpellCheck: _disableSpellCheck,
disableScreenshot: _disableScreenshot,
} = guiConfig.ui
disableSpellCheck = typeof _disableSpellCheck === 'boolean' ? _disableSpellCheck : disableSpellCheck
disableScreenshot = typeof _disableScreenshot === 'boolean' ? _disableScreenshot : disableScreenshot

if (typeof darkMode === 'string') {
switch (darkMode) {
Expand Down Expand Up @@ -327,6 +334,9 @@ const MainWindow = () => {
y: windowState.y,
...(isDarwin ? {titleBarStyle: 'hiddenInset'} : {}),
})

win.setContentProtection(disableScreenshot)

if (__DEV__ || __PROFILE__) {
setupDevToolsExtensions()
}
Expand Down
2 changes: 1 addition & 1 deletion shared/settings/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const sharedNewRoutes = {
[Constants.settingsGitTab]: gitRoutes.gitRoot,
[Constants.settingsInvitationsTab]: invitations,
[Constants.settingsNotificationsTab]: notifications,
[Constants.settingsScreenprotectorTab]: screenprotectorTab,
[Constants.settingsWalletsTab]: {...walletsRoutes.walletsRoot},
[Constants.settingsWhatsNewTab]: whatsNew,
addEmail,
Expand All @@ -78,7 +79,6 @@ const sharedNewModalRoutes = {
export const newRoutes = {
settingsRoot: C.isMobile ? (C.isPhone ? settingsRootPhone : settingsRootDesktop) : settingsRootDesktop,
...sharedNewRoutes,
[Constants.settingsScreenprotectorTab]: screenprotectorTab,
[Constants.settingsContactsTab]: contactsTab,
webLinks,
}
Expand Down
72 changes: 70 additions & 2 deletions shared/settings/screenprotector.desktop.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,70 @@
const Protect = () => null
export default Protect
import * as C from '@/constants'
import * as T from '@/constants/types'
import * as React from 'react'
import * as Kb from '@/common-adapters'

const Screenprotector = () => {
const [disableScreenshot, setDisableScreenshot] = React.useState<boolean | undefined>(undefined)
const initialDisableScreenshot = React.useRef<boolean | undefined>(undefined)
const loadDisableScreenshot = C.useRPC(T.RPCGen.configGuiGetValueRpcPromise)

// load it
if (disableScreenshot === undefined) {
setTimeout(() => {
loadDisableScreenshot(
[{path: 'ui.disableScreenshot'}],
result => {
const res = result.b ?? false
initialDisableScreenshot.current = res
setDisableScreenshot(res)
},
() => {
setDisableScreenshot(false)
}
)
}, 1)
}
const submitDisableSpellcheck = C.useRPC(T.RPCGen.configGuiSetValueRpcPromise)

const onToggleDisableScreenshot = () => {
const next = !disableScreenshot
setDisableScreenshot(next)
submitDisableSpellcheck(
[
{
path: 'ui.disableScreenshot',
value: {b: next, isNull: false},
},
],
() => {},
() => {
console.log('cant save screenshot?')
setDisableScreenshot(!next)
}
)
}

return (
<Kb.Box2 direction="vertical" fullWidth={true}>
<Kb.Box2 direction="vertical" fullWidth={true} style={styles.container}>
<Kb.Checkbox
label={
'Disable screenshots' +
(initialDisableScreenshot.current === disableScreenshot ? '' : ' (restart required)')
}
disabled={disableScreenshot === undefined}
checked={!!disableScreenshot}
onCheck={onToggleDisableScreenshot}
/>
</Kb.Box2>
</Kb.Box2>
)
}

const styles = Kb.Styles.styleSheetCreate(() => ({
container: {
...Kb.Styles.padding(Kb.Styles.globalMargins.small),
},
}))

export default Screenprotector
8 changes: 8 additions & 0 deletions shared/settings/sub-nav/left-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ const LeftNav = (props: Props) => {
selected={props.selected === C.Settings.settingsAboutTab}
onClick={() => props.onClick(C.Settings.settingsAboutTab)}
/>

{!Kb.Styles.isTablet && (
<SettingsItem
text="Screen protector"
selected={props.selected === C.Settings.settingsScreenprotectorTab}
onClick={() => props.onClick(C.Settings.settingsScreenprotectorTab)}
/>
)}
<SettingsItem
text="Feedback"
selected={props.selected === C.Settings.settingsFeedbackTab}
Expand Down

0 comments on commit 5346b7f

Please sign in to comment.