-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Push error handling of
get_arch
outwards
- Loading branch information
1 parent
d50a3c9
commit 9fd34a6
Showing
4 changed files
with
71 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use mullvad_update::version::VersionArchitecture; | ||
|
||
/// The environment consists of globals and/or constants which need to be computed at runtime. | ||
pub struct Environment { | ||
pub architecture: mullvad_update::format::Architecture, | ||
} | ||
|
||
pub enum Error { | ||
/// Failed to get the host's CPU architecture. | ||
// TODO: Attach underlying error | ||
Arch, | ||
} | ||
|
||
impl Environment { | ||
/// Try to load the environment. | ||
pub fn load() -> Result<Self, Error> { | ||
let architecture = Self::get_arch()?; | ||
|
||
Ok(Environment { architecture }) | ||
} | ||
|
||
/// Try to map the host's CPU architecture to one of the CPU architectures the Mullvad VPN app | ||
/// supports. | ||
fn get_arch() -> Result<VersionArchitecture, Error> { | ||
let arch = talpid_platform_metadata::get_native_arch() | ||
.map_err(|_| Error::Arch)? | ||
.ok_or(Error::Arch)?; | ||
|
||
let arch = match arch { | ||
talpid_platform_metadata::Architecture::X86 => VersionArchitecture::X86, | ||
talpid_platform_metadata::Architecture::Arm64 => VersionArchitecture::Arm64, | ||
}; | ||
|
||
Ok(arch) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters