summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-daemon/src/main.rs4
-rw-r--r--mullvad-daemon/src/settings.rs18
2 files changed, 21 insertions, 1 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index abfc83b764..d306aaf747 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -334,6 +334,10 @@ impl Daemon {
/// Consume the `Daemon` and run the main event loop. Blocks until an error happens or a
/// shutdown event is received.
pub fn run(mut self) -> Result<()> {
+ if self.settings.get_autoconnect() {
+ info!("Automatically connecting since autoconnect is turned on");
+ self.set_target_state(TargetState::Secured)?;
+ }
while let Ok(event) = self.rx.recv() {
self.handle_event(event)?;
if self.shutdown && self.state == TunnelState::NotRunning {
diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs
index 4622db15ce..b11b80017a 100644
--- a/mullvad-daemon/src/settings.rs
+++ b/mullvad-daemon/src/settings.rs
@@ -35,8 +35,10 @@ static SETTINGS_FILE: &str = "settings.json";
pub struct Settings {
account_token: Option<String>,
relay_settings: RelaySettings,
- /// If the app should allow communication with private (LAN) networks.
+ /// If the daemon should allow communication with private (LAN) networks.
allow_lan: bool,
+ /// If the daemon should connect the VPN tunnel directly on start or not.
+ auto_connect: bool,
/// Options that should be applied to tunnels of a specific type regardless of where the relays
/// might be located.
tunnel_options: TunnelOptions,
@@ -51,6 +53,7 @@ impl Default for Settings {
tunnel: Constraint::Any,
}),
allow_lan: false,
+ auto_connect: false,
tunnel_options: TunnelOptions::default(),
}
}
@@ -155,6 +158,19 @@ impl Settings {
}
}
+ pub fn get_auto_connect(&self) -> bool {
+ self.auto_connect
+ }
+
+ pub fn set_auto_connect(&mut self, auto_connect: bool) -> Result<bool> {
+ if auto_connect != self.auto_connect {
+ self.auto_connect = auto_connect;
+ self.save().map(|_| true)
+ } else {
+ Ok(false)
+ }
+ }
+
pub fn set_openvpn_mssfix(&mut self, openvpn_mssfix: Option<u16>) -> Result<bool> {
if self.tunnel_options.openvpn.mssfix != openvpn_mssfix {
self.tunnel_options.openvpn.mssfix = openvpn_mssfix;