feat: add search window (NIP-50) (#181)

* feat: add search window
* chore: improve search ui
This commit is contained in:
雨宮蓮
2024-04-23 15:34:08 +07:00
committed by GitHub
parent c00a7749b4
commit 174a3cc74e
22 changed files with 507 additions and 236 deletions

132
src-tauri/Cargo.lock generated
View File

@@ -300,8 +300,8 @@ dependencies = [
"futures-io",
"futures-lite 2.3.0",
"parking",
"polling 3.6.0",
"rustix 0.38.33",
"polling 3.7.0",
"rustix 0.38.34",
"slab",
"tracing",
"windows-sys 0.52.0",
@@ -340,7 +340,7 @@ dependencies = [
"cfg-if",
"event-listener 3.1.0",
"futures-lite 1.13.0",
"rustix 0.38.33",
"rustix 0.38.34",
"windows-sys 0.48.0",
]
@@ -359,7 +359,7 @@ dependencies = [
"cfg-if",
"event-listener 5.3.0",
"futures-lite 2.3.0",
"rustix 0.38.33",
"rustix 0.38.34",
"tracing",
"windows-sys 0.52.0",
]
@@ -387,7 +387,7 @@ dependencies = [
"cfg-if",
"futures-core",
"futures-io",
"rustix 0.38.33",
"rustix 0.38.34",
"signal-hook-registry",
"slab",
"windows-sys 0.52.0",
@@ -2612,9 +2612,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jobserver"
version = "0.1.30"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "685a7d121ee3f65ae4fddd72b25a04bb36b6af81bc0828f7d5434c0fe60fa3a2"
checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e"
dependencies = [
"libc",
]
@@ -3886,15 +3886,15 @@ dependencies = [
[[package]]
name = "polling"
version = "3.6.0"
version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0c976a60b2d7e99d6f229e414670a9b85d13ac305cc6d1e9c134de58c5aaaf6"
checksum = "645493cf344456ef24219d02a768cf1fb92ddf8c92161679ae3d91b91a637be3"
dependencies = [
"cfg-if",
"concurrent-queue",
"hermit-abi",
"pin-project-lite",
"rustix 0.38.33",
"rustix 0.38.34",
"tracing",
"windows-sys 0.52.0",
]
@@ -4333,9 +4333,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.33"
version = "0.38.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3cc72858054fcff6d7dea32df2aeaee6a7c24227366d7ea429aada2f26b16ad"
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
dependencies = [
"bitflags 2.5.0",
"errno",
@@ -4376,9 +4376,9 @@ checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247"
[[package]]
name = "rustls-webpki"
version = "0.102.2"
version = "0.102.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610"
checksum = "f3bce581c0dd41bce533ce695a1437fa16a7ab5ac3ccfa99fe1a620a7885eabf"
dependencies = [
"ring",
"rustls-pki-types",
@@ -5009,11 +5009,11 @@ dependencies = [
[[package]]
name = "tao"
version = "0.27.0"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd5b6ec2c43abd15155f040c765001098f50f425414b679225d471a1cd782753"
checksum = "92bcf8885e147b56d6e26751263b45876284f32ca404703f6d3b8f80d16ff4dd"
dependencies = [
"bitflags 1.3.2",
"bitflags 2.5.0",
"cocoa",
"core-foundation",
"core-graphics",
@@ -5040,7 +5040,8 @@ dependencies = [
"tao-macros",
"unicode-segmentation",
"url",
"windows 0.54.0",
"windows 0.56.0",
"windows-core 0.56.0",
"windows-version",
"x11-dl",
]
@@ -5075,9 +5076,9 @@ checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f"
[[package]]
name = "tauri"
version = "2.0.0-beta.15"
version = "2.0.0-beta.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd0aba659957a3f1f1666acbf17723e8d41dcc177539bf1adbe55305f5d7118a"
checksum = "4d411ebb670bbe5cf948f6c24978632937329748b499de1619ab55ad31512652"
dependencies = [
"anyhow",
"bytes",
@@ -5120,20 +5121,20 @@ dependencies = [
"webkit2gtk",
"webview2-com",
"window-vibrancy",
"windows 0.54.0",
"windows 0.56.0",
]
[[package]]
name = "tauri-build"
version = "2.0.0-beta.12"
version = "2.0.0-beta.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33de24aabe2b9c340d67005800cb6dd40aac5283126a42896fc8eec0b87cbe45"
checksum = "abcf98a9b4527567c3e5ca9723431d121e001c2145651b3fa044d22b5e025a7e"
dependencies = [
"anyhow",
"cargo_toml",
"dirs-next",
"glob",
"heck 0.4.1",
"heck 0.5.0",
"json-patch",
"schemars",
"semver",
@@ -5147,9 +5148,9 @@ dependencies = [
[[package]]
name = "tauri-codegen"
version = "2.0.0-beta.12"
version = "2.0.0-beta.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d1d211268a9590bbf75cc85b47208f59b447626c76396256e12479ac7df6c8b"
checksum = "b383f341efb803852b0235a2f330ca90c4c113f422dd6d646b888685b372cace"
dependencies = [
"base64 0.22.0",
"brotli",
@@ -5174,9 +5175,9 @@ dependencies = [
[[package]]
name = "tauri-macros"
version = "2.0.0-beta.12"
version = "2.0.0-beta.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b096f63f2724a1280ae0f5a34d0731de18ca18305e2ef6e5e9a39bb2710e8a85"
checksum = "71be71718cfe48b149507157bfbad0e2ba0e98ea51658be26c7c677eb188fb0c"
dependencies = [
"heck 0.4.1",
"proc-macro2",
@@ -5188,9 +5189,9 @@ dependencies = [
[[package]]
name = "tauri-plugin"
version = "2.0.0-beta.12"
version = "2.0.0-beta.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21c6be726c8d57ccf440e6b05a904e6acbbafb9aaf88b8a47cc1923d36ddc512"
checksum = "6baaee0a083db1e04a1b7a3b0670d86a4d95dd2a54e7cbfb5547762b8ed098d9"
dependencies = [
"anyhow",
"glob",
@@ -5439,9 +5440,9 @@ dependencies = [
[[package]]
name = "tauri-runtime"
version = "2.0.0-beta.12"
version = "2.0.0-beta.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96c957749c40db7999959f379f799db095f2248a80bdbb13d8c078f6c299240e"
checksum = "c7439729d0107c9797764919c39c4a4cc3af64306faaa48271da50d8eb4c0283"
dependencies = [
"dpi",
"gtk",
@@ -5453,14 +5454,14 @@ dependencies = [
"tauri-utils",
"thiserror",
"url",
"windows 0.54.0",
"windows 0.56.0",
]
[[package]]
name = "tauri-runtime-wry"
version = "2.0.0-beta.12"
version = "2.0.0-beta.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b937adb1cf3fa0457928ace959ca3fc1a85ddd69f56b124682d40f3e5683e60"
checksum = "0c38dcfa7f8c2b2e344c7401972e0ddaaec4fa655666788d94b1852d6c4a7fe8"
dependencies = [
"cocoa",
"gtk",
@@ -5476,22 +5477,22 @@ dependencies = [
"url",
"webkit2gtk",
"webview2-com",
"windows 0.54.0",
"windows 0.56.0",
"wry",
]
[[package]]
name = "tauri-utils"
version = "2.0.0-beta.12"
version = "2.0.0-beta.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "760ac613d7f0de95067bcbcbcea175fe1df88fc4ab59c7f0b2cc2d01dc16a199"
checksum = "d4709765385f035338ecc330f3fba753b8ee283c659c235da9768949cdb25469"
dependencies = [
"brotli",
"cargo_metadata",
"ctor",
"dunce",
"glob",
"heck 0.4.1",
"heck 0.5.0",
"html5ever",
"infer",
"json-patch",
@@ -5543,7 +5544,7 @@ checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
dependencies = [
"cfg-if",
"fastrand 2.0.2",
"rustix 0.38.33",
"rustix 0.38.34",
"windows-sys 0.52.0",
]
@@ -6386,14 +6387,14 @@ dependencies = [
[[package]]
name = "webview2-com"
version = "0.29.0"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38d5949fc3f537e90240c3e4f78dda2fa0431b671d50845a2f582173ef8a1201"
checksum = "5c914dd492a52f0377bef56fd1b6e74a79090f9ee631d625d5b505a00e4538b6"
dependencies = [
"webview2-com-macros",
"webview2-com-sys",
"windows 0.54.0",
"windows-core 0.54.0",
"windows 0.56.0",
"windows-core 0.56.0",
"windows-implement",
"windows-interface",
]
@@ -6411,13 +6412,13 @@ dependencies = [
[[package]]
name = "webview2-com-sys"
version = "0.29.0"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd1eaa1be63d6fdcadf893c40d7d53c889a6342b3a94930d34e6964d5bb7e8db"
checksum = "2a46bcf03482ec28eeb764ca788f67998cde4213adfbbfa90462622058530f5e"
dependencies = [
"thiserror",
"windows 0.54.0",
"windows-core 0.54.0",
"windows 0.56.0",
"windows-core 0.56.0",
]
[[package]]
@@ -6491,13 +6492,11 @@ dependencies = [
[[package]]
name = "windows"
version = "0.54.0"
version = "0.56.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49"
checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132"
dependencies = [
"windows-core 0.54.0",
"windows-implement",
"windows-interface",
"windows-core 0.56.0",
"windows-targets 0.52.5",
]
@@ -6521,19 +6520,21 @@ dependencies = [
[[package]]
name = "windows-core"
version = "0.54.0"
version = "0.56.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65"
checksum = "4698e52ed2d08f8658ab0c39512a7c00ee5fe2688c65f8c0a4f06750d729f2a6"
dependencies = [
"windows-implement",
"windows-interface",
"windows-result",
"windows-targets 0.52.5",
]
[[package]]
name = "windows-implement"
version = "0.53.0"
version = "0.56.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "942ac266be9249c84ca862f0a164a39533dc2f6f33dc98ec89c8da99b82ea0bd"
checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b"
dependencies = [
"proc-macro2",
"quote",
@@ -6542,9 +6543,9 @@ dependencies = [
[[package]]
name = "windows-interface"
version = "0.53.0"
version = "0.56.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da33557140a288fae4e1d5f8873aaf9eb6613a9cf82c3e070223ff177f598b60"
checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc"
dependencies = [
"proc-macro2",
"quote",
@@ -6813,11 +6814,11 @@ dependencies = [
[[package]]
name = "wry"
version = "0.39.1"
version = "0.39.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "798fb0ee725c2d243d463e62c5150fd12002a3f51f12a36d62cd7b1b7befd33d"
checksum = "1a4e9d37c0bbf497cd42bc2e0ba12e0040ab42e454f2907dc1e9ddb2eaf52d34"
dependencies = [
"base64 0.21.7",
"base64 0.22.0",
"block",
"cocoa",
"core-graphics",
@@ -6847,7 +6848,8 @@ dependencies = [
"webkit2gtk",
"webkit2gtk-sys",
"webview2-com",
"windows 0.54.0",
"windows 0.56.0",
"windows-core 0.56.0",
"windows-version",
"x11-dl",
]
@@ -6880,7 +6882,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8f25ead8c7e4cba123243a6367da5d3990e0d3affa708ea19dce96356bd9f1a"
dependencies = [
"gethostname",
"rustix 0.38.33",
"rustix 0.38.34",
"x11rb-protocol",
]
@@ -6898,7 +6900,7 @@ checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f"
dependencies = [
"libc",
"linux-raw-sys 0.4.13",
"rustix 0.38.33",
"rustix 0.38.34",
]
[[package]]

View File

@@ -7,6 +7,7 @@
"main",
"splash",
"settings",
"search",
"nwc",
"zap-*",
"event-*",

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
{"desktop-capability":{"identifier":"desktop-capability","description":"Capability for the desktop","local":true,"windows":["main","splash","settings","nwc","zap-*","event-*","user-*","editor-*","column-*"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","notification:allow-is-permission-granted","notification:allow-request-permission","notification:default","os:allow-locale","os:allow-platform","updater:allow-check","updater:default","window:allow-start-dragging","window:allow-create","window:allow-close","clipboard-manager:allow-write","clipboard-manager:allow-read","webview:allow-create-webview-window","webview:allow-create-webview","webview:allow-set-webview-size","webview:allow-set-webview-position","webview:allow-webview-close","dialog:allow-open","fs:allow-read-file","shell:allow-open",{"identifier":"http:default","allow":[{"url":"http://**/"},{"url":"https://**/"}]},{"identifier":"fs:allow-read-text-file","allow":[{"path":"$RESOURCE/locales/*"},{"path":"$RESOURCE/resources/*"}]}],"platforms":["linux","macOS","windows"]}}
{"desktop-capability":{"identifier":"desktop-capability","description":"Capability for the desktop","local":true,"windows":["main","splash","settings","search","nwc","zap-*","event-*","user-*","editor-*","column-*"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","notification:allow-is-permission-granted","notification:allow-request-permission","notification:default","os:allow-locale","os:allow-platform","updater:allow-check","updater:default","window:allow-start-dragging","window:allow-create","window:allow-close","clipboard-manager:allow-write","clipboard-manager:allow-read","webview:allow-create-webview-window","webview:allow-create-webview","webview:allow-set-webview-size","webview:allow-set-webview-position","webview:allow-webview-close","dialog:allow-open","fs:allow-read-file","shell:allow-open",{"identifier":"http:default","allow":[{"url":"http://**/"},{"url":"https://**/"}]},{"identifier":"fs:allow-read-text-file","allow":[{"path":"$RESOURCE/locales/*"},{"path":"$RESOURCE/resources/*"}]}],"platforms":["linux","macOS","windows"]}}

View File

@@ -6416,6 +6416,13 @@
"window:allow-start-dragging"
]
},
{
"description": "window:allow-start-resize-dragging -> Enables the start_resize_dragging command without any pre-configured scope.",
"type": "string",
"enum": [
"window:allow-start-resize-dragging"
]
},
{
"description": "window:allow-theme -> Enables the theme command without any pre-configured scope.",
"type": "string",
@@ -6836,6 +6843,13 @@
"window:deny-start-dragging"
]
},
{
"description": "window:deny-start-resize-dragging -> Denies the start_resize_dragging command without any pre-configured scope.",
"type": "string",
"enum": [
"window:deny-start-resize-dragging"
]
},
{
"description": "window:deny-theme -> Denies the theme command without any pre-configured scope.",
"type": "string",

View File

@@ -6416,6 +6416,13 @@
"window:allow-start-dragging"
]
},
{
"description": "window:allow-start-resize-dragging -> Enables the start_resize_dragging command without any pre-configured scope.",
"type": "string",
"enum": [
"window:allow-start-resize-dragging"
]
},
{
"description": "window:allow-theme -> Enables the theme command without any pre-configured scope.",
"type": "string",
@@ -6836,6 +6843,13 @@
"window:deny-start-dragging"
]
},
{
"description": "window:deny-start-resize-dragging -> Denies the start_resize_dragging command without any pre-configured scope.",
"type": "string",
"enum": [
"window:deny-start-resize-dragging"
]
},
{
"description": "window:deny-theme -> Denies the theme command without any pre-configured scope.",
"type": "string",

View File

@@ -57,11 +57,11 @@ fn main() {
client
.add_relay("wss://relayable.org")
.await
.expect("Cannot connect to relay.nostr.band, please try again later.");
.expect("Cannot connect to relayable.org, please try again later.");
client
.add_relay("wss://relay.damus.io")
.add_relay("wss://relay.nostr.band")
.await
.expect("Cannot connect to relay.damus.io, please try again later.");
.expect("Cannot connect to relay.nostr.band, please try again later.");
// Connect
client.connect().await;
@@ -129,6 +129,7 @@ fn main() {
nostr::event::get_event_thread,
nostr::event::publish,
nostr::event::repost,
nostr::event::search,
commands::folder::show_in_folder,
commands::folder::get_accounts,
commands::opg::fetch_opg,

View File

@@ -221,3 +221,26 @@ pub async fn repost(raw: &str, state: State<'_, Nostr>) -> Result<EventId, Strin
Err("Repost failed".into())
}
}
#[tauri::command]
pub async fn search(
content: &str,
limit: usize,
state: State<'_, Nostr>,
) -> Result<Vec<Event>, String> {
println!("search: {}", content);
let client = &state.client;
let filter = Filter::new()
.kinds(vec![Kind::TextNote, Kind::Metadata])
.search(content)
.limit(limit);
match client
.get_events_of(vec![filter], Some(Duration::from_secs(15)))
.await
{
Ok(events) => Ok(events),
Err(err) => Err(err.to_string()),
}
}

View File

@@ -10,6 +10,7 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
let menu = tauri::menu::MenuBuilder::new(app)
.item(&tauri::menu::MenuItem::with_id(app, "open", "Open Lume", true, None::<&str>).unwrap())
.item(&tauri::menu::MenuItem::with_id(app, "editor", "New Post", true, Some("cmd+n")).unwrap())
.item(&tauri::menu::MenuItem::with_id(app, "search", "Search", true, Some("cmd+k")).unwrap())
.separator()
.item(
&tauri::menu::MenuItem::with_id(
@@ -29,6 +30,7 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
.item(
&tauri::menu::MenuItem::with_id(app, "settings", "Settings...", true, Some("cmd+,")).unwrap(),
)
.separator()
.item(&tauri::menu::MenuItem::with_id(app, "quit", "Quit", true, None::<&str>).unwrap())
.build()
.unwrap();
@@ -74,6 +76,34 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
.unwrap();
}
}
"search" => {
if let Some(window) = app.get_window("search") {
if window.is_visible().unwrap_or_default() {
let _ = window.set_focus();
} else {
let _ = window.show();
let _ = window.set_focus();
};
} else {
#[cfg(target_os = "macos")]
let _ = WebviewWindowBuilder::new(app, "search", WebviewUrl::App(PathBuf::from("search")))
.title("Editor")
.inner_size(750., 470.)
.minimizable(false)
.resizable(false)
.title_bar_style(TitleBarStyle::Overlay)
.build()
.unwrap();
#[cfg(not(target_os = "macos"))]
let _ = WebviewWindowBuilder::new(app, "Search", WebviewUrl::App(PathBuf::from("search")))
.title("Search")
.inner_size(750., 470.)
.minimizable(false)
.resizable(false)
.build()
.unwrap();
}
}
"about" => {
app.shell().open("https://lume.nu", None).unwrap();
}
@@ -97,7 +127,6 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
)
.title("Settings")
.inner_size(800., 500.)
.hidden_title(true)
.title_bar_style(TitleBarStyle::Overlay)
.resizable(false)
.minimizable(false)