Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
threeseed committed May 21, 2024
1 parent 348edb8 commit fa0fcd2
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 45 deletions.
21 changes: 0 additions & 21 deletions src-tauri/src/handler_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,6 @@ use tauri::{AppHandle, Wry};

use crate::{MAIN_WINDOW, PREVIEW_WINDOW, windows_main};

#[tauri::command]
pub fn show_preview(app_handle: AppHandle<Wry>, _document: String) -> Result<(), String> {
debug!("Command: search->show_preview");
windows_main::disable_auto_hide(app_handle);
let window = PREVIEW_WINDOW.get().unwrap();
window.set_focus().unwrap();
window.center().unwrap();
Ok(())
}

#[tauri::command]
pub fn hide_preview(app_handle: AppHandle<Wry>) -> Result<(), String> {
debug!("Command: search->hide_preview");
windows_main::enable_auto_hide(app_handle);
let main_window = MAIN_WINDOW.get().unwrap();
let preview_window = PREVIEW_WINDOW.get().unwrap();
main_window.set_focus().unwrap();
preview_window.hide().unwrap();
Ok(())
}

#[tauri::command]
pub fn get_viewer(path: String) -> String {
let path = Path::new(path.as_str());
Expand Down
2 changes: 0 additions & 2 deletions src-tauri/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ pub fn invoke_handler(invoke: tauri::Invoke<Wry>) {
crate::handler_integrations::remove_integration,
crate::handler_open::open_application,
crate::handler_open::open_path,
crate::handler_preview::show_preview,
crate::handler_preview::hide_preview,
crate::handler_preview::get_viewer,
crate::handler_rules::list_rules,
crate::handler_search::search,
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/com/harana/search/client/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.harana.search.client.main.MainStore.UpdateActivePanel
import com.harana.search.client.main.ui.{MainPanel, Panel}
import com.harana.search.client.system.SystemStore.WindowReady
import com.harana.web.actions.Init
import com.harana.web.external.tauri.Window
import slinky.core.FunctionalComponent
import slinky.core.annotations.react
import slinky.core.facade.Hooks.useEffect
Expand Down
12 changes: 9 additions & 3 deletions src/main/scala/com/harana/search/client/main/ui/MainPanel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.harana.web.external.tailwind.OutlineIcons._
import com.harana.web.external.tailwind.dialog._
import com.harana.web.external.tailwind.popover._
import com.harana.web.external.tailwind.transition.{Transition, TransitionChild}
import org.scalajs.dom.{FocusEvent, KeyboardEvent, window}
import org.scalajs.dom.{FocusEvent, HTMLInputElement, KeyboardEvent, window}
import slinky.core.FunctionalComponent
import slinky.core.annotations.react
import slinky.core.facade.Fragment
Expand All @@ -24,7 +24,14 @@ import slinky.web.html._

useEffect(
() => {
val keyDownListener = (e: KeyboardEvent) => Circuit.dispatch(KeyDown(e.keyCode, e))
val keyDownListener = (e: KeyboardEvent) => {
Circuit.dispatch(KeyDown(e.keyCode, e))

if (!e.target.isInstanceOf[HTMLInputElement]) {
e.preventDefault()
e.stopPropagation()
}
}
val keyUpListener = (e: KeyboardEvent) => Circuit.dispatch(KeyUp(e.keyCode, e))
val blurListener = (_: FocusEvent) => if (!Circuit.state(_.systemState, false).isDebug) Circuit.dispatch(Hide)

Expand Down Expand Up @@ -88,7 +95,6 @@ import slinky.web.html._
)

val activePanel = Circuit.state(_.mainState, true).activePanel
println("ACTIVE PANEL = " + activePanel)

if (activePanel == Panel.Welcome) {
WelcomePanel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SearchHandler extends ActionHandler(zoomTo(_.searchState)) {
case Hide =>
effectOnly(
Effect(
Tauri.invoke[Unit]("hide_search").map(_ => NoChange)
Tauri.invoke[Unit]("hide_window", Map("label" -> "main")).map(_ => NoChange)
)
)

Expand Down Expand Up @@ -170,9 +170,7 @@ class SearchHandler extends ActionHandler(zoomTo(_.searchState)) {
val doc = document(documentId)
effectOnly(
if (value.selectedDocumentId.isEmpty || value.selectedDocumentId.get != documentId)
Effect(
Tauri.invoke[Unit]("emit_preview_message", Map("name" -> "preview_document_changed", "payload" -> doc.asJson.noSpaces)).map(_ => NoChange)
) + (if (doc.path.isDefined) Effect(Tauri.invoke[String]("get_viewer", Map("path" -> doc.path.get)).map(viewer => UpdateAllowPreview(viewer != "Noop"))) else Effect.action(NoChange)) +
(if (doc.path.isDefined) Effect(Tauri.invoke[String]("get_viewer", Map("path" -> doc.path.get)).map(viewer => UpdateAllowPreview(viewer != "Noop"))) else Effect.action(NoChange)) +
action(
ActionBatch(
LoadThumbnail(documentId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ class SearchKeyHandler extends ActionHandler(zoomTo(_.searchState)) {
}

case SearchColumn.Cards =>
event.stopPropagation()

val cardState = Circuit.state(_.cardState, false)
val hasVerticalCards = cardState.cards.nonEmpty && cardState.cards(cardState.middleHorizontalIndex).nonEmpty

Expand Down Expand Up @@ -196,10 +194,6 @@ class SearchKeyHandler extends ActionHandler(zoomTo(_.searchState)) {
}

case KeyUp(key, event) =>
effectOnly(action(NoChange))

event.stopPropagation()

effectOnly {
if (key == Keys.Escape)
if (value.searchTerm.isEmpty) {
Expand All @@ -216,8 +210,6 @@ class SearchKeyHandler extends ActionHandler(zoomTo(_.searchState)) {
else
action(Search(None))
else {
event.stopPropagation()
event.preventDefault()
action(NoChange)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,42 @@ class SearchMenuHandler extends ActionHandler(zoomTo(_.searchState)) {
case ShowBilling =>
effectOnly(
Effect(
Tauri.invoke("show_billing").map((_: js.Any) => NoChange)
Tauri.invoke[Unit]("show_billing").map(_ => NoChange)
)
)

case ShowFeedback =>
effectOnly(
Effect(
Tauri.invoke("open_url").map((_: js.Any) => NoChange)
Tauri.invoke[Unit]("open_url").map(_ => NoChange)
)
)

case ShowHaranaPlus =>
effectOnly(
Effect(
Tauri.invoke("show_#").map((_: js.Any) => NoChange)
Tauri.invoke[Unit]("show_#").map(_ => NoChange)
)
)

case ShowLogin =>
effectOnly(
Effect(
Tauri.invoke("show_login").map((_: js.Any) => NoChange)
Tauri.invoke[Unit]("show_login").map(_ => NoChange)
)
)

case ShowSettings =>
effectOnly(
Effect(
Tauri.invoke("show_settings").map((_: js.Any) => NoChange)
Tauri.invoke[Unit]("show_window", Map("label" -> "settings")).map(_ => NoChange)
)
)

case ShowSupport =>
effectOnly(
Effect(
Tauri.invoke("open_url", Map("url" -> "https://github.com/harana/search/issues")).map((_: js.Any) => NoChange)
Tauri.invoke[Unit]("open_url", Map("url" -> "https://github.com/harana/search/issues")).map(_ => NoChange)
)
)
}
Expand Down

0 comments on commit fa0fcd2

Please # to comment.