Skip to content

Commit

Permalink
feat: improve deno command path alias translation
Browse files Browse the repository at this point in the history
Translate path alias for deno command
  • Loading branch information
HuakunShen committed Sep 13, 2024
1 parent 913cc55 commit 81b7b3e
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 44 deletions.
14 changes: 7 additions & 7 deletions apps/desktop/lib/utils/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { gt } from "semver"

export async function checkUpdateAndInstall() {
const update = await check()
console.log("update", update)
if (update?.available) {
const confirmUpdate = await confirm(
`A new version ${update.version} is available. Do you want to install and relaunch?`
Expand All @@ -26,16 +27,17 @@ export async function checkUpdateAndInstall() {
}
}

export async function checkSingleExtensionUpdate(installedExt: ExtPackageJsonExtra) {
const extStore = useExtStore()
export async function checkSingleExtensionUpdate(
installedExt: ExtPackageJsonExtra,
autoupgrade: boolean
) {
const response = await gqlClient.query<FindLatestExtQuery, FindLatestExtQueryVariables>({
query: FindLatestExtDocument,
variables: {
identifier: installedExt.kunkun.identifier
}
})
const exts = response.data.ext_publishCollection?.edges
console.log(exts)
if (!exts || exts?.length <= 0) {
return
}
Expand All @@ -48,11 +50,9 @@ export async function checkSingleExtensionUpdate(installedExt: ExtPackageJsonExt
}
}

export async function checkExtensionUpdate() {
console.log("checkExtensionUpdate")

export async function checkExtensionUpdate(autoupgrade: boolean = false) {
const extStore = useExtStore()
extStore.manifests.forEach(async (ext) => {
await checkSingleExtensionUpdate(ext)
await checkSingleExtensionUpdate(ext, autoupgrade)
})
}
1 change: 0 additions & 1 deletion apps/desktop/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ListItem from "@/components/MainSearch/list-item.vue"
import { CommandEmpty, CommandGroup, CommandList } from "@/components/ui/command"
import { $searchTermSync, setSearchTerm } from "@/lib/stores/appState"
import { getActiveElementNodeName } from "@/lib/utils/dom"
import { version } from "@kksh/api/package.json"
import { useStore } from "@nanostores/vue"
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"
import { getCurrentWindow } from "@tauri-apps/api/window"
Expand Down
178 changes: 177 additions & 1 deletion extensions/demo-worker-template-ext/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions extensions/demo-worker-template-ext/main.ts

This file was deleted.

6 changes: 0 additions & 6 deletions extensions/demo-worker-template-ext/main_test.ts

This file was deleted.

6 changes: 3 additions & 3 deletions extensions/demo-worker-template-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"allow": [
{
"path": "$EXTENSION/src/deno-script.ts",
"env": ["HOME", "CWD"],
"read": "*",
"write": "*"
"env": ["npm_package_config_libvips", "CWD"],
"ffi": "*",
"read": ["$DESKTOP"]
}
]
},
Expand Down
18 changes: 6 additions & 12 deletions extensions/demo-worker-template-ext/src/deno-script.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { parseArgs } from "jsr:@std/cli/parse-args"
import sharp from "npm:sharp"

console.log("deno-script")
// make a file on desktop with deno
// const desktopPath = path.join(os.homedir(), "Desktop")
// fs.writeFileSync(path.join(desktopPath, "deno-script.txt"), "deno-script")
// how to get desktop path
const HOME = Deno.env.get("HOME")
// print cwd
console.log("CWD:", Deno.cwd())
await Deno.writeTextFile(`./hello2.txt`, "Hello World!");
// await Deno.writeTextFile(`${HOME}/Desktop/hello.txt`, "Hello World!");
const args = parseArgs(Deno.args)
console.log(args)
// await Deno.writeTextFile("./hello.txt", "Hello World!")
// console.log("File written to ./hello.txt")

const input = args.i
const output = args.o

sharp(input).blur(10).resize(300, 300).toFile(output)
12 changes: 7 additions & 5 deletions extensions/demo-worker-template-ext/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ class ExtensionTemplate extends WorkerExtension {
// console.log(res.stdout)
console.log("echo $PWD", await shell.executeBashScript("echo $PWD"))
// open.file("$EXTENSION/src/deno-script.ts")
const denoCmd = shell.createDenoCommand("$EXTENSION/src/deno-script.ts", ["--name=huakun"], {
allowAllWrite: true,
allowEnv: ["HOME", "CWD"],
allowAllRead: true,
cwd: "/Users/hacker/Desktop"
const desktopPath = await path.desktopDir()
const denoCmd = shell.createDenoCommand("$EXTENSION/src/deno-script.ts", ["-i=./avatar.png", "-o=./avatar-blur.jpeg"], {
allowEnv: ["npm_package_config_libvips", "CWD"],
allowRead: ["$DESKTOP"],
allowAllFfi: true,
cwd: desktopPath
})
const denoRes = await denoCmd.execute()
console.log("denoRes.stdout", denoRes.stdout)
console.log("denoRes.stderr", denoRes.stderr)
console.log(denoRes)

const extPath = await path.extensionDir()
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ export type {
INotification,
IOs,
IPath,
IShell,
// IShell,
ISystemInfo,
IUpdownload
// IFetch
} from "tauri-api-adapter"
export type { ISystem, IToast, IUiWorker, IUiIframe, IDb, IFs, IOpen, IEvent } from "../ui/client"
export type { IShell } from "./api/shell"
26 changes: 26 additions & 0 deletions packages/api/src/ui/server/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,42 @@ export async function verifyDenoCmdPermission(
)
)

if (config.allowRead) {
config.allowRead = await Promise.all(
config.allowRead.map(async (p) => await translateScopeToPath(p, extensionDir))
)
}

if (config.denyRead) {
config.denyRead = await Promise.all(
config.denyRead.map(async (p) => await translateScopeToPath(p, extensionDir))
)
}

if (config.allowWrite) {
config.allowWrite = await Promise.all(
config.allowWrite.map(async (p) => await translateScopeToPath(p, extensionDir))
)
}

if (config.denyWrite) {
config.denyWrite = await Promise.all(
config.denyWrite.map(async (p) => await translateScopeToPath(p, extensionDir))
)
}

denyRead = await Promise.all(
denyRead.map(async (p) =>
pathStartsWithAlias(p) ? await translateScopeToPath(p, extensionDir) : p
)
)

allowWrite = await Promise.all(
allowWrite.map(async (p) =>
pathStartsWithAlias(p) ? await translateScopeToPath(p, extensionDir) : p
)
)

denyWrite = await Promise.all(
denyWrite.map(async (p) =>
pathStartsWithAlias(p) ? await translateScopeToPath(p, extensionDir) : p
Expand Down

0 comments on commit 81b7b3e

Please sign in to comment.