Skip to content

Commit

Permalink
Move is_paid to Optional linkup config state (#95)
Browse files Browse the repository at this point in the history
This makes is_paid backwards compatible with old state files
  • Loading branch information
ostenbom authored Jun 3, 2024
1 parent c0d3f05 commit 16ab58e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion linkup-cli/src/background_booting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ impl BackgroundServices for RealBackgroundServices {

wait_till_ok(format!("{}linkup-check", local_url))?;

if state.should_use_tunnel() && !state.is_paid {
let should_run_free = state.linkup.is_paid.is_none() || !state.linkup.is_paid.unwrap();
if state.should_use_tunnel() && should_run_free {
if is_tunnel_running().is_err() {
println!("Starting tunnel...");
let tunnel_manager = RealTunnelManager {};
Expand Down
4 changes: 2 additions & 2 deletions linkup-cli/src/local_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub struct LocalState {
pub linkup: LinkupState,
pub domains: Vec<StorableDomain>,
pub services: Vec<LocalService>,
pub is_paid: bool,
}

impl LocalState {
Expand Down Expand Up @@ -90,6 +89,7 @@ pub struct LinkupState {
pub config_path: String,
pub remote: Url,
pub tunnel: Option<Url>,
pub is_paid: Option<bool>,
pub cache_routes: Option<Vec<String>>,
}

Expand Down Expand Up @@ -201,6 +201,7 @@ pub fn config_to_state(
};

let linkup = LinkupState {
is_paid: Some(is_paid),
session_name: String::new(),
session_token: random_token,
config_path,
Expand Down Expand Up @@ -235,7 +236,6 @@ pub fn config_to_state(
linkup,
domains,
services,
is_paid,
}
}

Expand Down
5 changes: 3 additions & 2 deletions linkup-cli/src/services/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn try_run_tunnel(state: &LocalState) -> Result<Url, CliError> {
},
}

let is_paid = state.is_paid;
let is_paid = state.linkup.is_paid.is_some() && state.linkup.is_paid.unwrap();
let session_name = state.linkup.session_name.clone();

let tunnel_url_re =
Expand Down Expand Up @@ -174,7 +174,8 @@ fn try_run_tunnel(state: &LocalState) -> Result<Url, CliError> {

fn daemonized_tunnel_child(state: &LocalState) {
let url = format!("http://localhost:{}", LINKUP_LOCALSERVER_PORT);
let cmd_args: Vec<&str> = match state.is_paid {
let is_paid = state.linkup.is_paid.is_some() && state.linkup.is_paid.unwrap();
let cmd_args: Vec<&str> = match is_paid {
true => vec!["tunnel", "run", state.linkup.session_name.as_str()],
false => vec!["tunnel", "--url", url.as_str()],
};
Expand Down
2 changes: 1 addition & 1 deletion linkup-cli/src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ mod tests {
config_path: "/tmp/home/.linkup/config".to_string(),
remote: Url::parse("http://localhost:9066").unwrap(),
tunnel: None,
is_paid: Some(true),
cache_routes: None,
}
},
services: vec![],
domains: vec![],
is_paid: true,
};
}

Expand Down

0 comments on commit 16ab58e

Please sign in to comment.