-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1038 from nextcloud/fix/init-process
fix: Talk init process
- Loading branch information
Showing
19 changed files
with
306 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import Vue from 'vue' | ||
import { createPinia, PiniaVuePlugin } from 'pinia' | ||
|
||
/** | ||
* Create and mount the Talk Desktop | ||
*/ | ||
export async function createTalkDesktopApp() { | ||
Vue.use(PiniaVuePlugin) | ||
const pinia = createPinia() | ||
|
||
// Load Talk Desktop asynchronously to make sure, | ||
// no module is loaded before the page has been set up and ready to run apps | ||
const { default: TalkDesktop } = await import('./TalkDesktop.vue') | ||
|
||
const TalkDesktopApp = Vue.extend(TalkDesktop) | ||
return new TalkDesktopApp({ pinia }).$mount('#app') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
|
||
<script setup lang="ts"> | ||
import { provide, ref } from 'vue' | ||
import { useHotKey } from '@nextcloud/vue/dist/Composables/useHotKey.js' | ||
import TitleBar from './TitleBar/TitleBar.vue' | ||
import TalkWrapper from './TalkWrapper/TalkWrapper.vue' | ||
import { openRoot } from './TalkWrapper/talk.service.ts' | ||
import { createViewer } from './Viewer/Viewer.js' | ||
import { useNotificationsStore } from './notifications/notifications.store.js' | ||
|
||
const isTalkInitialized = ref(false) | ||
provide('talk:isInitialized', isTalkInitialized) | ||
|
||
useNotificationsStore() | ||
|
||
window.OCA.Viewer = createViewer() | ||
|
||
// Unselect chat by escape key | ||
useHotKey('Escape', openRoot) | ||
</script> | ||
|
||
<template> | ||
<div id="app"> | ||
<div id="skip-actions" /> | ||
<TitleBar id="header" /> | ||
<TalkWrapper @ready="isTalkInitialized = true" /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
|
||
<script setup lang="ts"> | ||
import { onMounted } from 'vue' | ||
import { onTalkHashDirty, onTalkHashSetInitial, openConversation, setTalkHash } from './talk.service.ts' | ||
import { registerTalkDesktopSettingsSection } from '../Settings/index.ts' | ||
import { subscribeBroadcast } from '../../../shared/broadcast.service.ts' | ||
import { appData } from '../../../app/AppData.js' | ||
|
||
const emit = defineEmits<{ | ||
(event: 'ready'): void | ||
}>() | ||
|
||
onMounted(async () => { | ||
// Importing the main Talk entry point mounts a Vue app to the #content | ||
await import('@talk/src/main.js') | ||
|
||
// Additional integrations | ||
registerTalkDesktopSettingsSection() | ||
subscribeBroadcast('talk:conversation:open', ({ token, directCall }) => openConversation(token, { directCall })) | ||
|
||
// If there is a talkHash - set it initially | ||
if (appData.talkHash) { | ||
setTalkHash(appData.talkHash) | ||
} | ||
// Handle Talk Hash updates | ||
onTalkHashSetInitial((hash: string) => { | ||
appData.setTalkHash(hash).persist() | ||
}) | ||
onTalkHashDirty(() => { | ||
appData.setTalkHashDirty(true).persist() | ||
// TODO: make soft restart (!) | ||
window.TALK_DESKTOP.relaunch() | ||
}) | ||
|
||
// Ready | ||
emit('ready') | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div id="content" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { isNavigationFailure, NavigationFailureType } from '@talk/node_modules/vue-router' | ||
import { useTalkHashStore } from '@talk/src/stores/talkHash.js' | ||
|
||
/** | ||
* Get the Talk instance | ||
*/ | ||
function getTalkInstance() { | ||
if (!window.OCA.Talk?.instance) { | ||
throw new Error('Talk is not initialized yet or not available') | ||
} | ||
return window.OCA.Talk.instance | ||
} | ||
|
||
/** | ||
* Get the Talk router | ||
*/ | ||
function getTalkRouter() { | ||
return getTalkInstance().$router | ||
} | ||
|
||
/** | ||
* Get the current Talk route path | ||
*/ | ||
export function getCurrentTalkRoutePath() { | ||
// TODO: add Vue 3 compatibility | ||
return getTalkRouter().currentRoute.fullPath | ||
} | ||
|
||
/** | ||
* Open the Talk root | ||
*/ | ||
export function openRoot() { | ||
getTalkRouter().push({ name: 'root' }).catch(passDuplicatedNavigationError) | ||
} | ||
|
||
/** | ||
* Open a conversation in Talk | ||
* @param token - Conversation token | ||
* @param options - Options | ||
* @param options.directCall - Use direct call (open media settings to join a call) | ||
*/ | ||
export async function openConversation(token: string, { directCall = false }: { directCall?: boolean } = {}) { | ||
await getTalkRouter().push({ | ||
name: 'conversation', | ||
params: { token }, | ||
hash: directCall ? '#direct-call' : undefined, | ||
}).catch(passDuplicatedNavigationError) | ||
|
||
await window.TALK_DESKTOP.focusTalk() | ||
} | ||
|
||
/** | ||
* Ignore duplicated navigation error | ||
* @param error - Error | ||
*/ | ||
function passDuplicatedNavigationError(error: Error) { | ||
if (!isNavigationFailure(error, NavigationFailureType.duplicated)) { | ||
throw error | ||
} | ||
} | ||
|
||
type TalkHashStoreAdapter = { | ||
/** Set Nextcloud Talk hash */ | ||
setTalkHash: (hash: string) => void, | ||
/** Listen to Nextcloud Talk initialized */ | ||
onSetInitial: (callback: (hash: string) => void) => void, | ||
/** Listen to Nextcloud Talk hash set dirty */ | ||
onDirty: (callback: () => void) => void, | ||
} | ||
|
||
/** | ||
* Create a Talk hash store adapter | ||
*/ | ||
function createTalkHashStoreAdapter(): TalkHashStoreAdapter { | ||
const talkHashStore = useTalkHashStore(getTalkInstance().$pinia) | ||
|
||
let onDirty: Parameters<TalkHashStoreAdapter['onDirty']>[0] | ||
let onSetInitial: Parameters<TalkHashStoreAdapter['onSetInitial']>[0] | ||
|
||
talkHashStore.$onAction(({ name, after }) => { | ||
if (name !== 'setNextcloudTalkHash') { | ||
return | ||
} | ||
after(() => { | ||
if (talkHashStore.isNextcloudTalkHashDirty) { | ||
onDirty?.() | ||
} else { | ||
onSetInitial?.(talkHashStore.initialNextcloudTalkHash) | ||
} | ||
}) | ||
}) | ||
|
||
return { | ||
setTalkHash: (hash) => talkHashStore.setNextcloudTalkHash(hash), | ||
onDirty: (callback) => { | ||
onDirty = callback | ||
}, | ||
onSetInitial: (callback) => { | ||
onSetInitial = callback | ||
}, | ||
} | ||
} | ||
|
||
let talkHashStoreAdapter: TalkHashStoreAdapter | null = null | ||
|
||
/** | ||
* Get the Talk hash store adapter singleton | ||
*/ | ||
function getTalkHashStoreAdapter() { | ||
if (!talkHashStoreAdapter) { | ||
talkHashStoreAdapter = createTalkHashStoreAdapter() | ||
} | ||
return talkHashStoreAdapter | ||
} | ||
|
||
/** | ||
* Set the Talk hash | ||
* @param hash - Talk Hash | ||
*/ | ||
export function setTalkHash(hash: string) { | ||
getTalkHashStoreAdapter().setTalkHash(hash) | ||
} | ||
|
||
/** | ||
* Listen to Talk hash set initial | ||
* @param callback - Callback | ||
*/ | ||
export function onTalkHashSetInitial(callback: (hash: string) => void) { | ||
getTalkHashStoreAdapter().onSetInitial(callback) | ||
} | ||
|
||
/** | ||
* Listen to Talk hash dirty | ||
* @param callback - Callback | ||
*/ | ||
export function onTalkHashDirty(callback: () => void) { | ||
getTalkHashStoreAdapter().onDirty(callback) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.