From 796cd3bca6ed154c47d9d1d446db1e5e1047307c Mon Sep 17 00:00:00 2001 From: panekj Date: Mon, 22 Aug 2022 08:20:09 +0200 Subject: [PATCH] fix: differentiate between stable/nightly/debug --- lapce-data/src/proxy.rs | 20 ++++++++++++++++---- lapce-proxy/src/directory.rs | 8 ++++++-- lapce-proxy/src/lib.rs | 24 ++++++++++++++++-------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/lapce-data/src/proxy.rs b/lapce-data/src/proxy.rs index 4e94a0a5..024a6a2f 100644 --- a/lapce-data/src/proxy.rs +++ b/lapce-data/src/proxy.rs @@ -310,9 +310,17 @@ fn start_remote(&self, remote: impl Remote) -> Result<()> { // ! Below paths have to be synced with what is // ! returned by Config::proxy_directory() let remote_proxy_path = match platform { - Windows => format!("%HOMEDRIVE%%HOMEPATH%\\AppData\\Local\\lapce\\{APPLICATION_NAME}\\data\\proxy"), - Darwin => format!("~/Library/Application Support/dev.lapce.{APPLICATION_NAME}/proxy"), - _ => format!("~/.local/share/{APPLICATION_NAME}/proxy").to_lowercase(), + Windows => format!( + "%HOMEDRIVE%%HOMEPATH%\\AppData\\Local\\lapce\\{}\\data\\proxy", + *APPLICATION_NAME + ), + Darwin => format!( + "~/Library/Application Support/dev.lapce.{}/proxy", + *APPLICATION_NAME + ), + _ => { + format!("~/.local/share/{}/proxy", *APPLICATION_NAME).to_lowercase() + } }; let remote_proxy_file = match platform { @@ -342,7 +350,11 @@ fn start_remote(&self, remote: impl Remote) -> Result<()> { .ok_or_else(|| anyhow!("can't find proxy directory"))? .join(&proxy_filename); if !local_proxy_file.exists() { - let url = format!("https://github.com/lapce/lapce/releases/download/{}/{proxy_filename}.gz", if VERSION.eq("nightly") { VERSION.to_string() } else { format!("v{}", *VERSION) }); + let url = format!("https://github.com/lapce/lapce/releases/download/{}/{proxy_filename}.gz", match *VERSION { + "nightly" | "debug" => "nightly".to_string(), + _ => format!("v{}", *VERSION), + }); + log::debug!(target: "lapce_data::proxy::start_remote", "proxy download URI: {url}"); let mut resp = reqwest::blocking::get(url).expect("request failed"); if resp.status().is_success() { let mut out = std::fs::File::create(&local_proxy_file) diff --git a/lapce-proxy/src/directory.rs b/lapce-proxy/src/directory.rs index 61669822..5f7844a4 100644 --- a/lapce-proxy/src/directory.rs +++ b/lapce-proxy/src/directory.rs @@ -7,12 +7,16 @@ pub struct Directory {} impl Directory { + fn project_dirs() -> Option { + ProjectDirs::from("dev", "lapce", *APPLICATION_NAME) + } + // Get path of local data directory // Local data directory differs from data directory // on some platforms and is not transferred across // machines pub fn data_local_directory() -> Option { - match ProjectDirs::from("dev", "lapce", APPLICATION_NAME) { + match Self::project_dirs() { Some(dir) => { let dir = dir.data_local_dir(); if !dir.exists() { @@ -89,7 +93,7 @@ pub fn plugins_directory() -> Option { // Config directory contain only configuration files pub fn config_directory() -> Option { - match ProjectDirs::from("dev", "lapce", APPLICATION_NAME) { + match Self::project_dirs() { Some(dir) => { let dir = dir.config_dir(); if !dir.exists() { diff --git a/lapce-proxy/src/lib.rs b/lapce-proxy/src/lib.rs index 1914f8bf..873b322f 100644 --- a/lapce-proxy/src/lib.rs +++ b/lapce-proxy/src/lib.rs @@ -20,21 +20,29 @@ }; use once_cell::sync::Lazy; -#[cfg(debug_assertions)] -pub const APPLICATION_NAME: &str = "Lapce-debug"; +pub static APPLICATION_NAME: Lazy<&str> = Lazy::new(application_name); -#[cfg(not(debug_assertions))] -pub const APPLICATION_NAME: &str = "Lapce"; +fn application_name() -> &'static str { + if cfg!(debug_assertions) { + "Lapce-Debug" + } else if option_env!("RELEASE_TAG_NAME") + .unwrap_or("") + .starts_with("nightly") + { + "Lapce-Nightly" + } else { + "Lapce-Stable" + } +} pub static VERSION: Lazy<&str> = Lazy::new(version); fn version() -> &'static str { if cfg!(debug_assertions) { "debug" - } else if option_env!("RELEASE_TAG_NAME").is_some() - && option_env!("RELEASE_TAG_NAME") - .unwrap() - .starts_with("nightly") + } else if option_env!("RELEASE_TAG_NAME") + .unwrap_or("") + .starts_with("nightly") { option_env!("RELEASE_TAG_NAME").unwrap() } else {