Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"desktop:dev": "tauri dev --config src-tauri/tauri-dev.conf.json",
"desktop:dev:debug": "DEBUG=true yarn desktop:dev",
"desktop:build:dev": "DEBUG=true tauri build --config src-tauri/tauri-dev.conf.json",
"desktop:build:flatpak": "DEBUG=true tauri build --config src-tauri/tauri-flatpak.conf.json",
"desktop:build:flatpak": "tauri build --config src-tauri/tauri-flatpak.conf.json",
"desktop:build:flatpak:debug": "DEBUG=true tauri build --config src-tauri/tauri-flatpak.conf.json --debug",
"desktop:build:debug": "tauri build --debug",
"desktop:build": "tauri build",
"format:check": "prettier --check .",
Expand Down
5,696 changes: 5,696 additions & 0 deletions desktop/src-tauri/gen/schemas/linux-schema.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions desktop/src-tauri/src/install_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::path::Path;
use std::str::Lines;
use std::{env, path::PathBuf};
use thiserror::Error;
use std::fs;
use log::{info,debug};

#[derive(Error, Debug)]
#[allow(dead_code)]
Expand Down Expand Up @@ -92,6 +94,11 @@ fn install(_app_handle: AppHandle, force: bool) -> Result<(), InstallCLIError> {
let mut user_local_bin = home;
user_local_bin.push(".local/bin/devpod");

// create .local/bin if necessary
if let Some(path) = user_local_bin.clone().parent() {
fs::create_dir_all(path);
}

target_paths.push(user_local_bin);
target_paths.push(user_bin);
}
Expand Down
10 changes: 10 additions & 0 deletions desktop/src-tauri/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use log::error;
use serde::Serialize;
use tauri_plugin_store::StoreExt;
use ts_rs::TS;
use std::env;

const SETTINGS_FILE_NAME: &str = ".settings.json";

Expand Down Expand Up @@ -86,6 +87,15 @@ impl Settings {
return false;
}

let mut is_flatpak = false;
match env::var("FLATPAK_ID") {
Ok(_) => is_flatpak = true,
Err(_) => is_flatpak = false,
}
if is_flatpak {
return false
}

