Skip to content

Commit 4464007

Browse files
committed
wip
Signed-off-by: Grigorii K. Shartsev <[email protected]>
1 parent e7ee0e3 commit 4464007

File tree

9 files changed

+3394
-1
lines changed

9 files changed

+3394
-1
lines changed

resources/locales.json

Lines changed: 3002 additions & 0 deletions
Large diffs are not rendered by default.

src/app/AppConfig.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export type AppConfig = {
4545
* Default: true on macOS, false otherwise.
4646
*/
4747
monochromeTrayIcon: boolean
48+
/**
49+
* List of languages to use for spell checking in addition to the system language.
50+
* Default: [], use system preferences
51+
*/
52+
spellCheckLanguages: string[]
4853

4954
// ----------------
5055
// Privacy settings
@@ -66,6 +71,7 @@ const defaultAppConfig: AppConfig = {
6671
theme: 'default',
6772
systemTitleBar: isLinux(),
6873
monochromeTrayIcon: isMac(),
74+
spellCheckLanguages: [],
6975
}
7076

7177
/** Local cache of the config file mixed with the default values */

src/app/__AppConfig.ts

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { join } from 'node:path'
7+
import { readFile, writeFile } from 'node:fs/promises'
8+
import { app } from 'electron'
9+
import { isLinux, isMac } from '../shared/os.utils.js'
10+
11+
const APP_CONFIG_FILE_NAME = 'config.json'
12+
13+
// Windows: C:\Users\<username>\AppData\Roaming\Nextcloud Talk\config.json
14+
// Linux: ~/.config/Nextcloud Talk/config.json (or $XDG_CONFIG_HOME)
15+
// macOS: ~/Library/Application Support/Nextcloud Talk/config.json
16+
const APP_CONFIG_FILE_PATH = join(app.getPath('userData'), APP_CONFIG_FILE_NAME)
17+
18+
/**
19+
* Application level config. Applied to all accounts and persist on re-login.
20+
* Stored in the application data directory.
21+
*/
22+
export type AppConfig = {
23+
// ----------------
24+
// General settings
25+
// ----------------
26+
27+
/** Whether the app should run on startup. Not implemented */
28+
runOnStartup: boolean
29+
30+
// -------------------
31+
// Appearance settings
32+
// -------------------
33+
34+
/** Whether to use a monochrome tray icon. By default, true only on Mac. Not implemented */
35+
monochromeTrayIcon: boolean
36+
/** The scale factor for the app. By default, 1. Not implemented */
37+
scale: number
38+
/** List of languages to use for spell checking in addition to the system language. By default, none. Not implemented */
39+
spellCheckLanguages: string[]
40+
41+
// ----------------
42+
// Privacy settings
43+
// ----------------
44+
45+
/** Whether to show message previews in notifications. By default, true. Not implemented */
46+
showMessagePreviewInNotifications: boolean
47+
48+
// ----------------------
49+
// Notifications settings
50+
// ----------------------
51+
/**
52+
* Whether to play a sound when a notification is received
53+
* - always: always play sound
54+
* - respect-dnd: play sound only if user status isn't Do-Not-Disturb [default]
55+
* - never: disable notification sound
56+
* Not implemented
57+
*/
58+
playSound: 'always' | 'respect-dnd' | 'never'
59+
}
60+
61+
/**
62+
* Get the default config
63+
*/
64+
const defaultAppConfig: AppConfig = {
65+
runOnStartup: false,
66+
theme: 'default',
67+
systemTitleBar: isLinux(),
68+
monochromeTrayIcon: isMac(),
69+
scale: 1,
70+
spellCheckLanguages: [],
71+
showMessagePreviewInNotifications: true,
72+
playSound: 'respect-dnd',
73+
}
74+
75+
/** Local cache of the config file mixed with the default values */
76+
const appConfig: Partial<AppConfig> = {}
77+
/** Whether the application config has been read from the config file and ready to use */
78+
let initialized = false
79+
80+
/**
81+
* Read the application config from the file
82+
*/
83+
async function readAppConfigFile(): Promise<Partial<AppConfig>> {
84+
try {
85+
const content = await readFile(APP_CONFIG_FILE_PATH, 'utf-8')
86+
return JSON.parse(content)
87+
} catch (error) {
88+
if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') {
89+
console.error('Failed to read the application config file', error)
90+
}
91+
// No file or invalid file - no custom config
92+
return {}
93+
}
94+
}
95+
96+
/**
97+
* Write the application config to the config file
98+
* @param config - The config to write
99+
*/
100+
async function writeAppConfigFile(config: Partial<AppConfig>) {
101+
try {
102+
// Format for readability
103+
const content = JSON.stringify(config, null, 2)
104+
await writeFile(APP_CONFIG_FILE_PATH, content)
105+
} catch (error) {
106+
console.error('Failed to write the application config file', error)
107+
throw error
108+
}
109+
}
110+
111+
/**
112+
* Load the application config into the application memory
113+
*/
114+
export async function loadAppConfig() {
115+
const config = await readAppConfigFile()
116+
Object.assign(appConfig, config)
117+
initialized = true
118+
}
119+
120+
export function getAppConfig(): AppConfig
121+
export function getAppConfig<T extends keyof AppConfig>(key?: T): AppConfig[T]
122+
/**
123+
* Get an application config value
124+
* @param key - The config key to get
125+
* @return - If key is provided, the value of the key. Otherwise, the full config
126+
*/
127+
export function getAppConfig<T extends keyof AppConfig>(key?: T): AppConfig | AppConfig[T] {
128+
if (!initialized) {
129+
throw new Error('The application config is not initialized yet')
130+
}
131+
132+
const config = Object.assign({}, defaultAppConfig, appConfig)
133+
134+
if (key) {
135+
return config[key]
136+
}
137+
138+
return config
139+
}
140+
141+
/**
142+
* Set an application config value
143+
* @param key - Settings key to set
144+
* @param value - Value to set or undefined to reset to the default value
145+
* @return Promise<AppConfig> - The full settings after the change
146+
*/
147+
export async function setAppConfig<K extends keyof AppConfig>(key: K, value?: AppConfig[K]) {
148+
if (value !== undefined) {
149+
appConfig[key] = value
150+
} else {
151+
delete appConfig[key]
152+
}
153+
await writeAppConfigFile(appConfig)
154+
}

