Skip to content

Commit 388161f

Browse files
committed
Revert "Use new unreadCountStore for setting appIcon Badge"
This reverts commit a639ada.
1 parent a639ada commit 388161f

File tree

4 files changed

+23
-71
lines changed

4 files changed

+23
-71
lines changed

src/main.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ ipcMain.handle('app:getSystemL10n', () => ({
8585
}))
8686
ipcMain.handle('app:enableWebRequestInterceptor', (event, ...args) => enableWebRequestInterceptor(...args))
8787
ipcMain.handle('app:disableWebRequestInterceptor', (event, ...args) => disableWebRequestInterceptor(...args))
88-
ipcMain.handle('app:setBadgeCount', async (event, count) => {
89-
return app.setBadgeCount(count)
90-
})
88+
ipcMain.handle('app:setBadgeCount', async (event, count) => app.setBadgeCount(count))
9189
ipcMain.on('app:relaunch', () => {
9290
app.relaunch()
9391
app.exit(0)

src/talk/renderer/TalkDesktop.vue

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
-->
55

66
<script setup lang="ts">
7-
import { provide, ref, onMounted } from 'vue'
7+
import { provide, ref } from 'vue'
88
import TitleBar from './TitleBar/TitleBar.vue'
99
import TalkWrapper from './TalkWrapper/TalkWrapper.vue'
1010
import { createViewer } from './Viewer/Viewer.js'
1111
import { useNotificationsStore } from './notifications/notifications.store.js'
12-
import unreadCountStore from '../../../spreed/src/store/unreadCountStore.js'
1312

1413
const isTalkInitialized = ref(false)
1514
provide('talk:isInitialized', isTalkInitialized)

src/talk/renderer/TalkWrapper/TalkWrapper.vue

+19-66
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,38 @@
44
-->
55

66
<script setup lang="ts">
7-
import { onMounted, onUnmounted } from 'vue'
7+
import { onMounted } from 'vue'
88
import { onTalkHashDirty, onTalkHashUpdate, openConversation, setTalkHash } from './talk.service.ts'
99
import { registerTalkDesktopSettingsSection } from '../Settings/index.ts'
1010
import { subscribeBroadcast } from '../../../shared/broadcast.service.ts'
1111
import { appData } from '../../../app/AppData.js'
12-
import unreadCountStore, { EVENTS } from '@talk/src/store/unreadCountStore'
13-
import { subscribe, emit as emitEvent } from '@nextcloud/event-bus'
1412

1513
const emit = defineEmits<{
1614
(event: 'ready'): void
1715
}>()
1816

19-
// Handler for unread count updates
20-
let unsubscribeUnreadCount: (() => void) | null = null
21-
22-
const waitForTalkAndStore = async () => {
23-
console.debug('TalkWrapper: Waiting for Talk instance and store...')
24-
let attempts = 0
25-
const maxAttempts = 50
26-
const delay = 100
27-
28-
while (attempts < maxAttempts) {
29-
if (window.OCA?.Talk?.instance && window.store && window.TALK_DESKTOP) {
30-
console.debug('TalkWrapper: Talk instance, store, and TALK_DESKTOP found')
31-
return true
32-
}
33-
await new Promise(resolve => setTimeout(resolve, delay))
34-
attempts++
35-
}
36-
throw new Error('Talk instance, store, or TALK_DESKTOP not initialized after maximum attempts')
37-
}
38-
3917
onMounted(async () => {
40-
try {
41-
await import('@talk/src/main.js')
42-
43-
registerTalkDesktopSettingsSection()
44-
subscribeBroadcast('talk:conversation:open', ({ token, directCall }) => openConversation(token, { directCall }))
45-
46-
await waitForTalkAndStore()
47-
const store = window.store
48-
49-
// Register store module if not already registered
50-
if (!store.hasModule('unreadCount')) {
51-
store.registerModule('unreadCount', unreadCountStore)
52-
}
18+
// Importing the main Talk entry point mounts a Vue app to the #content
19+
await import('@talk/src/main.js')
5320

54-
// Initialize badge handling
55-
window.TALK_DESKTOP.setBadgeCount(0)
56-
57-
// Subscribe to unread count updates
58-
unsubscribeUnreadCount = subscribe(EVENTS.UNREAD_COUNT_UPDATED, ({ unreadMessages }) => {
59-
window.TALK_DESKTOP.setBadgeCount(unreadMessages || 0)
60-
})
61-
62-
// Now trigger the initial calculation
63-
store.dispatch('unreadCount/recalculateTotalUnreadCounters')
64-
65-
if (appData.talkHash) {
66-
setTalkHash(appData.talkHash)
67-
}
68-
onTalkHashUpdate((hash: string) => {
69-
appData.setTalkHash(hash).persist()
70-
})
71-
onTalkHashDirty(() => {
72-
appData.setTalkHashDirty(true).persist()
73-
})
74-
75-
emit('ready')
76-
} catch (error) {
77-
console.error('TalkWrapper: Error during initialization:', error)
78-
}
79-
})
21+
// Additional integrations
22+
registerTalkDesktopSettingsSection()
23+
subscribeBroadcast('talk:conversation:open', ({ token, directCall }) => openConversation(token, { directCall }))
8024

81-
// Cleanup event listeners
82-
onUnmounted(() => {
83-
if (unsubscribeUnreadCount) {
84-
unsubscribeUnreadCount()
25+
// If there is a talkHash - set it initially
26+
if (appData.talkHash) {
27+
setTalkHash(appData.talkHash)
8528
}
29+
// Handle Talk Hash updates
30+
onTalkHashUpdate((hash: string) => {
31+
appData.setTalkHash(hash).persist()
32+
})
33+
onTalkHashDirty(() => {
34+
appData.setTalkHashDirty(true).persist()
35+
})
36+
37+
// Ready
38+
emit('ready')
8639
})
8740
</script>
8841

src/talk/renderer/notifications/notifications.store.js

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export function createNotificationStore() {
9494
if (notifications.length > _oldcount) {
9595
_oldcount = notifications.length
9696
if (state.backgroundFetching && document.hidden) {
97+
window.TALK_DESKTOP.setBadgeCount()
9798
window.TALK_DESKTOP.flashAppIcon(true)
9899
// If we didn't already highlight, store the title so we can restore on tab-view
99100
if (!document.title.startsWith('* ')) {
@@ -109,6 +110,7 @@ export function createNotificationStore() {
109110
* the Talk might have altered it.
110111
*/
111112
function _restoreTitle() {
113+
window.TALK_DESKTOP.setBadgeCount(0)
112114
window.TALK_DESKTOP.flashAppIcon(false)
113115
if (document.title.startsWith('* ')) {
114116
document.title = document.title.substring(2)

0 commit comments

Comments
 (0)