Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions resources-linux/defguard-client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ Desktop client for managing WireGuard VPN connections
%{__install} -m 755 src-tauri/target/release/defguard-client %{buildroot}/%{_bindir}/
%{__install} -m 755 src-tauri/target/release/defguard-service %{buildroot}/%{_sbindir}/
%{__install} -m 644 src-tauri/target/release/resources/icons/tray-32x32-black.png %{buildroot}/%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-black.png
%{__install} -m 644 src-tauri/target/release/resources/icons/tray-32x32-black-active.png %{buildroot}/%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-black-active.png
%{__install} -m 644 src-tauri/target/release/resources/icons/tray-32x32-color.png %{buildroot}/%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-color.png
%{__install} -m 644 src-tauri/target/release/resources/icons/tray-32x32-color-active.png %{buildroot}/%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-color-active.png
%{__install} -m 644 src-tauri/target/release/resources/icons/tray-32x32-gray.png %{buildroot}/%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-gray.png
%{__install} -m 644 src-tauri/target/release/resources/icons/tray-32x32-gray-active.png %{buildroot}/%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-gray-active.png
%{__install} -m 644 src-tauri/target/release/resources/icons/tray-32x32-white.png %{buildroot}/%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-white.png
%{__install} -m 644 src-tauri/target/release/resources/icons/tray-32x32-white-active.png %{buildroot}/%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-white-active.png
%{__install} -m 644 resources-linux/defguard-service.service %{buildroot}/%{_prefix}/lib/systemd/system/
%{__install} -m 644 resources-linux/defguard-client.desktop %{buildroot}/%{_datadir}/applications/defguard-client.desktop
%{__install} -m 644 src-tauri/icons/128x128.png %{buildroot}/%{_datadir}/icons/hicolor/128x128/apps/defguard-client.png
Expand Down Expand Up @@ -54,9 +58,13 @@ systemctl daemon-reload
%{_bindir}/defguard-client
%{_sbindir}/defguard-service
%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-black.png
%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-black-active.png
%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-color.png
%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-color-active.png
%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-gray.png
%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-gray-active.png
%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-white.png
%{_prefix}/lib/defguard-client/resources/icons/tray-32x32-white-active.png
%{_prefix}/lib/systemd/system/defguard-service.service
%{_datadir}/applications/defguard-client.desktop
%{_datadir}/icons/hicolor/128x128/apps/defguard-client.png
Expand Down
40 changes: 5 additions & 35 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ use crate::{
CommonConnection, CommonConnectionInfo, CommonLocationStats, ConnectionType,
};

#[derive(Clone, Serialize)]
pub(crate) struct Payload<'a> {
pub(crate) message: &'a str,
}

