mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
feat(gui-client/linux): debug command for enabling and disabling GUI autostart (#5361)
Refs #5118
This commit is contained in:
@@ -5,12 +5,19 @@ use crate::client;
|
||||
use anyhow::Result;
|
||||
|
||||
#[derive(clap::Subcommand)]
|
||||
pub enum Cmd {
|
||||
pub(crate) enum Cmd {
|
||||
CheckForUpdates,
|
||||
Crash,
|
||||
DnsChanges,
|
||||
Hostname,
|
||||
NetworkChanges,
|
||||
SetAutostart(SetAutostartArgs),
|
||||
}
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
pub(crate) struct SetAutostartArgs {
|
||||
#[clap(action=clap::ArgAction::Set)]
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
pub fn run(cmd: Cmd) -> Result<()> {
|
||||
@@ -20,7 +27,8 @@ pub fn run(cmd: Cmd) -> Result<()> {
|
||||
Cmd::DnsChanges => client::network_changes::run_dns_debug()?,
|
||||
Cmd::Hostname => hostname(),
|
||||
Cmd::NetworkChanges => client::network_changes::run_debug()?,
|
||||
};
|
||||
Cmd::SetAutostart(SetAutostartArgs { enabled }) => set_autostart(enabled)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -50,3 +58,10 @@ fn hostname() {
|
||||
hostname::get().ok().and_then(|x| x.into_string().ok())
|
||||
);
|
||||
}
|
||||
|
||||
fn set_autostart(enabled: bool) -> Result<()> {
|
||||
firezone_headless_client::debug_command_setup()?;
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(client::gui::set_autostart(enabled))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ mod os;
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
mod os;
|
||||
|
||||
pub(crate) use os::set_autostart;
|
||||
|
||||
pub(crate) type CtlrTx = mpsc::Sender<ControllerRequest>;
|
||||
|
||||
/// All managed state that we might need to access from odd places like Tauri commands.
|
||||
|
||||
@@ -1,6 +1,36 @@
|
||||
use anyhow::Result;
|
||||
use anyhow::{Context as _, Result};
|
||||
use tauri::api::notification::Notification;
|
||||
|
||||
pub(crate) async fn set_autostart(enabled: bool) -> Result<()> {
|
||||
let dir = dirs::config_local_dir()
|
||||
.context("Can't compute `config_local_dir`")?
|
||||
.join("autostart");
|
||||
let link = dir.join("firezone-client-gui.desktop");
|
||||
if enabled {
|
||||
tokio::fs::create_dir_all(&dir)
|
||||
.await
|
||||
.context("Can't create autostart dir")?;
|
||||
let target = std::path::Path::new("/usr/share/applications/firezone-client-gui.desktop");
|
||||
// If the link already exists, delete it
|
||||
tokio::fs::remove_file(&link).await.ok();
|
||||
tokio::fs::symlink(target, link)
|
||||
.await
|
||||
.context("Can't create autostart link")?;
|
||||
tracing::info!("Enabled autostart.");
|
||||
} else if tokio::fs::try_exists(&link) // I think this else-if is less intuitive, but Clippy insisted
|
||||
.await
|
||||
.context("Can't check if autostart link exists")?
|
||||
{
|
||||
tokio::fs::remove_file(&link)
|
||||
.await
|
||||
.context("Can't remove autostart link")?;
|
||||
tracing::info!("Disabled autostart.");
|
||||
} else {
|
||||
tracing::info!("Autostart is already disabled.");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Since clickable notifications don't work on Linux yet, the update text
|
||||
/// must be different on different platforms
|
||||
pub(crate) fn show_update_notification(
|
||||
|
||||
@@ -2,6 +2,11 @@ use super::{ControllerRequest, CtlrTx};
|
||||
use anyhow::{Context, Result};
|
||||
use connlib_shared::BUNDLE_ID;
|
||||
|
||||
#[allow(clippy::unused_async)]
|
||||
pub(crate) async fn set_autostart(_enabled: bool) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Since clickable notifications don't work on Linux yet, the update text
|
||||
/// must be different on different platforms
|
||||
pub(crate) fn show_update_notification(
|
||||
|
||||
@@ -41,12 +41,8 @@ sudo usermod -aG firezone-client "$USER"
|
||||
reboot
|
||||
```
|
||||
|
||||
To auto-start the Client when you log in, run these commands:
|
||||
|
||||
```bash
|
||||
mkdir -p "$HOME/.config/autostart"
|
||||
ln -s /usr/share/applications/firezone-client-gui.desktop "$HOME/.config/autostart"
|
||||
```
|
||||
To auto-start the Client when you log in, run
|
||||
`firezone-client-gui debug set-autostart true`
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -121,8 +117,7 @@ To export or clear your logs:
|
||||
|
||||
## Uninstalling
|
||||
|
||||
1. Remove the auto-start link:
|
||||
`rm --force "$HOME/.config/autostart/firezone-client-gui.desktop"`
|
||||
1. Remove the auto-start link: `firezone-client-gui debug set-autostart false`
|
||||
1. Quit `firezone-client-gui` if it's running.
|
||||
1. Remove the package: `sudo apt-get remove firezone-client-gui`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user