store
.unwrap()
.get("autoUpdate")
Expand Down
4 changes: 3 additions & 1 deletion desktop/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ class Client {
public async isCLIInstalled(): Promise<Result<boolean>> {
try {
// we're in a flatpak, we need to check in other paths.
if (import.meta.env.TAURI_IS_FLATPAK === "true") {
const isFlatpak = await this.getEnv("FLATPAK_ID")
if (isFlatpak) {
this.log("debug", "Running in flatpak, checking ~/.local/bin on the host");
const home_dir = await this.getEnv("HOME")
// this will throw if doesn't exist
const exists = await invoke<boolean>("file_exists", {
Expand Down
45 changes: 31 additions & 14 deletions desktop/src/client/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {
Command as ShellCommand,
} from "@tauri-apps/plugin-shell"
import { debug, ErrorTypeCancelled, isError, Result, ResultError, Return, sleep } from "../lib"
import { DEVPOD_BINARY, DEVPOD_FLAG_OPTION, DEVPOD_UI_ENV_VAR } from "./constants"
import { DEVPOD_BINARY, DEVPOD_FLAG_OPTION, DEVPOD_UI_ENV_VAR, DEVPOD_ADDITIONAL_ENV_VARS } from "./constants"
import { TStreamEvent } from "./types"
import { TAURI_SERVER_URL } from "./tauriClient"
import * as log from "@tauri-apps/plugin-log"
import { invoke } from "@tauri-apps/api/core"

export type TStreamEventListenerFn = (event: TStreamEvent) => void
export type TEventListener<TEventName extends string> = Parameters<
Expand All @@ -33,6 +35,8 @@ export class Command implements TCommand<ChildProcess<string>> {
private childProcess?: Child
private args: string[]
private cancelled = false
private isFlatpak: boolean | undefined
private extraEnvVars: Record<string, string>

public static ADDITIONAL_ENV_VARS: string = ""
public static HTTP_PROXY: string = ""
Expand All @@ -41,7 +45,7 @@ export class Command implements TCommand<ChildProcess<string>> {

constructor(args: string[]) {
debug("commands", "Creating Devpod command with args: ", args)
const extraEnvVars = Command.ADDITIONAL_ENV_VARS.split(",")
this.extraEnvVars = Command.ADDITIONAL_ENV_VARS.split(",")
.map((envVarStr) => envVarStr.split("="))
.reduce(
(acc, pair) => {
Expand All @@ -57,30 +61,37 @@ export class Command implements TCommand<ChildProcess<string>> {

// set proxy related environment variables
if (Command.HTTP_PROXY) {
extraEnvVars["HTTP_PROXY"] = Command.HTTP_PROXY
this.extraEnvVars["HTTP_PROXY"] = Command.HTTP_PROXY
}
if (Command.HTTPS_PROXY) {
extraEnvVars["HTTPS_PROXY"] = Command.HTTPS_PROXY
this.extraEnvVars["HTTPS_PROXY"] = Command.HTTPS_PROXY
}
if (Command.NO_PROXY) {
extraEnvVars["NO_PROXY"] = Command.NO_PROXY
this.extraEnvVars["NO_PROXY"] = Command.NO_PROXY
}

// allows the CLI to detect if commands have been invoked from the UI
extraEnvVars[DEVPOD_UI_ENV_VAR] = "true"

if (import.meta.env.TAURI_IS_FLATPAK === "true") {
this.sidecarCommand = ShellCommand.create("run-path-devpod-wrapper", args, {
env: { ...extraEnvVars, ["FLATPAK_ID"]: "sh.loft.devpod" },
})
} else {
this.sidecarCommand = ShellCommand.sidecar(DEVPOD_BINARY, args, { env: extraEnvVars })
}
this.extraEnvVars[DEVPOD_UI_ENV_VAR] = "true"
this.sidecarCommand = ShellCommand.sidecar(DEVPOD_BINARY, args, { env: this.extraEnvVars })
this.args = args
}

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

public async run(): Promise<Result<ChildProcess<string>>> {
try {
// Run once to check with the rust backend if we are running inside the flatpak sandbox
// This informs the CLI wrapper to use flatpak-spawn to escape the sandbox and export this.extraEnvVars
if (this.isFlatpak === undefined) {
this.isFlatpak = await this.getEnv("FLATPAK_ID")
if (this.isFlatpak) {
this.extraEnvVars["FLATPAK_ID"] = "sh.loft.devpod"
this.extraEnvVars[DEVPOD_ADDITIONAL_ENV_VARS] = recordToCSV(this.extraEnvVars)
this.sidecarCommand = ShellCommand.sidecar(DEVPOD_BINARY, this.args, { env: this.extraEnvVars })
}
}
const rawResult = await this.sidecarCommand.execute()
debug("commands", `Result for command with args ${this.args}:`, rawResult)

Expand Down Expand Up @@ -232,3 +243,9 @@ export function serializeRawOptions(
): string[] {
return Object.entries(rawOptions).map(([key, value]) => flag + `=${key}=${value}`)
}

function recordToCSV(record: Record<string, string>): string {
return Object.entries(record)
.map(([key, value]) => `${key}=${value}`)
.join(',');
}
1 change: 1 addition & 0 deletions desktop/src/client/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ export const DEVPOD_FLAG_GIT_SIGNING_KEY = "--git-ssh-signing-key"
export const DEVPOD_FLAG_FORCE_BROWSER = "--force-browser"

export const DEVPOD_UI_ENV_VAR = "DEVPOD_UI"
export const DEVPOD_ADDITIONAL_ENV_VARS = "DEVPOD_ADDITIONAL_ENV_VARS"
Loading