Skip to content

Commit

Permalink
chore(update): update modal added (#754)
Browse files Browse the repository at this point in the history
Co-authored-by: Stuart Woodbury <stuartwoodbury@protonmail.ch>
Co-authored-by: Phill Wisniewski <93608357+phillsatellite@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Luis Cardeña <35935591+luisecm@users.noreply.github.com>
Co-authored-by: Matt Wisniewski <infamousvaguerat@gmail.com>
Co-authored-by: Sara Tavares <29093946+stavares843@users.noreply.github.com>
  • Loading branch information
7 people authored Apr 30, 2023
1 parent c22b62b commit 3c4b056
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 24 deletions.
10 changes: 10 additions & 0 deletions common/locales/en-US/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ uplink = Uplink
.check-for-updates = Check for updates
.download-update = Download Update
updates = Updates
.title = Uplink has an update available. Follow these steps to download and install the latest update.
.instruction1 = 1. Download the update from our release page.
.instruction2 = 2. Close Uplink.
.instruction3 = 3. Run the installer. The older version of uplink will be overwritten, leaving your account intact.
.instruction4 = 4. Open Uplink and start chatting again!
.instruction5 = *We are going to streamline this process in a future update.
.button-label = Pick Download Folder
.download-label = Download Update
warning-messages = Warning Messages
.please-enter-at-least = Please enter at least
.maximum-of = Maximum of
Expand Down
2 changes: 1 addition & 1 deletion kit/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub mod nav;

pub mod indicator;

pub mod modal;
pub mod toast;

pub mod user;
pub mod user_image;
pub mod user_image_group;
Expand Down
47 changes: 47 additions & 0 deletions kit/src/components/modal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use common::icons::outline::Shape;
use dioxus::prelude::*;

use crate::elements::button::Button;

#[derive(Props)]
pub struct Props<'a> {
children: Element<'a>,
on_dismiss: EventHandler<'a, ()>,
}

#[allow(non_snake_case)]
pub fn Modal<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
cx.render(rsx!(
div {
class: "modal-wrapper",
onclick: move |_| cx.props.on_dismiss.call(()),
div {
class: "modal",
onclick: move |evt| {
evt.stop_propagation();
},
div {
class: "modal-content",
div {
class: "modal-head",
Button {
onpress: move |_| {
cx.props.on_dismiss.call(());
},
icon: Shape::XMark
},
},
div {
class: "model-body",
rsx!(cx.props.children.as_ref()),
},


},



}
}
))
}
49 changes: 49 additions & 0 deletions kit/src/components/modal/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

.modal-wrapper {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 10;
min-height: 300px;
display: flex;
border: 1px solid black;
justify-content: center; /* align item horizontally */
align-items: center; /* align item vertically */
// this was copied over from Popup from an old version of uplink. not sure how much is necessary
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
transition: blur 0.2s;
background: var(--theme-semi-transparent);

.modal {
width: 70%;
height: 70%;
background: var(--background);
border: 1px solid var(--border-color);
border-radius: 10px;
opacity:1;
cursor: default;
}
}

.modal-content {
display: flex;
flex-direction: column;
}

.model-body {
flex: auto;
padding: 25px;
}

.modal-head {
margin: 3px;
margin-left: auto;
}

.modal-content .modal-head .btn-wrap {
height: var(--titlebar-height);
width: var(--titlebar-height);
}
23 changes: 14 additions & 9 deletions ui/src/components/settings/sub_pages/about.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::PathBuf;
use std::process::Command;

use common::language::get_local_text;
Expand All @@ -10,9 +11,8 @@ use kit::elements::{button::Button, Appearance};

use warp::logging::tracing::log;