src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
const path = require('node:path')
7-
const { app, dialog, BrowserWindow, ipcMain, desktopCapturer, systemPreferences, shell } = require('electron')
7+
const { app, dialog, BrowserWindow, ipcMain, desktopCapturer, systemPreferences, shell, session } = require('electron')
88
const { setupMenu } = require('./app/app.menu.js')
99
const { setupReleaseNotificationScheduler } = require('./app/githubReleaseNotification.service.js')
1010
const { enableWebRequestInterceptor, disableWebRequestInterceptor } = require('./app/webRequestInterceptor.js')
@@ -61,6 +61,7 @@ ipcMain.handle('app:getSystemL10n', () => ({
6161
locale: app.getLocale().replace('-', '_'),
6262
language: app.getPreferredSystemLanguages()[0].replace('-', '_'),
6363
}))
64+
ipcMain.handle('app:getAvailableSpellCheckerLanguages', () => session.defaultSession.availableSpellCheckerLanguages)
6465
ipcMain.handle('app:enableWebRequestInterceptor', (event, ...args) => enableWebRequestInterceptor(...args))
6566
ipcMain.handle('app:disableWebRequestInterceptor', (event, ...args) => disableWebRequestInterceptor(...args))
6667
ipcMain.handle('app:setBadgeCount', async (event, count) => app.setBadgeCount(count))

