Skip to content

Commit

Permalink
feat(desktop): add talk settings frontend API
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <[email protected]>
  • Loading branch information
ShGKme committed Sep 10, 2024
1 parent ae83af9 commit f7721de
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/components/SettingsDialog/SettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
<NcAppSettingsDialog :open.sync="showSettings"
:name="t('spreed', 'Talk settings')"
:show-navigation="true"
first-selected-section="keyboard shortcuts"
:container="container">
<!-- Custom settings sections registered via OCA.Talk.Settings -->
<NcAppSettingsSection v-for="{ id, name, element } in customSettingsSections"
:id="id"
:key="id"
:name="name"
class="app-settings-section">
<component :is="element" />
</NcAppSettingsSection>

<NcAppSettingsSection id="devices"
:name="t('spreed', 'Choose devices')"
class="app-settings-section">
Expand Down Expand Up @@ -185,6 +193,7 @@ import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadi
import MediaDevicesPreview from './MediaDevicesPreview.vue'
import { useCustomSettings } from '../../services/SettingsAPI.ts'

Check failure on line 196 in src/components/SettingsDialog/SettingsDialog.vue

View workflow job for this annotation

GitHub Actions / NPM lint

`../../services/SettingsAPI.ts` import should occur after import of `../../services/CapabilitiesManager.ts`
import { PRIVACY } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
Expand All @@ -207,11 +216,13 @@ export default {
setup() {
const settingsStore = useSettingsStore()
const { customSettingsSections } = useCustomSettings()
return {
settingsStore,
supportTypingStatus,
isBackgroundBlurred,
customSettingsSections,
}
},
Expand Down
4 changes: 3 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import App from './App.vue'

import './init.js'
import router from './router/router.js'
import { SettingsAPI } from './services/SettingsAPI.ts'
import store from './store/index.js'

// Leaflet icon patch
Expand Down Expand Up @@ -81,7 +82,7 @@ const Sidebar = function() {
if (!sidebarShown) {
this.state.file = ''
}
}
},
)
}

Expand Down Expand Up @@ -153,5 +154,6 @@ if (!window.OCA.Talk) {
window.OCA.Talk = {}
}
OCA.Talk.instance = instance
OCA.Talk.Settings = SettingsAPI

export default instance
66 changes: 66 additions & 0 deletions src/services/SettingsAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { readonly, shallowReactive } from 'vue'

import { emit } from '@nextcloud/event-bus'

type TalkSettingsSection = {
/**
* Section internal ID
*/
id: string
/**
* Section visible name
*/
name: string
/**
* WebComponent's (custom element's) tag name to render as the section content
*/
element: string
}

const customSettingsSections: TalkSettingsSection[] = shallowReactive([])

/**
* Register a custom settings section
* @param section - Settings section
*/
function registerSection(section: TalkSettingsSection) {
customSettingsSections.push(section)
}

/**
* Unregister a custom settings section
* @param id - Section ID
*/
function unregisterSection(id: string) {
const index = customSettingsSections.findIndex((section) => section.id === id)
if (index !== -1) {
customSettingsSections.splice(index, 1)
}
}

/**
* Open settings dialog
*/
function open() {
emit('show-settings', undefined)
}

export const SettingsAPI = {
open,
registerSection,
unregisterSection,
}

/**
* Composable to use custom settings in Talk
*/
export function useCustomSettings() {
return {
customSettingsSections: readonly(customSettingsSections),
}
}

0 comments on commit f7721de

Please sign in to comment.