// Create new WireGuard interface
#[tauri::command(async)]
pub async fn connect(
Expand Down Expand Up @@ -137,12 +132,7 @@ pub async fn disconnect(
"Emitting the event informing the frontend about the disconnection from \
{connection_type} {name}({location_id})"
);
handle.emit(
EventKey::ConfigChanged.into(),
Payload {
message: "Created new connection",
},
)?;
handle.emit(EventKey::ConnectionChanged.into(), ())?;
debug!("Event emitted successfully");
stop_log_watcher_task(&handle, &connection.interface_name)?;
reload_tray_menu(&handle).await;
Expand Down Expand Up @@ -774,12 +764,7 @@ pub async fn update_location_routing(
location.route_all_traffic = route_all_traffic;
location.save(&*DB_POOL).await?;
debug!("Location routing updated for location {name}(ID: {location_id})");
handle.emit(
EventKey::LocationUpdate.into(),
Payload {
message: "Location routing updated",
},
)?;
handle.emit(EventKey::LocationUpdate.into(), ())?;
Ok(())
} else {
error!(
Expand All @@ -793,12 +778,7 @@ pub async fn update_location_routing(
tunnel.route_all_traffic = route_all_traffic;
tunnel.save(&*DB_POOL).await?;
info!("Tunnel routing updated for tunnel {location_id}");
handle.emit(
EventKey::LocationUpdate.into(),
Payload {
message: "Tunnel routing updated",
},
)?;
handle.emit(EventKey::LocationUpdate.into(), ())?;
Ok(())
} else {
error!("Couldn't update tunnel routing: tunnel with id {location_id} not found.");
Expand Down Expand Up @@ -882,12 +862,7 @@ pub async fn update_tunnel(mut tunnel: Tunnel<Id>, handle: AppHandle) -> Result<
debug!("Received tunnel configuration to update: {tunnel:?}");
tunnel.save(&*DB_POOL).await?;
info!("The tunnel {tunnel} configuration has been updated.");
handle.emit(
EventKey::LocationUpdate.into(),
Payload {
message: "Tunnel saved",
},
)?;
handle.emit(EventKey::LocationUpdate.into(), ())?;
Ok(())
}

Expand All @@ -896,12 +871,7 @@ pub async fn save_tunnel(tunnel: Tunnel<NoId>, handle: AppHandle) -> Result<(),
debug!("Received tunnel configuration to save: {tunnel:?}");
let tunnel = tunnel.save(&*DB_POOL).await?;
info!("The tunnel {tunnel} configuration has been saved.");
handle.emit(
EventKey::LocationUpdate.into(),
Payload {
message: "Tunnel saved",
},
)?;
handle.emit(EventKey::LocationUpdate.into(), ())?;
Ok(())
}

Expand Down
35 changes: 10 additions & 25 deletions src-tauri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use windows_service::{

use crate::{
appstate::AppState,
commands::{LocationInterfaceDetails, Payload},
commands::LocationInterfaceDetails,
database::{
models::{
connection::{ActiveConnection, Connection},
Expand Down Expand Up @@ -638,12 +638,7 @@ pub(crate) async fn handle_connection_for_location(
.await;

debug!("Sending event informing the frontend that a new connection has been created.");
handle.emit(
EventKey::ConfigChanged.into(),
Payload {
message: "Created new connection",
},
)?;
handle.emit(EventKey::ConnectionChanged.into(), ())?;
debug!("Event informing the frontend that a new connection has been created sent.");

// spawn log watcher
Expand Down Expand Up @@ -675,12 +670,7 @@ pub(crate) async fn handle_connection_for_tunnel(
.await;

debug!("Sending event informing the frontend that a new connection has been created.");
handle.emit(
EventKey::ConfigChanged.into(),
Payload {
message: "Created new connection",
},
)?;
handle.emit(EventKey::ConnectionChanged.into(), ())?;
debug!("Event informing the frontend that a new connection has been created sent.");

// spawn log watcher
Expand Down Expand Up @@ -887,7 +877,7 @@ async fn check_connection(
) -> Result<(), Error> {
let appstate = app_handle.state::<AppState>();
let interface_name = get_interface_name(name);
let service_name = format!("WireGuardTunnel${}", interface_name);
let service_name = format!("WireGuardTunnel${interface_name}");
let service = match service_manager.open_service(&service_name, ServiceAccess::QUERY_STATUS) {
Ok(service) => service,
Err(windows_service::Error::Winapi(err))
Expand Down Expand Up @@ -940,12 +930,7 @@ async fn check_connection(
.await;

debug!("Sending event informing the frontend that a new connection has been created.");
app_handle.emit(
EventKey::ConnectionChanged.into(),
Payload {
message: "Created new connection",
},
)?;
app_handle.emit(EventKey::ConnectionChanged.into(), ())?;
debug!("Event informing the frontend that a new connection has been created sent.");

debug!("Spawning service log watcher for {connection_type} {name}...");
Expand Down Expand Up @@ -974,12 +959,12 @@ pub async fn sync_connections(app_handle: &AppHandle) -> Result<(), Error> {
ServiceManager::local_computer(None::<&str>, ServiceManagerAccess::CONNECT).map_err(
|err| {
error!(
"Failed to open service control manager while trying to sync client's connections \
with the host state: {err}"
);
"Failed to open service control manager while trying to sync client's \
connections with the host state: {err}"
);
Error::InternalError(
"Failed to open service control manager while trying to sync client's
connections with the host state"
"Failed to open service control manager while trying to sync client's \
connections with the host state"
.to_string(),
)
},
Expand Down
Loading