Skip to content

Commit 7861e48

Browse files
committed
feat(user-status): add config for system activity status
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
1 parent 01ca02e commit 7861e48

File tree

6 files changed

+58
-4
lines changed

6 files changed

+58
-4
lines changed

build/BuildConfig.types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export type BuildConfigFile = {
6666
*/
6767
privacyUrl: string
6868

69+
/**
70+
* Disallow the user to disable the system activity status check
71+
*/
72+
forceEnableSystemActivityStatus: boolean
73+
6974
/****************
7075
* Distribution *
7176
****************/

build/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"brandFontColor": "#FFFFFF",
77
"helpUrl": "https://nextcloud.com/talk/",
88
"privacyUrl": "https://nextcloud.com/privacy/",
9+
"forceEnableSystemActivityStatus": false,
910
"windowsExe": true,
1011
"windowsMsi": true,
1112
"macosDmg": true,

src/app/AppConfig.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { join } from 'node:path'
77
import { readFile, writeFile } from 'node:fs/promises'
88
import { app, webContents } from 'electron'
99
import { isLinux, isMac } from './system.utils.ts'
10+
import { BUILD_CONFIG } from '../shared/build.config.ts'
1011

1112
const APP_CONFIG_FILE_NAME = 'config.json'
1213

@@ -70,7 +71,11 @@ export type AppConfig = {
7071
// Privacy settings
7172
// ----------------
7273

73-
// Nothing yet...
74+
/**
75+
* Whether check system activity/idle when updating user status to "Online"/"Away"
76+
* Default: true
77+
*/
78+
enableSystemActivityStatus: boolean
7479

7580
// ----------------------
7681
// Notifications settings
@@ -120,13 +125,19 @@ const defaultAppConfig: AppConfig = {
120125
systemTitleBar: isLinux,
121126
monochromeTrayIcon: isMac,
122127
zoomFactor: 1,
128+
enableSystemActivityStatus: true,
123129
playSoundChat: 'respect-dnd',
124130
playSoundCall: 'respect-dnd',
125131
enableCallbox: 'respect-dnd',
126132
secondarySpeaker: false,
127133
secondarySpeakerDevice: null,
128134
}
129135

136+
const forcedConfig: Partial<AppConfig> = {}
137+
if (BUILD_CONFIG.forceEnableSystemActivityStatus) {
138+
forcedConfig.enableSystemActivityStatus = true
139+
}
140+
130141
/** Local cache of the config file mixed with the default values */
131142
const appConfig: Partial<AppConfig> = {}
132143
/** Whether the application config has been read from the config file and ready to use */
@@ -190,7 +201,7 @@ export function getAppConfig<T extends AppConfigKey>(key?: T): AppConfig | AppCo
190201
throw new Error('The application config is not initialized yet')
191202
}
192203

193-
const config = { ...defaultAppConfig, ...appConfig }
204+
const config = { ...defaultAppConfig, ...appConfig, ...forcedConfig }
194205

195206
if (key) {
196207
return config[key]

src/talk/renderer/Settings/DesktopSettingsSection.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { storeToRefs } from 'pinia'
1010
import { t } from '@nextcloud/l10n'
1111
import NcButton from '@nextcloud/vue/components/NcButton'
1212
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
13+
import IconAccountBadge from 'vue-material-design-icons/AccountBadge.vue'
1314
import IconMagnify from 'vue-material-design-icons/Magnify.vue'
1415
import IconMinus from 'vue-material-design-icons/Minus.vue'
1516
import IconPlus from 'vue-material-design-icons/Plus.vue'
@@ -28,6 +29,7 @@ import { useAppConfigStore } from './appConfig.store.ts'
2829
import { useAppConfigValue } from './useAppConfigValue.ts'
2930
import { useNcSelectModel } from '../composables/useNcSelectModel.ts'
3031
import { ZOOM_MIN, ZOOM_MAX } from '../../../constants.js'
32+
import { BUILD_CONFIG } from '../../../shared/build.config.ts'
3133
3234
const isLinux = window.systemInfo.isLinux
3335
@@ -81,6 +83,14 @@ const playSoundCallOption = useNcSelectModel(playSoundCall, generalNotificationO
8183
const enableCallbox = useAppConfigValue('enableCallbox')
8284
const enableCallboxOption = useNcSelectModel(enableCallbox, generalNotificationOptions)
8385
86+
const forceEnableSystemActivityStatus = BUILD_CONFIG.forceEnableSystemActivityStatus
87+
const enableSystemActivityStatus = useAppConfigValue('enableSystemActivityStatus')
88+
const enableSystemActivityStatusOptions = [
89+
{ label: t('talk_desktop', 'Also from activity in the system'), value: true } as const,
90+
{ label: t('talk_desktop', 'Only from activity in the app'), value: false } as const,
91+
]
92+
const enableSystemActivityStatusOption = useNcSelectModel(enableSystemActivityStatus, enableSystemActivityStatusOptions)
93+
8494
const secondarySpeaker = useAppConfigValue('secondarySpeaker')
8595
8696
const EMPTY_DEVICE_OPTION = { value: null, label: t('talk_desktop', 'None') }
@@ -139,6 +149,19 @@ function relaunch() {
139149
<NcCheckboxRadioSwitch v-model="launchAtStartup" type="switch">
140150
{{ t('talk_desktop', 'Launch at startup') }}
141151
</NcCheckboxRadioSwitch>
152+
153+
<SettingsSelect
154+
v-model="enableSystemActivityStatusOption"
155+
:options="enableSystemActivityStatusOptions"
156+
:disabled="forceEnableSystemActivityStatus"
157+
:label="t('talk_desktop', 'Set my user status to Online/Away')">
158+
<template #icon="{ size }">
159+
<IconAccountBadge :size="size" />
160+
</template>
161+
<template v-if="forceEnableSystemActivityStatus" #description>
162+
{{ t('talk_desktop', 'Changing this option is disabled by administrator') }}
163+
</template>
164+
</SettingsSelect>
142165
</SettingsSubsection>
143166

144167
<SettingsSubsection :name="t('talk_desktop', 'Appearance')">

src/talk/renderer/Settings/components/SettingsSelect.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export default {
5656
<template #action>
5757
<slot name="action" />
5858
</template>
59+
60+
<template v-if="$slots.description" #description>
61+
<slot name="description" />
62+
</template>
5963
</SettingsFormGroup>
6064
</template>
6165

src/talk/renderer/UserStatus/useSystemIdle.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { onUnmounted, readonly, ref } from 'vue'
6+
import { onUnmounted, readonly, ref, watch } from 'vue'
77
import { requestUserGesturedPermission } from '../../../shared/requestUserGesturedPermission.ts'
8+
import { useAppConfigValue } from '../Settings/useAppConfigValue.ts'
89

910
let hasPermission = false
1011

@@ -14,12 +15,21 @@ let hasPermission = false
1415
* @param threshold - How long user is considered idle in ms, default is 1 minute
1516
*/
1617
export function useSystemIdle(threshold: number = 60_000) {
18+
const enableSystemActivityStatus = useAppConfigValue('enableSystemActivityStatus')
19+
1720
const isIdleDetected = ref(false)
1821

1922
let abortController: AbortController
2023
let idleDetector: IdleDetector
2124

22-
startIdleDetector()
25+
watch(enableSystemActivityStatus, (isEnabled, wasEnabled) => {
26+
if (isEnabled) {
27+
startIdleDetector()
28+
}
29+
if (wasEnabled) {
30+
stopIdleDetector()
31+
}
32+
}, { immediate: true })
2333

2434
onUnmounted(() => {
2535
stopIdleDetector()

0 commit comments

Comments
 (0)