feat: add device sharing metadata application

This commit is contained in:
mesalogo
2026-10-01 01:31:44 +08:00
parent 0a02a17cb6
commit a3b41bf2b1
28 changed files with 853 additions and 33 deletions
+24
View File
@@ -0,0 +1,24 @@
import { ipcMain, type BrowserWindow } from 'electron'
import { ipcChannels } from '../shared/ipc-channels'
import { sharingIdSchema, sharingPublicationDraftSchema, sharingSettingsInputSchema } from '../shared/device-sharing-contracts'
import { assertTrustedSender } from './trusted-ipc-sender'
import type { DeviceSharingService } from './device-sharing-service'
export function registerDeviceSharingIpc(window: BrowserWindow, service: DeviceSharingService): () => void {
const handlers = {
[ipcChannels.sharingSettingsGet]: () => service.getSettings(),
[ipcChannels.sharingSettingsSave]: (input: unknown) => service.saveSettings(sharingSettingsInputSchema.parse(input)),
[ipcChannels.sharingRegister]: () => service.registerDevice(),
[ipcChannels.sharingCatalog]: () => service.getCatalog(),
[ipcChannels.sharingPublish]: (input: unknown) => service.publish(sharingPublicationDraftSchema.parse(input)),
[ipcChannels.sharingRevoke]: (input: unknown) => service.revoke(sharingIdSchema.parse(input))
}
for (const [channel, handler] of Object.entries(handlers)) {
ipcMain.removeHandler(channel)
ipcMain.handle(channel, (event, input: unknown) => {
assertTrustedSender(event, window)
return handler(input)
})
}
return () => { for (const channel of Object.keys(handlers)) ipcMain.removeHandler(channel) }
}