feat(wallet): app version check (#3308)

This commit is contained in:
Pierre Dommerc
2023-04-17 15:12:26 +02:00
committed by GitHub
parent 4aeac1acd2
commit de64da8e20
11 changed files with 73 additions and 7 deletions
+12
View File
@@ -12,3 +12,15 @@ pub struct AppEnv {
pub SHOW_TERMINAL: Option<String>,
pub ENABLE_QA_MODE: Option<String>,
}
#[cfg_attr(feature = "generate-ts", derive(ts_rs::TS))]
#[cfg_attr(
feature = "generate-ts",
ts(export, export_to = "nym-wallet/src/types/rust/AppVersion.ts")
)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
pub struct AppVersion {
pub current_version: String,
pub latest_version: String,
pub is_update_available: bool,
}
+2
View File
@@ -124,6 +124,8 @@ pub enum BackendError {
SignatureError(String),
#[error("Unable to open a new window")]
NewWindowError,
#[error("Failed to check for application update")]
CheckAppVersionError,
#[error(transparent)]
WalletError {
+2
View File
@@ -8,6 +8,7 @@ use tauri::{Manager, Menu};
use nym_mixnet_contract_common::{Gateway, MixNode};
use crate::menu::AddDefaultSubmenus;
use crate::operations::app;
use crate::operations::help;
use crate::operations::mixnet;
use crate::operations::nym_api;
@@ -35,6 +36,7 @@ fn main() {
tauri::Builder::default()
.manage(WalletState::default())
.invoke_handler(tauri::generate_handler![
app::version::check_version,
mixnet::account::add_account_for_password,
mixnet::account::archive_wallet_file,
mixnet::account::connect_with_mnemonic,
@@ -0,0 +1 @@
pub mod version;
@@ -0,0 +1,29 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::error::BackendError;
use nym_wallet_types::app::AppVersion;
#[tauri::command]
pub async fn check_version(handle: tauri::AppHandle) -> Result<AppVersion, BackendError> {
log::info!(">>> Getting app version info");
let res = tauri::updater::builder(handle)
.check()
.await
.map(|u| AppVersion {
current_version: u.current_version().to_string(),
latest_version: u.latest_version().to_owned(),
is_update_available: u.is_update_available(),
})
.map_err(|e| {
log::error!("An error ocurred while checking for app update {}", e);
BackendError::CheckAppVersionError
})?;
log::debug!(
"<<< update available: [{}], current version {}, latest version {}",
res.is_update_available,
res.current_version,
res.latest_version
);
Ok(res)
}
@@ -1,6 +1,7 @@
// Copyright 2021-2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
pub mod app;
pub mod help;
pub(crate) mod helpers;
pub mod mixnet;
@@ -1,18 +1,17 @@
import React, { useContext, useEffect, useState } from 'react';
import { Stack, Typography } from '@mui/material';
import { Button, Stack, Typography } from '@mui/material';
import { checkUpdate } from '@tauri-apps/api/updater';
import { AppContext } from '../../context';
import { checkVersion } from '../../requests';
const AppVersion = () => {
const [updateAvailable, setUpdateAvailable] = useState(false);
const { appVersion } = useContext(AppContext);
const updateCheck = async () => {
const update = await checkUpdate();
if (update.shouldUpdate && update.manifest) {
const res = await checkVersion();
if (res.is_update_available) {
setUpdateAvailable(true);
} else {
setUpdateAvailable(false);
}
};
@@ -20,6 +19,12 @@ const AppVersion = () => {
updateCheck();
}, [appVersion]);
const updateHandler = async () => {
// despite the name, this will spawn an external native window with
// an embedded "download and install" flow
checkUpdate();
};
return (
<Stack direction="column" alignItems="flex-end" gap={1}>
<Stack direction="row" gap={1} alignItems="center">
@@ -29,9 +34,9 @@ const AppVersion = () => {
<Typography>{`Nym Wallet ${appVersion}`}</Typography>
</Stack>
{updateAvailable && (
<Typography color="primary" fontWeight={600}>
<Button variant="text" onClick={() => updateHandler()}>
Update available
</Typography>
</Button>
)}
</Stack>
);
+4
View File
@@ -0,0 +1,4 @@
import { invokeWrapper } from './wrapper';
import { AppVersion } from '../types/rust/AppVersion';
export const checkVersion = async () => invokeWrapper<AppVersion>('check_version');
+1
View File
@@ -1,3 +1,4 @@
export * from './app';
export * from './account';
export * from './actions';
export * from './contract';
+7
View File
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface AppVersion {
current_version: string;
latest_version: string;
is_update_available: boolean;
}
+2
View File
@@ -29,6 +29,7 @@ use nym_types::vesting::{OriginalVestingResponse, PledgeData, VestingAccountInfo
use nym_vesting_contract_common::Period;
use nym_wallet_types::admin::TauriContractStateParams;
use nym_wallet_types::app::AppEnv;
use nym_wallet_types::app::AppVersion;
use nym_wallet_types::interval::Interval;
use nym_wallet_types::network::Network;
use nym_wallet_types::network_config::{Validator, ValidatorUrl, ValidatorUrls};
@@ -126,6 +127,7 @@ fn main() {
// nym-wallet
do_export!(AppEnv);
do_export!(AppVersion);
do_export!(Interval);
do_export!(Network);
do_export!(TauriContractStateParams);