Skip to content

Commit

Permalink
feat: add kv api to @kksh/api package
Browse files Browse the repository at this point in the history
  • Loading branch information
HuakunShen committed Jan 5, 2025
1 parent 0e82b54 commit bac9a54
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
15 changes: 0 additions & 15 deletions apps/desktop/src/routes/app/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@
}
}}
/>
<Button
onclick={async () => {
await kv.set("test", Math.random().toString())
const value = await kv.get("test")
console.log(value)
}}
>
Set
</Button>
<Button
onclick={async () => {
const value = await kv.get("test")
console.log(value)
}}>Get</Button
>
<Command.Root
class={cn("h-screen rounded-lg border shadow-md")}
bind:value={$appState.highlightedCmd}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
toast,
// wrap,
type IComponent,
type IDb,
type WorkerExtension
} from "@kksh/api/ui/worker"
import { Button } from "@kksh/svelte5"
Expand Down
2 changes: 1 addition & 1 deletion packages/api/jsr.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://jsr.io/schema/config-file.v1.json",
"name": "@kunkun/api",
"version": "0.0.44",
"version": "0.0.47",
"license": "MIT",
"exports": {
".": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kksh/api",
"version": "0.0.46",
"version": "0.0.47",
"type": "module",
"exports": {
".": "./src/index.ts",
Expand Down
8 changes: 7 additions & 1 deletion packages/api/src/ui/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type {
} from "tauri-plugin-shellx-api"
import { EventEmitter, open as shellxOpen } from "tauri-plugin-shellx-api"
import * as v from "valibot"
import { type JarvisExtDB } from "../commands/db"
import { KV, type JarvisExtDB } from "../commands/db"
import type { fileSearch } from "../commands/fileSearch"
import { type AppInfo } from "../models/apps"
import type { LightMode, Position, Radius, ThemeColor } from "../models/styles"
Expand Down Expand Up @@ -182,6 +182,12 @@ export interface IDb {
update: typeof JarvisExtDB.prototype.update
}

export interface IKV {
get: typeof KV.prototype.get
set: typeof KV.prototype.set
exists: typeof KV.prototype.exists
}

export interface IFs {
readDir: typeof readDir
readFile: typeof readFile
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/ui/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
IDb,
IEvent,
IFs,
IKV,
IOpen,
IPath,
ISecurity,
Expand All @@ -47,13 +48,13 @@ import type { WorkerExtension } from "./ext"

// export { expose, wrap } from "@huakunshen/comlink"
export { WorkerExtension } from "./ext"
export type { IDb } from "../client"
/**
* For the APIs annotated with "inherit from tauri-api-adapter", they inherit the client API completely from tauri-api-adapter
* There may be server API changes for them, but the client API can be inherited
*/
type API = {
db: IDb // for kunkun
kv: IKV // for kunkun
system: ISystem // for kunkun
open: IOpen // for kunkun
clipboard: IClipboard // inherit from tauri-api-adapter
Expand Down Expand Up @@ -93,6 +94,7 @@ export const toast = constructToastAPI(api.toast)
export const updownload = constructUpdownloadAPI(api.updownload)
export const {
db,
kv,
os,
clipboard,
dialog,
Expand Down
11 changes: 11 additions & 0 deletions packages/extensions/demo-worker-template-ext/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {
app,
Child,
clipboard,
db,
expose,
Form,
fs,
Icon,
IconEnum,
kv,
List,
Markdown,
open,
Expand Down Expand Up @@ -51,6 +53,15 @@ class ExtensionTemplate extends WorkerExtension {
clipboard.readText().then((text) => {
console.log("Clipboard text:", text)
})
kv.exists("test").then((exists) => {
console.log("KV exists:", exists)
})
kv.set("test", Math.random().toString()).then(() => {
return kv.get("test").then((value) => {
console.log("KV value:", value)
})
})

// console.log("Check screen capture permission:", await security.mac.checkScreenCapturePermission())
// await security.mac.revealSecurityPane("AllFiles")
// console.log(await security.mac.verifyFingerprint())
Expand Down

0 comments on commit bac9a54

Please sign in to comment.