Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
threeseed committed May 20, 2024
1 parent 18513ff commit 348edb8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ fn main() {
}
_ => {}
},
tauri::RunEvent::ExitRequested { api, .. } => {},
_ => {}
})
}
6 changes: 2 additions & 4 deletions src-tauri/src/windows_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ pub fn init_main_panel(app_handle: AppHandle<Wry>, always_center: bool, show_dev
windows_main_mac::init_main_panel(app_handle, always_center, show_devtools)
}

#[tauri::command]
pub fn show_main(app_handle: AppHandle<Wry>) {
#[cfg(target_os = "macos")]
windows_main_mac::show_main(app_handle)
}

#[tauri::command]
pub fn hide_search(app_handle: AppHandle<Wry>) {
pub fn hide_main(app_handle: AppHandle<Wry>) {
#[cfg(target_os = "macos")]
windows_main_mac::hide_search(app_handle)
windows_main_mac::hide_main(app_handle)
}

pub fn enable_auto_hide(app_handle: AppHandle<Wry>) {
Expand Down
13 changes: 9 additions & 4 deletions src-tauri/src/windows_main_mac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn register_shortcut(app_handle: AppHandle<Wry>, shortcut: String) {
let _ = shortcut_manager
.register(shortcut.as_str(), move || {
if panel.is_visible() {
hide_search(app_handle.clone());
hide_main(app_handle.clone());
} else {
// let start = Instant::now();
//
Expand Down Expand Up @@ -150,8 +150,8 @@ pub fn show_main(app_handle: AppHandle<Wry>) {
panel!(app_handle).show();
}

pub fn hide_search(app_handle: AppHandle<Wry>) {
panel!(app_handle).order_out(None);
pub fn hide_main(app_handle: AppHandle<Wry>) {
panel!(app_handle).hide();
}

pub fn enable_auto_hide(app_handle: AppHandle<Wry>) {
Expand Down Expand Up @@ -258,6 +258,10 @@ impl RawNSPanel {
self.make_key_and_order_front(None);
}

fn hide(&self) {
self.order_out(Some(self.content_view()));
}

fn is_visible(&self) -> bool {
let flag: BOOL = unsafe { msg_send![self, isVisible] };
flag == YES
Expand Down Expand Up @@ -385,7 +389,7 @@ impl RawNSPanelDelegate {
unsafe impl Message for RawNSPanelDelegate {}

impl INSObject for RawNSPanelDelegate {
fn class() -> &'static runtime::Class {
fn class() -> &'static Class {
Self::get_class()
}
}
Expand All @@ -402,6 +406,7 @@ unsafe fn create_main_panel(window: &Window<Wry>) -> ShareId<RawNSPanel> {
let panel = panel.share();

handle.setHasShadow_(BOOL::from(false));
handle.setReleasedWhenClosed_(BOOL::from(false));
panel.set_level(NSMainMenuWindowLevel + 1);
panel.set_style_mask(NSWindowStyleMaskNonActivatingPanel);
panel.set_collection_behaviour(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class SearchHandler extends ActionHandler(zoomTo(_.searchState)) {
effectOnly(
Effect(
Tauri.invoke("search", Map("query" -> term.get)).map { (jsResults: js.Dictionary[js.Array[RawDocument]]) => {
analytics.pushEvent("search")
val results = jsResults.toMap.view
.map(pair => (pair._1, pair._2.toList.sortBy(_.title.toLowerCase).map(rd => Document(rd, pair._1))))
.toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class SearchKeyHandler extends ActionHandler(zoomTo(_.searchState)) {
effectOnly {
if (key == Keys.Escape)
if (value.searchTerm.isEmpty) {
Tauri.invoke("hide_search")
Tauri.invoke("hide_window", Map("label" -> "main"))
action(NoChange)
} else
if (value.focusedPanel != SearchColumn.Search)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import scala.scalajs.js.JSConverters._
when(state.focusedPanel == SearchColumn.Search)(ApplicationHint()),
when(state.searchResults.nonEmpty) {
PopoverButton(
onClick = () => Tauri.invoke("update_window_size", Map("label" -> "search", "width" -> 950.0, "height" -> 680.0).toJSDictionary),
onClick = () => Tauri.invoke("update_window_size", Map("label" -> "main", "width" -> 950.0, "height" -> 680.0).toJSDictionary),
className = "absolute right-4 top-4 h-6 w-5 text-gray-400")(
Bars3Icon()
)
Expand Down

0 comments on commit 348edb8

Please # to comment.