Huakun Shen ed87fc6c12
App Setup (#2)
* chore: add vendor submodules

* feat: add packages for db,ci,schema,api,jarvis cmds

* feat: add tauri-jarvis-plugin

* feat: implement extension commands list

* fix(desktop): import path errors after packages refactor

* chore: add self signed cert

* fix: prevent prerender for desktop

* fix(desktop): desktop sveltekit static build, use csr for dynamic route

* feat: add error handling page and components

* refactor: component lib

* refactor: move more types, functions and components out of desktop

* refactor(ui): more refactor

* refactor(ui): move store components to @kksh/ui

* ci: add CI for build & test

* refactor: rename @kksh/extensions to @kksh/extension

* ci: add 2 more ci

* ci: fix

* fix: CI env var

* chore: add changeset

* feat: implement extension store item detail view

* feat: implement extension store install, uninstall, upgrade

* format

* revert: upgradable logic, the new one doesn't work yet

* refactor: make @kksh/ui dependent only on @kksh/api

Reason: @kksh/ui may be published later for building website, all its dependency packages must be also published. To avoid trouble it should be standalone, depend only on packages already published

* refactor: cleanup

* fixed: some typescript error

* chore: got typedoc working on @kksh/api

* ci: disable manifest schema upload CI on push
2024-11-03 13:54:44 -05:00

59 lines
2.1 KiB
TypeScript

/**
* `tauri-api-adapter` contains a `constructEventApi()`.
* We don't use that one because it exposes raw `listen()` and `emit()`, which may expose too much power to the client.
* Instead in this project, we define a custom `IEventServer` interface and `constructEventApi()` function that
* only exposes a limited set of events.
*/
import { listen, TauriEvent } from "@tauri-apps/api/event"
import { type EventPermission } from "../../permissions"
import { EventPermissionMap } from "../../permissions/permission-map"
import { checkPermission } from "../../utils/permission-check"
import type { DragDropPayload, DragEnterPayload, DragOverPayload, IEvent } from "../client"
export function constructEventApi(permissions: EventPermission[]): IEvent {
return {
onDragDrop: (callback) => {
checkPermission<EventPermission>(permissions, EventPermissionMap.onDragDrop)
listen<DragDropPayload>(TauriEvent.DRAG_DROP, (e) => {
callback(e.payload)
})
},
onDragEnter: (callback) => {
checkPermission<EventPermission>(permissions, EventPermissionMap.onDragEnter)
listen<DragEnterPayload>(TauriEvent.DRAG_ENTER, (e) => {
callback(e.payload)
})
},
onDragLeave: (callback) => {
checkPermission<EventPermission>(permissions, EventPermissionMap.onDragLeave)
listen<null>(TauriEvent.DRAG_LEAVE, (e) => {
callback()
})
},
onDragOver: (callback) => {
checkPermission<EventPermission>(permissions, EventPermissionMap.onDragOver)
listen<DragOverPayload>(TauriEvent.DRAG_OVER, (e) => {
callback(e.payload)
})
},
onWindowBlur: (callback) => {
checkPermission<EventPermission>(permissions, EventPermissionMap.onWindowBlur)
listen<null>(TauriEvent.WINDOW_BLUR, (e) => {
callback()
})
},
onWindowCloseRequested: (callback) => {
checkPermission<EventPermission>(permissions, EventPermissionMap.onWindowCloseRequested)
listen<null>(TauriEvent.WINDOW_CLOSE_REQUESTED, (e) => {
callback()
})
},
onWindowFocus: (callback) => {
checkPermission<EventPermission>(permissions, EventPermissionMap.onWindowFocus)
listen<null>(TauriEvent.WINDOW_FOCUS, (e) => {
callback()
})
}
}
}