kunkun/packages/api/src/ui/server/security.ts
Huakun Shen ad30a8c3bb
fix: duplicate api calls from comlink (#27)
* refactor: replace comlink with kkrpc

* fix: import path in api pkg and btn styling in ui iframe page

* fix: fixed fetch API from kkRPC migrate

* refactor: replace comlink-stdio with kkrpc

* update deno lock

* bump @kksh/api

* update API version

* publish api pkg again to fix kkrpc version

* update pnpm lock

* dep: fix dependency problems

* dep: update deno.lock

* chore: remove 2 submodules

they were added only for integration development

* update pnpm lock

* fix: test template path

* format: with prettier

* downgrade next version

* ci: try to fix next build on windows

* try to fix CI

* Revert "try to fix CI"

This reverts commit b9c63c392f50f1d2d3ceec406e49b1af2348c740.

* upgrade tauri-api-adapter

* try to fix next

* remove templates from pnpm workspace

* update CI test

* publish @kksh/api with upgraded tauri-api-adapter to fix nextjs template
2024-11-19 05:57:31 -05:00

54 lines
1.8 KiB
TypeScript

import { Command, open } from "tauri-plugin-shellx-api"
import * as v from "valibot"
import { macSecurity } from "../../commands"
import { SecurityPermissionMap, type SecurityPermission } from "../../permissions"
import { checkPermission } from "../../utils/permission-check"
import { MacSecurityOptions, type ISecurity } from "../client"
export function constructSecurityAPI(permissions: SecurityPermission[]): ISecurity {
return {
mac: {
revealSecurityPane: (privacyOption?: MacSecurityOptions) => {
checkPermission<SecurityPermission>(
permissions,
SecurityPermissionMap.mac.revealSecurityPane
)
if (privacyOption) {
const parsedOption = v.parse(MacSecurityOptions, privacyOption)
return open(
`x-apple.systempreferences:com.apple.preference.security?Privacy_${parsedOption}`
)
} else {
return open("x-apple.systempreferences:com.apple.preference.security")
}
},
verifyFingerprint: async () => {
return macSecurity.verifyAuth()
},
requestScreenCapturePermission: async () => {
checkPermission<SecurityPermission>(
permissions,
SecurityPermissionMap.mac.requestScreenCapturePermission
)
return macSecurity.requestScreenCaptureAccess()
},
checkScreenCapturePermission: async () => {
checkPermission<SecurityPermission>(
permissions,
SecurityPermissionMap.mac.checkScreenCapturePermission
)
return macSecurity.checkScreenCaptureAccess()
},
resetPermission: (privacyOption: MacSecurityOptions) => {
const parsedOption = v.parse(MacSecurityOptions, privacyOption)
const cmd = Command.create("tccutil", ["reset", parsedOption, "sh.kunkun.desktop"])
return cmd.execute().then((res) => {
if (res.code !== 0) {
throw new Error(`Failed to reset permission: ${res.stderr}`)
}
})
}
}
}
}