Skip to content

Commit

Permalink
refactor: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
HuakunShen committed Oct 25, 2024
1 parent e52237f commit 035b9ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
17 changes: 12 additions & 5 deletions apps/desktop/components/forms/add-dev-ext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,19 @@ async function onNpmPackageNameSubmit(data: z.infer<typeof npmPackageNameFormSch
toast.warning("Please set the dev extension path in the settings to install tarball extension")
return navigateTo("/set-dev-ext-path")
}
installFromNpmPackageName(data.name, appConfig.devExtensionPath).catch((err) => {
ElNotification.warning({
title: "Failed to install extension",
message: err
installFromNpmPackageName(data.name, appConfig.devExtensionPath)
.then(() => {
ElNotification.success({
title: "Success",
message: "Extension installed successfully"
})
})
.catch((err) => {
ElNotification.warning({
title: "Failed to install extension",
message: err
})
})
})
}
async function onPickLocalExtensionFolder() {
Expand Down
26 changes: 9 additions & 17 deletions apps/desktop/lib/utils/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,15 @@ export async function installDevExtensionDir(dirPath: string): Promise<ExtPackag
}

export async function installThroughNpmAPI(url: string, targetDir: string) {
return axios
.get(url)
.then((res) => {
const tarball = z.string().parse(res.data?.dist?.tarball)
console.log(tarball)
if (tarball) {
return installTarballUrl(tarball, targetDir)
} else {
ElMessage.error("Tarball Not Found")
}
})
.catch((error: any) => {
ElNotification.error({
title: "Fail to Install",
message: error
})
})
return axios.get(url).then((res) => {
const tarball = z.string().parse(res.data?.dist?.tarball)
console.log(tarball)
if (tarball) {
return installTarballUrl(tarball, targetDir)
} else {
ElMessage.error("Tarball Not Found")
}
})
}

export async function installFromNpmPackageName(name: string, targetDir: string) {
Expand Down
8 changes: 5 additions & 3 deletions apps/desktop/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { CommandEmpty, CommandGroup, CommandList } from "@/components/ui/command
import { getActiveElementNodeName } from "@/lib/utils/dom"
import { RPCChannel } from "@hk/comlink-stdio"
import { TauriShellStdio } from "@kksh/api"
import { Action as ActionnSchema } from "@kksh/api/models"
import { Action } from "@kksh/api/ui/worker"
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"
import { getCurrentWindow } from "@tauri-apps/api/window"
import { fetch } from "@tauri-apps/plugin-http"
Expand All @@ -21,6 +23,7 @@ import { useLastTimeStore } from "~/stores/lastTime"
import { findAllArgsInLink, useQuicklinkLoader } from "~/stores/quickLink"
import { useRemoteCmdStore } from "~/stores/remoteCmds"
import { useSystemCmdsStore } from "~/stores/systemCmds"
import { useAppUiStore } from "~/stores/ui"
import { ComboboxInput } from "radix-vue"
import { Command } from "tauri-plugin-shellx-api"
import type { EventEmitter, IOPayload, OutputEvents } from "tauri-plugin-shellx-api"
Expand All @@ -32,6 +35,7 @@ const builtinCmdStore = useBuiltInCmdStore()
const appsStore = useAppsLoaderStore()
const sysCmdsStore = useSystemCmdsStore()
const appStateStore = useAppStateStore()
const appUiStore = useAppUiStore()
const remoteCmdStore = useRemoteCmdStore()
const extStore = useExtensionStore()
// const devExtStore = useDevExtStore()
Expand Down Expand Up @@ -89,9 +93,7 @@ useListenToWindowFocus(() => {
})
onMounted(async () => {
// fetch("https://localhost:1566/info").then((res) => {
// console.log("res", res)
// }).catch(console.err)
appUiStore.setDefaultAction("Open")
if (appWindow.label !== "main") {
setTimeout(() => {
toast.error("Non-main window should not open this page.")
Expand Down

0 comments on commit 035b9ba

Please sign in to comment.