mirror of
https://github.com/modrinth/code.git
synced 2026-09-02 13:05:50 +00:00
refactor: app event bus (#6985)
* refactor: app event bus * fix: use messagepack + cleanup * fix: use postcard * fix: lint * fix: import gate * fix: prettierignore + lint * fix: lint * fix: rev
This commit is contained in:
@@ -127,13 +127,9 @@ import { useRouter } from 'vue-router'
|
||||
import ExportModal from '@/components/ui/ExportModal.vue'
|
||||
import ShareModalWrapper from '@/components/ui/modal/ShareModalWrapper.vue'
|
||||
import { useManagedContentPolicy } from '@/composables/instances/use-managed-content-policy'
|
||||
import { useAppEvent } from '@/composables/use-app-event'
|
||||
import { trackEvent } from '@/helpers/analytics'
|
||||
import { get_project_versions, get_version, get_version_many } from '@/helpers/cache.js'
|
||||
import {
|
||||
instance_bulk_update_progress_listener,
|
||||
instance_listener,
|
||||
type InstanceBulkUpdateProgress,
|
||||
} from '@/helpers/events.js'
|
||||
import {
|
||||
add_project_from_path,
|
||||
edit,
|
||||
@@ -151,6 +147,7 @@ import { type InstanceContentData, loadInstanceContentData } from '@/helpers/ins
|
||||
import { get as getSettings, set as setSettings } from '@/helpers/settings'
|
||||
import type { CacheBehaviour } from '@/helpers/types'
|
||||
import { highlightModInInstance } from '@/helpers/utils.js'
|
||||
import { type AppEventPayload, injectAppEvents } from '@/providers/app-events'
|
||||
import { injectContentInstall } from '@/providers/content-install'
|
||||
import { useTheming } from '@/store/state'
|
||||
import type { FeatureFlag } from '@/store/theme'
|
||||
@@ -159,6 +156,8 @@ import { injectInstancePage } from '../instance-context'
|
||||
import { instanceContentQueryOptions, instanceKeys } from '../query-options'
|
||||
import { injectSharedInstance } from '../shared-instance-context'
|
||||
|
||||
type InstanceBulkUpdateProgress = AppEventPayload<'instance_bulk_update_progress'>
|
||||
|
||||
const messages = defineMessages({
|
||||
modpackContentHeader: {
|
||||
id: 'app.instance.content.managed-content.modpack-header',
|
||||
@@ -229,6 +228,7 @@ function contentOwnerLink(owner: ContentOwner): NonNullable<ContentOwner['link']
|
||||
|
||||
const { formatMessage } = useVIntl()
|
||||
const { handleError, addNotification } = injectNotificationManager()
|
||||
const appEvents = injectAppEvents()
|
||||
const { installingItems, installRevisionByInstance, installFailureRevisionByInstance } =
|
||||
injectContentInstall()
|
||||
const router = useRouter()
|
||||
@@ -955,7 +955,7 @@ async function bulkUpdateAllProjects(onProgress?: (status: BulkOperationStatus)
|
||||
message: formatMessage(messages.bulkUpdateResolvingVersions),
|
||||
waiting: true,
|
||||
})
|
||||
unlisten = await instance_bulk_update_progress_listener((progress) => {
|
||||
unlisten = appEvents.on('instance_bulk_update_progress', (progress) => {
|
||||
if (progress.instanceId !== instance.value.id) return
|
||||
onProgress(formatBulkUpdateProgress(progress))
|
||||
})
|
||||
@@ -1725,7 +1725,18 @@ const removeBeforeEach = router.beforeEach(() => {
|
||||
|
||||
let isUnmounted = false
|
||||
let unlistenDragDrop: UnlistenFn | null = null
|
||||
let unlistenInstances: UnlistenFn | null = null
|
||||
|
||||
useAppEvent('instance', async (event) => {
|
||||
if (
|
||||
instance.value &&
|
||||
event.instance_id === instance.value.id &&
|
||||
event.event === 'synced' &&
|
||||
instance.value.install_stage === 'installed' &&
|
||||
!isBulkOperating.value
|
||||
) {
|
||||
await initProjects()
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
void getCurrentWebview()
|
||||
@@ -1747,27 +1758,6 @@ onMounted(() => {
|
||||
unlistenDragDrop = unlisten
|
||||
})
|
||||
.catch(handleError)
|
||||
|
||||
void instance_listener(async (event: { event: string; instance_id: string }) => {
|
||||
if (
|
||||
instance.value &&
|
||||
event.instance_id === instance.value.id &&
|
||||
event.event === 'synced' &&
|
||||
instance.value.install_stage === 'installed' &&
|
||||
!isBulkOperating.value
|
||||
) {
|
||||
await initProjects()
|
||||
}
|
||||
})
|
||||
.then((unlisten) => {
|
||||
if (isUnmounted) {
|
||||
unlisten()
|
||||
return
|
||||
}
|
||||
|
||||
unlistenInstances = unlisten
|
||||
})
|
||||
.catch(handleError)
|
||||
})
|
||||
|
||||
watch(
|
||||
@@ -1803,6 +1793,5 @@ onUnmounted(() => {
|
||||
isUnmounted = true
|
||||
removeBeforeEach()
|
||||
unlistenDragDrop?.()
|
||||
unlistenInstances?.()
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user