use crate::utils::auto_updater::{
get_download_dest, DownloadProgress, DownloadState, SoftwareDownloadCmd,
};
use crate::get_download_modal;
use crate::utils::auto_updater::{DownloadProgress, DownloadState, SoftwareDownloadCmd};
use crate::{
components::settings::SettingSection,
utils::{self, auto_updater::GitHubRelease},
Expand Down Expand Up @@ -77,15 +77,20 @@ pub fn AboutPage(cx: Scope) -> Element {
appearance: Appearance::Secondary,
icon: Icon::ArrowDown,
onpress: move |_| {
if let Some(dest) = get_download_dest() {
download_state.write().stage = DownloadProgress::Pending;
download_state.write().destination = Some(dest.clone());
update_button_loading.set(true);
download_ch.send(SoftwareDownloadCmd(dest));
}
download_state.write().stage = DownloadProgress::PickFolder;
}
})
}
DownloadProgress::PickFolder => rsx!(get_download_modal {
on_dismiss: move |_| {
download_state.write().stage = DownloadProgress::Idle;
},
on_submit: move |dest: PathBuf| {
download_state.write().stage = DownloadProgress::Pending;
download_state.write().destination = Some(dest.clone());
download_ch.send(SoftwareDownloadCmd(dest));
}
}),
DownloadProgress::Pending => {
rsx!(Button {
key: "{pending_key}",
Expand Down
94 changes: 83 additions & 11 deletions ui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]
#![allow(unused_variables)]
#![cfg_attr(feature = "production_mode", windows_subsystem = "windows")]
// the above macro will make uplink be a "window" application instead of a "console" application for Windows.

Expand All @@ -17,8 +19,10 @@ use extensions::UplinkExtension;
use futures::channel::oneshot;
use futures::StreamExt;
use kit::components::context_menu::{ContextItem, ContextMenu};
use kit::components::modal::Modal;
use kit::components::nav::Route as UIRoute;
use kit::components::topbar_controls::Topbar_Controls;
use kit::elements::button::Button;
use kit::elements::Appearance;
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -53,7 +57,7 @@ use crate::layouts::storage::{FilesLayout, DRAG_EVENT};
use crate::layouts::unlock::UnlockLayout;

use crate::utils::auto_updater::{
get_download_dest, DownloadProgress, DownloadState, SoftwareDownloadCmd, SoftwareUpdateCmd,
DownloadProgress, DownloadState, SoftwareDownloadCmd, SoftwareUpdateCmd,
};

use crate::window_manager::WindowManagerCmdChannels;
Expand Down Expand Up @@ -896,23 +900,17 @@ fn get_update_icon(cx: Scope) -> Element {
ContextItem {
text: get_local_text("uplink.update-menu-download"),
onpress: move |_| {
if let Some(dest) = get_download_dest() {
download_state.write().stage = DownloadProgress::Pending;
download_state.write().destination = Some(dest.clone());
download_ch.send(SoftwareDownloadCmd(dest));
}
download_state.write().stage = DownloadProgress::PickFolder;

}
}
)),
div {
id: "update-available",
aria_label: "update-available",
onclick: move |_| {
if let Some(dest) = get_download_dest() {
download_state.write().stage = DownloadProgress::Pending;
download_state.write().destination = Some(dest.clone());
download_ch.send(SoftwareDownloadCmd(dest));
}
download_state.write().stage = DownloadProgress::PickFolder;

},
IconElement {
icon: common::icons::solid::Shape::ArrowDownCircle,
Expand All @@ -921,6 +919,16 @@ fn get_update_icon(cx: Scope) -> Element {
}
}
)),
DownloadProgress::PickFolder => cx.render(rsx!(get_download_modal {
on_dismiss: move |_| {
download_state.write().stage = DownloadProgress::Idle;
},
on_submit: move |dest: PathBuf| {
download_state.write().stage = DownloadProgress::Pending;
download_state.write().destination = Some(dest.clone());
download_ch.send(SoftwareDownloadCmd(dest));
}
})),
DownloadProgress::Pending => cx.render(rsx!(div {
id: "update-available",
class: "topbar-item",
Expand Down Expand Up @@ -966,6 +974,70 @@ fn get_update_icon(cx: Scope) -> Element {
}
}

#[inline_props]
pub fn get_download_modal<'a>(
cx: Scope<'a>,
on_submit: EventHandler<'a, PathBuf>,
on_dismiss: EventHandler<'a, ()>,
) -> Element<'a> {
let download_location: &UseState<Option<PathBuf>> = use_state(cx, || None);

let dl = download_location.current();
let disp_download_location = dl
.as_ref()
.clone()
.map(|x| x.to_string_lossy().to_string())
.unwrap_or_default();

cx.render(rsx!(Modal {
on_dismiss: move |_| on_dismiss.call(()),
children: cx.render(rsx!(
div {
class: "download-modal disp-flex col",
h1 {
get_local_text("updates.title")
},
ul {
class: "instruction-list",
li {
get_local_text("updates.instruction1")
},
li {
Button {
text: get_local_text("updates.download-label"),
aria_label: get_local_text("updates.download-label"),
appearance: Appearance::Secondary,
onpress: |_| {
let _ = open::that("https://github.com/Satellite-im/Uplink/releases/latest");
}
}
},
li {
get_local_text("updates.instruction2")
},
li {
get_local_text("updates.instruction3")
},
li {
get_local_text("updates.instruction4")
}
},
p {
get_local_text("updates.instruction5")
},
// dl.as_ref().clone().map(|dest| rsx!(
// Button {
// text: "download installer".into(),
// onpress: move |_| {
// on_submit.call(dest.clone());
// }
// }
// ))
}
))
}))
}

fn get_logger(cx: Scope) -> Element {
let state = use_shared_state::<State>(cx)?;

Expand Down
38 changes: 35 additions & 3 deletions ui/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ body {
cursor: pointer;
min-height: 1.6rem;
.btn-wrap {
height: var(--titlebar-height);
width: var(--titlebar-height);
padding: unset;
.btn {
font-size: var(--text-size-less);
height: 100%;
opacity: 0.5;
}
}
}
Expand Down Expand Up @@ -163,4 +160,39 @@ body {
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.disp-flex {
display: inline-flex;

&.row {
flex-direction: row;
}

&.col {
flex-direction: column;
}
}

.instruction-list {
padding-top: 15px;
padding-bottom: 15px;
}

.download-modal {
color: var(--text-color-bright);
li {
padding: 5px;
}
}

.download-button .btn-wrap {
height: 45px;
.btn {
font-size: 16px;
}
}

.instruction-list .btn-wrap .btn {
font-size: 20px;
}
20 changes: 20 additions & 0 deletions ui/src/utils/auto_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct SoftwareDownloadCmd(pub PathBuf);
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum DownloadProgress {
Idle,
PickFolder,
Pending,
Finished,
}
Expand Down Expand Up @@ -70,6 +71,25 @@ pub async fn check_for_release() -> anyhow::Result<Option<GitHubRelease>> {
get_github_release("https://api.github.com/repos/Satellite-im/Uplink/releases/latest")
.await?;

// ensure installer is released - .deb, .msi, or .dpkg
let extension = if cfg!(target_os = "windows") {
".msi"
} else if cfg!(target_os = "linux") {
".deb"
} else if cfg!(target_os = "macos") {
".dpkg"
} else {
bail!("unknown OS");
};

if !latest_release
.assets
.iter()
.any(|x| x.name.contains(extension))
{
bail!("{extension} file not found in software release");
}

if versions_match(&latest_release.tag_name) {
Ok(None)
} else {
Expand Down

0 comments on commit 3c4b056

Please sign in to comment.