src/preload.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const TALK_DESKTOP = {
5454
* @return {Promise<{ locale: string, language: string }>}
5555
*/
5656
getSystemL10n: () => ipcRenderer.invoke('app:getSystemL10n'),
57+
/**
58+
* Get available spell checker languages
59+
*
60+
* @return {Promise<string[]>}
61+
*/
62+
getAvailableSpellCheckerLanguages: () => ipcRenderer.invoke('app:getAvailableSpellCheckerLanguages'),
5763
/**
5864
* Enable web request intercepting
5965
*

src/talk/renderer/Settings/DesktopSettingsSection.vue

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { useAppConfigValue } from './useAppConfigValue.ts'
1515
import { useNcSelectModel } from '../composables/useNcSelectModel.ts'
1616
import { useAppConfig } from './appConfig.store.ts'
1717
import { storeToRefs } from 'pinia'
18+
import locales from '../../../../resources/locales.json'
19+
import { computed, ref } from "vue";
1820
1921
const { isRelaunchRequired } = storeToRefs(useAppConfig())
2022
@@ -28,6 +30,31 @@ const themeOption = useNcSelectModel(theme, themeOptions)
2830
2931
const systemTitleBar = useAppConfigValue('systemTitleBar')
3032
const monochromeTrayIcon = useAppConfigValue('monochromeTrayIcon')
33+
const spellCheckLanguages = useAppConfigValue('spellCheckLanguages')
34+
const availableSpellCheckLanguages = ref<Set<string>>(new Set())
35+
36+
window.TALK_DESKTOP.getAvailableSpellCheckerLanguages().then((languages: string[]) => {
37+
availableSpellCheckLanguages.value = new Set(languages.map((code) => code.replaceAll('_', '-')))
38+
console.log('availableSpellCheckLanguages', languages)
39+
})
40+
41+
const langToSelectOption = (code: string) => ({ label: locales.find(locale => locale), value: code }))
42+
}
43+
44+
const spellCheckLanguagesOptions = computed(() => [
45+
{ label: t('talk_desktop', 'System default'), value: 'default' },
46+
...locales
47+
.filter(({ code }) => availableSpellCheckLanguages.value.has(code))
48+
.map(({ code, name }) => ({ label: name, value: code })),
49+
])
50+
const selectedSpellCheckLanguagesOption = computed(() => {
51+
get() {
52+
return
53+
},
54+
set(value) {
55+
56+
}
57+
})
3158
3259
/**
3360
* Restart the app
@@ -66,6 +93,10 @@ function relaunch() {
6693
<NcCheckboxRadioSwitch :checked.sync="systemTitleBar" type="switch">
6794
{{ t('talk_desktop', 'Use system title bar') }}
6895
</NcCheckboxRadioSwitch>
96+
97+
<SettingsSelect v-model="spellCheckLanguagesOption" :options="spellCheckLanguagesOptions" searchable tags>
98+
{{ t('talk_desktop', 'Spell check languages') }}
99+
</SettingsSelect>
69100
</SettingsSubsection>
70101
</div>
71102
</template>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const model = computed({
2525

2626
<script lang="ts">
2727
export default {
28+
inheritAttrs: false,
29+
2830
model: {
2931
prop: 'modelValue',
3032
event: 'update:modelValue',
@@ -47,6 +49,7 @@ export default {
4749
:options="options"
4850
:clearable="false"
4951
:searchable="false"
52+
v-bind="$attrs"
5053
label-outside />
5154
</label>
5255
</template>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
6+
<script setup lang="ts">
7+
import { t } from '@nextcloud/l10n'
8+
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
9+
import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar.js'
10+
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
11+
import NcListItem from '@nextcloud/vue/dist/Components/NcListItem.js'
12+
import IconAccountMultiplePlus from 'vue-material-design-icons/AccountMultiplePlus.vue'
13+
import IconDelete from 'vue-material-design-icons/Delete.vue'
14+
import SettingsSubsection from './SettingsSubsection.vue'
15+
</script>
16+
17+
<template>
18+
<SettingsSubsection>
19+
<ul>
20+
<NcListItem name="Grigorii K. Shartsev" details="nextcloud.local">
21+
<template #icon>
22+
<NcAvatar user="shgkme" />
23+
</template>
24+
<template #subname>
25+
26+
</template>
27+
<template #actions>
28+
<NcActionButton>
29+
<template #icon>
30+
<IconDelete :size="20" />
31+
</template>
32+
{{ t('talk_desktop', 'Remove') }}
33+
</NcActionButton>
34+
</template>
35+
</NcListItem>
36+
<NcListItem name="admin" details="stable30.local">
37+
<template #icon>
38+
<NcAvatar user="admin" />
39+
</template>
40+
<template #subname>
41+
42+
</template>
43+
<template #actions>
44+
<NcActionButton>
45+
<template #icon>
46+
<IconDelete :size="20" />
47+
</template>
48+
{{ t('talk_desktop', 'Remove') }}
49+
</NcActionButton>
50+
</template>
51+
</NcListItem>
52+
</ul>
53+
<NcButton wide>
54+
<template #icon>
55+
<IconAccountMultiplePlus :size="20" />
56+
</template>
57+
{{ t('talk_desktop', 'Log into a new account') }}
58+
</NcButton>
59+
</SettingsSubsection>
60+
</template>

0 commit comments

Comments
 (0)