Skip to content

Commit bf3eeb4

Browse files
committed
Decouple app updater/downloader from installer-downloader frontend
1 parent 207c584 commit bf3eeb4

19 files changed

+83
-109
lines changed

Cargo.lock

+16-60
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ members = [
2727
"mullvad-setup",
2828
"mullvad-types",
2929
"mullvad-types/intersection-derive",
30+
"mullvad-update",
3031
"mullvad-version",
3132
"talpid-core",
3233
"talpid-dbus",

installer-downloader/Cargo.toml

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[package]
22
name = "installer-downloader"
3-
description = """
4-
A secure minimal web installer for the Mullvad app
5-
"""
3+
description = "A secure minimal web installer for the Mullvad app"
64
authors.workspace = true
75
repository.workspace = true
86
license.workspace = true
@@ -22,14 +20,11 @@ windows-sys = { version = "0.52.0", features = ["Win32_System", "Win32_System_Li
2220

2321
[dependencies]
2422
anyhow = "1.0"
25-
pgp = "0.14.0"
26-
reqwest = { version = "0.12.9", features = ["blocking", "json"] }
27-
serde = { workspace = true, features = ["derive"] }
28-
serde_json = { workspace = true }
2923
tokio = { version = "1", features = ["full"] }
30-
image = { version = "0.25.5", default-features = false, features = ["png"] }
3124
async-trait = "0.1"
3225

26+
mullvad-update = { path = "../mullvad-update" }
27+
3328
[target.'cfg(target_os = "windows")'.dependencies]
3429
native-windows-gui = { version = "1.0.12", features = ["image-decoder"] }
3530

installer-downloader/src/cacao_impl/delegate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex};
33
use cacao::{control::Control, layout::Layout};
44

55
use super::ui::{Action, AppWindow};
6-
use crate::controller::{AppDelegate, AppDelegateQueue};
6+
use crate::delegate::{AppDelegate, AppDelegateQueue};
77

88
impl AppDelegate for AppWindow {
99
type Queue = Queue;

installer-downloader/src/controller/controller.rs installer-downloader/src/controller.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
//! This module implements the actual logic performed by different UI components.
22
3-
use super::{AppDelegate, AppDelegateQueue};
3+
use crate::delegate::{AppDelegate, AppDelegateQueue};
4+
use crate::ui_downloader::{UiAppDownloader, UiProgressUpdater};
45

5-
use crate::{
6+
use mullvad_update::{
67
api::{self, VersionInfoProvider},
78
app::{self, AppDownloaderFactory, AppDownloaderParameters},
89
};
910

1011
use std::future::Future;
1112
use tokio::sync::{mpsc, oneshot};
1213

13-
use super::ui_downloader::{UiAppDownloader, UiProgressUpdater};
14-
1514
/// Actions handled by an async worker task in [handle_action_messages].
1615
enum TaskMessage {
1716
SetVersionInfo(api::VersionInfo),
@@ -22,6 +21,19 @@ enum TaskMessage {
2221
/// See the [module-level docs](self).
2322
pub struct AppController {}
2423

24+
/// Public entry function for registering a [AppDelegate].
25+
pub fn initialize_controller<T: AppDelegate + 'static>(delegate: &mut T) {
26+
use mullvad_update::api::LatestVersionInfoProvider;
27+
use mullvad_update::app::HttpAppDownloader;
28+
29+
// App downloader (factory) to use
30+
type DownloaderFactory<T> = HttpAppDownloader<UiProgressUpdater<T>, UiProgressUpdater<T>>;
31+
// Version info provider to use
32+
type VersionInfoProvider = LatestVersionInfoProvider;
33+
34+
AppController::initialize::<_, DownloaderFactory<T>, VersionInfoProvider>(delegate)
35+
}
36+
2537
impl AppController {
2638
/// Initialize [AppController] using the provided delegate.
2739
///

installer-downloader/src/controller/mod.rs installer-downloader/src/delegate.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
//! Framework-agnostic module that hooks up a UI to actions
22
3-
mod controller;
4-
mod ui_downloader;
5-
6-
pub use ui_downloader::UiProgressUpdater;
7-
8-
use crate::{api::LatestVersionInfoProvider, app::HttpAppDownloader};
3+
pub use crate::ui_downloader::UiProgressUpdater;
94

105
/// Trait implementing high-level UI actions
116
pub trait AppDelegate {
@@ -60,15 +55,3 @@ pub trait AppDelegate {
6055
pub trait AppDelegateQueue<T: ?Sized>: Send {
6156
fn queue_main<F: FnOnce(&mut T) + 'static + Send>(&self, callback: F);
6257
}
63-
64-
pub use controller::AppController;
65-
66-
/// Public entry function for registering a [AppDelegate].
67-
pub fn initialize_controller<T: AppDelegate + 'static>(delegate: &mut T) {
68-
// App downloader (factory) to use
69-
type DownloaderFactory<T> = HttpAppDownloader<UiProgressUpdater<T>, UiProgressUpdater<T>>;
70-
// Version info provider to use
71-
type VersionInfoProvider = LatestVersionInfoProvider;
72-
73-
controller::AppController::initialize::<_, DownloaderFactory<T>, VersionInfoProvider>(delegate)
74-
}

installer-downloader/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
pub mod api;
2-
pub mod app;
31
pub mod controller;
4-
pub mod fetch;
5-
pub mod verify;
2+
pub mod delegate;
3+
pub mod ui_downloader;

installer-downloader/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
22
use installer_downloader::controller;
3+
use installer_downloader::delegate;
34

45
#[cfg(target_os = "macos")]
56
mod cacao_impl;

installer-downloader/src/controller/ui_downloader.rs installer-downloader/src/ui_downloader.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
//! This module hooks up [AppDelegate]s to arbitrary implementations of [AppDownloader] and
22
//! [fetch::ProgressUpdater].
33
4-
use super::{AppDelegate, AppDelegateQueue};
5-
use crate::{app::AppDownloader, fetch};
4+
use crate::delegate::{AppDelegate, AppDelegateQueue};
5+
use mullvad_update::{
6+
app::{self, AppDownloader},
7+
fetch,
8+
};
69

710
/// [AppDownloader] that delegates the actual work to some underlying `downloader` and uses it to
811
/// update a UI.
@@ -28,7 +31,7 @@ impl<Delegate: AppDelegate, Downloader: AppDownloader + Send + 'static>
2831
impl<Delegate: AppDelegate, Downloader: AppDownloader + Send + 'static> AppDownloader
2932
for UiAppDownloader<Delegate, Downloader>
3033
{
31-
async fn download_signature(&mut self) -> Result<(), crate::app::DownloadError> {
34+
async fn download_signature(&mut self) -> Result<(), app::DownloadError> {
3235
if let Err(error) = self.downloader.download_signature().await {
3336
self.queue.queue_main(move |self_| {
3437
self_.set_status_text("ERROR: Failed to retrieve signature.");
@@ -41,7 +44,7 @@ impl<Delegate: AppDelegate, Downloader: AppDownloader + Send + 'static> AppDownl
4144
}
4245
}
4346

44-
async fn download_executable(&mut self) -> Result<(), crate::app::DownloadError> {
47+
async fn download_executable(&mut self) -> Result<(), app::DownloadError> {
4548
match self.downloader.download_executable().await {
4649
Ok(()) => {
4750
self.queue.queue_main(move |self_| {
@@ -63,7 +66,7 @@ impl<Delegate: AppDelegate, Downloader: AppDownloader + Send + 'static> AppDownl
6366
}
6467
}
6568

66-
async fn verify(&mut self) -> Result<(), crate::app::DownloadError> {
69+
async fn verify(&mut self) -> Result<(), app::DownloadError> {
6770
match self.downloader.verify().await {
6871
Ok(()) => {
6972
self.queue.queue_main(move |self_| {

installer-downloader/src/winapi_impl/delegate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use native_windows_gui::{self as nwg, Event};
55
use windows_sys::Win32::UI::WindowsAndMessaging::PostMessageW;
66

77
use super::ui::{AppWindow, QUEUE_MESSAGE};
8-
use crate::controller::{AppDelegate, AppDelegateQueue};
8+
use crate::delegate::{AppDelegate, AppDelegateQueue};
99

1010
impl AppDelegate for AppWindow {
1111
type Queue = Queue;

installer-downloader/src/winapi_impl/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use native_windows_gui as nwg;
22

3-
use crate::controller::{AppDelegate, AppDelegateQueue};
3+
use crate::delegate::{AppDelegate, AppDelegateQueue};
44

55
mod delegate;
66
mod ui;

installer-downloader/tests/controller.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
//! Tests for integrations between UI controller and other components
22
3-
use installer_downloader::api::{Version, VersionInfo, VersionInfoProvider};
4-
use installer_downloader::app::{
3+
use installer_downloader::controller::AppController;
4+
use installer_downloader::delegate::{AppDelegate, AppDelegateQueue, UiProgressUpdater};
5+
use mullvad_update::api::{Version, VersionInfo, VersionInfoProvider};
6+
use mullvad_update::app::{
57
AppDownloader, AppDownloaderFactory, AppDownloaderParameters, DownloadError,
68
};
7-
use installer_downloader::controller::{
8-
AppController, AppDelegate, AppDelegateQueue, UiProgressUpdater,
9-
};
10-
use installer_downloader::fetch::ProgressUpdater;
9+
use mullvad_update::fetch::ProgressUpdater;
1110
use std::sync::{Arc, LazyLock, Mutex};
1211
use std::time::Duration;
1312
use std::vec::Vec;

mullvad-update/Cargo.toml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "mullvad-update"
3+
description = "Support functions for securely installing or updating Mullvad VPN"
4+
authors.workspace = true
5+
repository.workspace = true
6+
license.workspace = true
7+
edition.workspace = true
8+
rust-version.workspace = true
9+
10+
[lints]
11+
workspace = true
12+
13+
[dependencies]
14+
anyhow = "1.0"
15+
pgp = "0.14.0"
16+
reqwest = { version = "0.12.9", features = ["blocking", "json"] }
17+
serde = { workspace = true, features = ["derive"] }
18+
serde_json = { workspace = true }
19+
tokio = { version = "1", features = ["full"] }
20+
async-trait = "0.1"
File renamed without changes.
File renamed without changes.
File renamed without changes.

mullvad-update/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Support functions for securely installing or updating Mullvad VPN
2+
3+
pub mod api;
4+
pub mod app;
5+
pub mod fetch;
6+
pub mod verify;

installer-downloader/src/verify.rs mullvad-update/src/verify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub trait AppVerifier: 'static + Clone {
2020
pub struct PgpVerifier;
2121

2222
impl PgpVerifier {
23-
const SIGNING_PUBKEY: &[u8] = include_bytes!("mullvad-code-signing.gpg");
23+
const SIGNING_PUBKEY: &[u8] = include_bytes!("../mullvad-code-signing.gpg");
2424
}
2525

2626
impl AppVerifier for PgpVerifier {

0 commit comments

Comments
 (0)