Skip to content

Commit

Permalink
Show code while connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Feb 13, 2023
1 parent 4052ad8 commit 2ba3f49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 15 additions & 9 deletions src/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ states! {

state Initial(code: String);

async state Connecting(controller: ConnectingController) -> ConnectResult {
new(code: Code) { connect(code) }
async state Connecting(controller: ConnectingController, code: Code) -> ConnectResult {
new(code: Code) {
let (future, controller) = connect(code.clone());
(future, controller, code)
}
next {
Ok(receive_request) => Connected(receive_request),
Err(PortalError::Canceled) => Default::default(),
Expand All @@ -55,7 +58,7 @@ states! {
let ctx = ui.ctx().clone();
let (future, controller) = receive_request.accept(move || ctx.request_repaint());
(future, controller, filename)
}
}
next {
Ok(path) => Completed(path),
Err(PortalError::Canceled) => Default::default(),
Expand Down Expand Up @@ -85,8 +88,8 @@ impl ReceiveView {
}
}
}
ReceiveState::Connecting(_, controller) => {
show_connecting_page(ui, controller);
ReceiveState::Connecting(_, controller, code) => {
show_connecting_page(ui, controller, code);
}
ReceiveState::Error(error) => {
let error = error.to_string();
Expand Down Expand Up @@ -172,15 +175,15 @@ enum ConnectedPageResponse {
Reject,
}

fn show_connecting_page(ui: &mut Ui, controller: &mut ConnectingController) {
fn show_connecting_page(ui: &mut Ui, controller: &mut ConnectingController, code: &Code) {
if cancel_button(ui, CancelLabel::Cancel) {
controller.cancel();
}

page_with_content(
ui,
"Connecting with peer",
"Preparing to Receive File",
"Receive File",
format!("Connecting with peer using transfer code \"{code}\""),
"📥",
|ui| {
ui.spinner();
Expand Down Expand Up @@ -261,7 +264,10 @@ fn show_completed_page(ui: &mut Ui, downloaded_path: &Path) -> Option<CompletedP
page_with_content(
ui,
"File Transfer Successful",
format!("File \"{}\" has been saved to your Downloads folder", filename.to_string_lossy()),
format!(
"File \"{}\" has been saved to your Downloads folder",
filename.to_string_lossy()
),
"✅",
|ui| {
if ui
Expand Down
4 changes: 1 addition & 3 deletions src/send.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::egui_ext::ContextExt;
use crate::transmit_info::transit_info_message;
use crate::widgets::{cancel_button, page, page_with_content, CancelLabel, MIN_BUTTON_SIZE};
use eframe::{
egui::{Button, Key, Modifiers, ProgressBar, Ui},
};
use eframe::egui::{Button, Key, Modifiers, ProgressBar, Ui};
use portal_proc_macro::states;
use portal_wormhole::send::{send, SendRequest, SendingController, SendingProgress};
use portal_wormhole::{Code, PortalError, Progress};
Expand Down

0 comments on commit 2ba3f49

Please sign in to comment.