Skip to content

Commit

Permalink
Use flatpak XDG home dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
someone13574 committed May 18, 2024
1 parent 672de4c commit aaad2c7
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ mod linux {

#[cfg(feature = "flatpak")]
mod flatpak {
use std::ffi::OsString;
use std::path::PathBuf;
use std::process::Command;
use std::{env, process};
Expand All @@ -306,11 +307,9 @@ mod flatpak {
/// Restarts outside of the sandbox if currently inside
pub fn restart_to_host() {
if let Some(bin_dir) = get_flatpak_bin_dir() {
let mut args = vec![
"/usr/bin/flatpak-spawn".into(),
"--host".into(),
bin_dir.join("zed").into(),
];
let mut args = vec!["/usr/bin/flatpak-spawn".into(), "--host".into()];
args.append(&mut get_xdg_env_args());
args.push(bin_dir.join("zed").into());

let mut is_app_location_set = false;
for arg in &env::args_os().collect::<Vec<_>>()[1..] {
Expand All @@ -328,6 +327,19 @@ mod flatpak {
process::exit(1);
}
}

fn get_xdg_env_args() -> Vec<OsString> {
let keep_keys = vec![
"XDG_DATA_HOME",
"XDG_CONFIG_HOME",
"XDG_CACHE_HOME",
"XDG_STATE_HOME",
];
env::vars()
.filter(|(key, _)| keep_keys.contains(&key.as_str()))
.map(|(key, val)| format!("--env={}={}", key, val).into())
.collect()
}
}

// todo("windows")
Expand Down

0 comments on commit aaad2c7

Please sign in to comment.