Skip to content

Commit

Permalink
fix(desktop): fix throwing promise in flatpak lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbreuninger committed Jun 13, 2024
1 parent 07fe40e commit 589bb54
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 60 deletions.
108 changes: 55 additions & 53 deletions desktop/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,40 @@ import { Command as DevPodCommand } from "./command"
type TChannels = {
event:
| Readonly<{
type: "ShowToast"
message: string
title: string
status: NonNullable<UseToastOptions["status"]>
}>
type: "ShowToast"
message: string
title: string
status: NonNullable<UseToastOptions["status"]>
}>
| Readonly<{ type: "ShowDashboard" }>
| Readonly<{ type: "CommandFailed" }>
| Readonly<{
type: "OpenWorkspace"
workspace_id: string | null
provider_id: string | null
ide: string | null
source: string
}>
| Readonly<{
type: "ImportWorkspace"
workspace_id: string
workspace_uid: string
devpod_pro_host: string
project: string
options: Record<string, string> | null
}>
| Readonly<{
type: "SetupPro"
host: string
accessKey: string | null
options: Record<string, string> | null
}>
| Readonly<{ type: "CommandFailed" }>
| Readonly<{
type: "OpenWorkspace"
workspace_id: string | null
provider_id: string | null
ide: string | null
source: string
}>
| Readonly<{
type: "ImportWorkspace"
workspace_id: string
workspace_uid: string
devpod_pro_host: string
project: string
options: Record<string, string> | null
}>
| Readonly<{
type: "SetupPro"
host: string
accessKey: string | null
options: Record<string, string> | null
}>
}
type TChannelName = keyof TChannels
type TClientEventListener<TChannel extends TChannelName> = (payload: TChannels[TChannel]) => void
type TClientSettings = Pick<
TSettings,
"debugFlag" | "additionalCliFlags" | "dotfilesURL" | "additionalEnvVars"
TSettings,
"debugFlag" | "additionalCliFlags" | "dotfilesURL" | "additionalEnvVars"
>
export type TPlatform = Awaited<ReturnType<typeof os.platform>>
export type TArch = Awaited<ReturnType<typeof os.arch>>
Expand Down Expand Up @@ -226,18 +226,20 @@ class Client {
}
}

public async getEnv(name: string) {
return await invoke("get_env", { name });
public async getEnv(name: string): Promise<boolean> {
return invoke<boolean>("get_env", { name })
}

public async isCLIInstalled(): Promise<Result<boolean>> {
try {
// we're in a flatpak, we need to check in other paths.
const isflatpak = await this.getEnv("FLATPAK_ID");
const isflatpak = await this.getEnv("FLATPAK_ID")
if (isflatpak) {
const home_dir = await this.getEnv("HOME");
const home_dir = await this.getEnv("HOME")
// this will throw if doesn't exist
const exists = await invoke("file_exists", {filepath: home_dir+"/.local/bin/devpod" }) as unknown as boolean;
const exists = await invoke<boolean>("file_exists", {
filepath: home_dir + "/.local/bin/devpod",
})

return Return.Value(exists)
}
Expand Down Expand Up @@ -303,25 +305,25 @@ class Client {
// Synchronize promise state with update operation
await new Promise((res, rej) => {
updater
.onUpdaterEvent((event) => {
if (event.status === "ERROR") {
unsubscribe?.()
rej(event.error)

return
}

if (event.status === "DONE") {
unsubscribe?.()
res(undefined)

return
}
})
.then(async (u) => {
unsubscribe = u
await updater.installUpdate()
})
.onUpdaterEvent((event) => {
if (event.status === "ERROR") {
unsubscribe?.()
rej(event.error)

return
}

if (event.status === "DONE") {
unsubscribe?.()
res(undefined)

return
}
})
.then(async (u) => {
unsubscribe = u
await updater.installUpdate()
})
})

return Return.Ok()
Expand Down
15 changes: 8 additions & 7 deletions desktop/src/client/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { debug, isError } from "../lib"
import { Result, ResultError, Return } from "../lib/result"
import { DEVPOD_BINARY, DEVPOD_FLAG_OPTION, DEVPOD_UI_ENV_VAR } from "./constants"
import { TStreamEvent } from "./types"
import { invoke } from "@tauri-apps/api"
import { client } from "./client"

export type TStreamEventListenerFn = (event: TStreamEvent) => void
export type TEventListener<TEventName extends string> = Parameters<
Expand Down Expand Up @@ -36,13 +36,14 @@ export class Command implements TCommand<ChildProcess> {
return { ...acc, [key]: value }
}, {})

let isflatpak = false;
try {
isflatpak = invoke("get_env", { name: "FLAPTAK_ID" }) as unknown as boolean;
} catch {
isflatpak = false;
}
const isflatpak = false
// try {
// // isflatpak = client.getEnv("FLAPTAK_ID")
// } catch {
// isflatpak = false
// }

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (isflatpak) {
this.sidecarCommand = new ShellCommand("run-path-devpod-wrapper", args, {
env: {
Expand Down

0 comments on commit 589bb54

Please sign in to comment.