Open .slatepack file with the app #13
2 changed files with 28 additions and 13 deletions
|
@ -33,12 +33,17 @@ lazy_static! {
|
|||
pub struct App<Platform> {
|
||||
/// Platform specific callbacks handler.
|
||||
pub platform: Platform,
|
||||
|
||||
/// Main content.
|
||||
content: Content,
|
||||
|
||||
/// Last window resize direction.
|
||||
resize_direction: Option<ResizeDirection>,
|
||||
|
||||
/// Flag to check if it's first draw.
|
||||
first_draw: bool,
|
||||
/// Flag to check if attention required after window focus.
|
||||
attention_required: bool,
|
||||
}
|
||||
|
||||
impl<Platform: PlatformCallbacks> App<Platform> {
|
||||
|
@ -48,6 +53,7 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
|||
content: Content::default(),
|
||||
resize_direction: None,
|
||||
first_draw: true,
|
||||
attention_required: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,8 +115,19 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
|||
// Provide incoming data to wallets.
|
||||
if let Some(data) = self.platform.consume_data() {
|
||||
self.content.wallets.on_data(ui, Some(data), &self.platform);
|
||||
self.attention_required = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Check if desktop window was focused after requested attention.
|
||||
if View::is_desktop() && self.attention_required
|
||||
&& ctx.input(|i| i.viewport().focused.unwrap_or(true)) {
|
||||
self.attention_required = false;
|
||||
ctx.send_viewport_cmd(
|
||||
ViewportCommand::RequestUserAttention(egui::UserAttentionType::Reset)
|
||||
);
|
||||
ctx.send_viewport_cmd(ViewportCommand::WindowLevel(egui::WindowLevel::Normal));
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw custom resizeable window content.
|
||||
|
|
|
@ -19,7 +19,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
|||
use std::sync::Arc;
|
||||
use parking_lot::RwLock;
|
||||
use lazy_static::lazy_static;
|
||||
use egui::{UserAttentionType, ViewportCommand};
|
||||
use egui::{UserAttentionType, ViewportCommand, WindowLevel};
|
||||
use rfd::FileDialog;
|
||||
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
|
@ -126,14 +126,6 @@ impl PlatformCallbacks for Desktop {
|
|||
r_data.is_some()
|
||||
};
|
||||
if has_data {
|
||||
// Reset window state.
|
||||
let r_ctx = self.ctx.read();
|
||||
if r_ctx.is_some() {
|
||||
let ctx = r_ctx.as_ref().unwrap();
|
||||
ctx.send_viewport_cmd(
|
||||
ViewportCommand::RequestUserAttention(UserAttentionType::Reset)
|
||||
);
|
||||
}
|
||||
// Clear data.
|
||||
let mut w_data = PASSED_DATA.write();
|
||||
let data = w_data.clone();
|
||||
|
@ -160,16 +152,22 @@ impl Desktop {
|
|||
let mut w_data = PASSED_DATA.write();
|
||||
*w_data = Some(data);
|
||||
|
||||
// Bring focus on window.
|
||||
let r_ctx = self.ctx.read();
|
||||
if r_ctx.is_some() {
|
||||
let ctx = r_ctx.as_ref().unwrap();
|
||||
ctx.send_viewport_cmd(ViewportCommand::Visible(true));
|
||||
ctx.send_viewport_cmd(ViewportCommand::Minimized(false));
|
||||
// Request attention on taskbar.
|
||||
ctx.send_viewport_cmd(
|
||||
ViewportCommand::RequestUserAttention(UserAttentionType::Informational)
|
||||
);
|
||||
ctx.send_viewport_cmd(ViewportCommand::Focus);
|
||||
// Un-minimize window.
|
||||
if ctx.input(|i| i.viewport().minimized.unwrap_or(false)) {
|
||||
ctx.send_viewport_cmd(ViewportCommand::Minimized(false));
|
||||
}
|
||||
// Focus to window.
|
||||
if !ctx.input(|i| i.viewport().focused.unwrap_or(false)) {
|
||||
ctx.send_viewport_cmd(ViewportCommand::WindowLevel(WindowLevel::AlwaysOnTop));
|
||||
ctx.send_viewport_cmd(ViewportCommand::Focus);
|
||||
}
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue