Skip to content

Commit

Permalink
feat: tried to fix routing problem after opening file://
Browse files Browse the repository at this point in the history
  • Loading branch information
HuakunShen committed Oct 25, 2024
1 parent 10f6440 commit 14e248c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
4 changes: 0 additions & 4 deletions apps/desktop/components/forms/add-dev-ext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ onKeyStroke("Escape", (e) => {
navigateTo("/")
})
function onBack() {
navigateTo("/")
}
async function onUrlSubmit(data: z.infer<typeof urlFormSchema>) {
// data.url
// https://storage.huakun.tech/vscode-0.0.6.tgz
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ export const HTMLElementId = {
ActionPanelInputId: "action-panel-input",
WorkerExtInputId: "worker-ext-input"
}

export const DEEP_LINK_INSTALL_EXTENSION_WINDOW_LABEL = "main:deep-link-install-extension"
8 changes: 6 additions & 2 deletions apps/desktop/lib/init/deeplink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {
DEEP_LINK_PATH_STORE
} from "@kksh/api"
import { extname } from "@tauri-apps/api/path"
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"
import { getCurrentWebviewWindow, WebviewWindow } from "@tauri-apps/api/webviewWindow"
import { onOpenUrl } from "@tauri-apps/plugin-deep-link"
import { error } from "@tauri-apps/plugin-log"
import { emitRefreshDevExt } from "~/lib/utils/tauri-events"
import * as v from "valibot"
import { toast } from "vue-sonner"
import { DEEP_LINK_INSTALL_EXTENSION_WINDOW_LABEL } from "../constants"

const StorePathSearchParams = v.object({
identifier: v.optional(v.string())
Expand Down Expand Up @@ -79,7 +80,10 @@ export async function handleFileProtocol(parsedUrl: URL) {
case "kunkun":
// TODO: Handle file protocol, install extension from file (essentially a .tgz file)
const url = `/add-dev-ext?path=${encodeURIComponent(filePath)}`
navigateTo(url)
new WebviewWindow(DEEP_LINK_INSTALL_EXTENSION_WINDOW_LABEL, {
url
})
// navigateTo("/add-dev-ext")
break
default:
console.error("Unknown file extension:", fileExt)
Expand Down
10 changes: 9 additions & 1 deletion apps/desktop/pages/add-dev-ext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ import {
} from "@kksh/vue/form"
import { Input } from "@kksh/vue/input"
import { ArrowLeftIcon } from "@radix-icons/vue"
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"
import { open as openDialog } from "@tauri-apps/plugin-dialog"
import { exists } from "@tauri-apps/plugin-fs"
import { onKeyStroke } from "@vueuse/core"
import { DEEP_LINK_INSTALL_EXTENSION_WINDOW_LABEL } from "~/lib/constants"
import { installTarball } from "~/lib/utils/install"
import { useAppConfigStore } from "~/stores/appConfig"
// import { useForm } from "vee-validate"
import { toast } from "vue-sonner"
import { z } from "zod"
const appWindow = getCurrentWebviewWindow()
// const formSchema = z.object({
// filePath: z.string()
// })
Expand All @@ -39,7 +43,11 @@ onKeyStroke("Escape", (e) => {
})
function onBack() {
navigateTo("/")
if (appWindow.label !== "main") {
appWindow.close()
} else {
navigateTo("/")
}
}
// function onSubmit(e: Event) {
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function handleQuicklinkEnter() {
console.error("handleQuicklinkEnter error:", flatten<typeof CmdListItemValue>(parse.issues))
}
}
</script>
<template>
<div class="h-full grow">
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/pages/set-dev-ext-path.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { Button } from "@kksh/vue/button"
import { ArrowLeftIcon } from "@radix-icons/vue"
import { onKeyStroke } from "@vueuse/core"
const router = useRouter()
onKeyStroke("Escape", (e) => {
e.preventDefault()
onBack()
})
function onBack() {
navigateTo("/")
// navigateTo("/")
router.back()
}
</script>
<template>
Expand Down

0 comments on commit 14e248c

Please sign in to comment.