Reopen the window without focus when an Arena champ select starts (#63)
A minimized window, or one hidden in the notification area, comes back above the other windows while League keeps the keyboard. An already visible window is left alone, and the window stays open after the champ select. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #64.
This commit is contained in:
1 parent
c5ed246668
commit
24aca3c93d
4 files changed
+86
-12
No files matched your search
@@ -90,7 +90,14 @@ impl RootView {
|
||||
let champ_select = cx.subscribe_in(
|
||||
&page,
|
||||
window,
|
||||
|this, _, _: &stats_page::ChampSelectTransition, window, cx| {
|
||||
|this, _, transition: &stats_page::ChampSelectTransition, window, cx| {
|
||||
// Only on entry: the window stays open after the champ select.
|
||||
if transition.entered
|
||||
&& let Some(hwnd) = tray::window_hwnd(window)
|
||||
{
|
||||
// Outside this update: the native calls resize the window through GPUI.
|
||||
cx.spawn(async move |_, _| tray::reveal(hwnd)).detach();
|
||||
}
|
||||
if this.screen == Screen::Settings {
|
||||
// Champ select takes the window away: do not bring back half-typed edits.
|
||||
this.show_page(window, cx);
|
||||
|
||||
@@ -83,7 +83,10 @@ impl SelectItem for AccountItem {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ChampSelectTransition;
|
||||
/// The page entered or left an Arena champ select.
|
||||
pub struct ChampSelectTransition {
|
||||
pub entered: bool,
|
||||
}
|
||||
impl EventEmitter<ChampSelectTransition> for StatsPage {}
|
||||
|
||||
pub struct StatsPage {
|
||||
@@ -388,7 +391,9 @@ impl StatsPage {
|
||||
self.reload_in_background(window, cx);
|
||||
}
|
||||
if changed_page {
|
||||
cx.emit(ChampSelectTransition);
|
||||
cx.emit(ChampSelectTransition {
|
||||
entered: self.in_champ_select(),
|
||||
});
|
||||
}
|
||||
self.update_picks();
|
||||
if pool_changed || switch {
|
||||
@@ -1221,7 +1226,7 @@ impl Render for StatsPage {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::cell::Cell;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
@@ -1421,6 +1426,37 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn only_entering_a_champ_select_is_reported_as_an_entry(cx: &mut TestAppContext) {
|
||||
use crate::worker::Msg;
|
||||
use arena_tracker_core::ChampSelect;
|
||||
let tracker = Tracker::open(Path::new(":memory:"), Box::new(RefreshHistory)).unwrap();
|
||||
let (page, mut window) = open_page_with_tracker(cx, tracker);
|
||||
let entered = Rc::new(RefCell::new(Vec::new()));
|
||||
let _events = window.update(|_, cx| {
|
||||
let entered = entered.clone();
|
||||
cx.subscribe(
|
||||
&page,
|
||||
move |_, transition: &super::ChampSelectTransition, _| {
|
||||
entered.borrow_mut().push(transition.entered)
|
||||
},
|
||||
)
|
||||
});
|
||||
let hovered = |current| ChampSelect::new(current, [39].into(), vec![39]);
|
||||
for champ_select in [
|
||||
None,
|
||||
Some(("Alice#EUW".into(), hovered(Some(39)))),
|
||||
Some(("Alice#EUW".into(), hovered(None))),
|
||||
None,
|
||||
None,
|
||||
] {
|
||||
window.update(|w, cx| {
|
||||
page.update(cx, |p, cx| p.apply(Msg::ChampSelect(champ_select), w, cx))
|
||||
});
|
||||
}
|
||||
assert_eq!(*entered.borrow(), [true, false]);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn typing_in_the_search_field_filters_the_table(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page(cx);
|
||||
|
||||
+38
-7
@@ -253,15 +253,46 @@ fn fill(field: &mut [u16], text: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reopen(hwnd: HWND) {
|
||||
/// The window's tray, while it is installed.
|
||||
fn installed_tray(hwnd: HWND) -> Option<Rc<Tray>> {
|
||||
let mut data = 0;
|
||||
if unsafe { GetWindowSubclass(hwnd, Some(window_proc), TRAY_SUBCLASS, Some(&mut data)) }
|
||||
unsafe { GetWindowSubclass(hwnd, Some(window_proc), TRAY_SUBCLASS, Some(&mut data)) }
|
||||
.as_bool()
|
||||
{
|
||||
let data = data as *const Tray;
|
||||
unsafe { retain(data) }.open();
|
||||
} else {
|
||||
foreground(hwnd);
|
||||
.then(|| unsafe { retain(data as *const Tray) })
|
||||
}
|
||||
|
||||
pub fn reopen(hwnd: HWND) {
|
||||
match installed_tray(hwnd) {
|
||||
Some(tray) => tray.open(),
|
||||
None => foreground(hwnd),
|
||||
}
|
||||
}
|
||||
|
||||
/// Brings a minimized window, or one hidden in the notification area, back above the other
|
||||
/// windows while the foreground app keeps the keyboard. A window already shown is left alone.
|
||||
pub fn reveal(hwnd: HWND) {
|
||||
unsafe {
|
||||
let iconic = IsIconic(hwnd).as_bool();
|
||||
if IsWindowVisible(hwnd).as_bool() && !iconic {
|
||||
return;
|
||||
}
|
||||
if let Some(tray) = installed_tray(hwnd) {
|
||||
tray.remove_icon();
|
||||
}
|
||||
if iconic {
|
||||
// shortcut: a window minimized from maximized may come back at its normal size, as no
|
||||
// show command maximizes without activating; revisit if the Windows check shows it.
|
||||
let _ = ShowWindow(hwnd, SW_SHOWNOACTIVATE);
|
||||
}
|
||||
let _ = SetWindowPos(
|
||||
hwnd,
|
||||
Some(HWND_TOP),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user