mirror of
https://github.com/edu4rdshl/Strata.git
synced 2026-07-17 23:24:46 +00:00
perf: return raw bytes from GetItemContent instead of base64
The D-Bus interface previously returned content as a base64-encoded string (type 's'), requiring the daemon to encode and GJS to decode on every paste. D-Bus natively supports byte arrays (type 'ay'), eliminating both encode and decode steps entirely. Changes: - dbus_service.rs: return (String, Vec<u8>); drop base64 calls - dbus.js: content_b64 arg changed from type 's' to type 'ay' - panel.js: remove GLib.base64_decode(); pass ay bytes directly - Cargo.toml/Cargo.lock: remove base64 dependency (no longer used) For a 1 MB text paste this avoids allocating a 1.33 MB intermediate string and decoding it on the compositor main thread. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
40a9a3bbd5
commit
f9826c63a8
5 changed files with 11 additions and 19 deletions
7
strata-daemon/Cargo.lock
generated
7
strata-daemon/Cargo.lock
generated
|
|
@ -201,12 +201,6 @@ version = "1.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "base64"
|
|
||||||
version = "0.22.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.11.1"
|
version = "2.11.1"
|
||||||
|
|
@ -1281,7 +1275,6 @@ name = "strata-daemon"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
|
||||||
"blake3",
|
"blake3",
|
||||||
"dirs",
|
"dirs",
|
||||||
"image",
|
"image",
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ uuid = { version = "1", features = ["v4"] }
|
||||||
|
|
||||||
# Image thumbnail generation (runs in spawn_blocking — never blocks async runtime)
|
# Image thumbnail generation (runs in spawn_blocking — never blocks async runtime)
|
||||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
|
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
|
||||||
base64 = { version = "0.22", features = ["std"] }
|
|
||||||
|
|
||||||
# Fast content hashing for deduplication
|
# Fast content hashing for deduplication
|
||||||
blake3 = "1"
|
blake3 = "1"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use base64::Engine as _;
|
|
||||||
use zbus::{interface, object_server::SignalContext};
|
use zbus::{interface, object_server::SignalContext};
|
||||||
|
|
||||||
use crate::db::{Db, RawItem};
|
use crate::db::{Db, RawItem};
|
||||||
|
|
@ -112,7 +111,8 @@ impl StrataManager {
|
||||||
/// Return the raw content of a clipboard item for GJS to write to clipboard.
|
/// Return the raw content of a clipboard item for GJS to write to clipboard.
|
||||||
/// GJS uses St.Clipboard (text) or Meta.SelectionSourceMemory (images)
|
/// GJS uses St.Clipboard (text) or Meta.SelectionSourceMemory (images)
|
||||||
/// because the Wayland data-control protocol is not accessible from non-compositor processes.
|
/// because the Wayland data-control protocol is not accessible from non-compositor processes.
|
||||||
async fn get_item_content(&self, id: String) -> zbus::fdo::Result<(String, String)> {
|
/// Content is returned as a raw byte array (`ay`) — no base64 round-trip.
|
||||||
|
async fn get_item_content(&self, id: String) -> zbus::fdo::Result<(String, Vec<u8>)> {
|
||||||
let db = self.db.clone();
|
let db = self.db.clone();
|
||||||
let item: Option<RawItem> = tokio::task::spawn_blocking(move || db.get_raw_item(&id))
|
let item: Option<RawItem> = tokio::task::spawn_blocking(move || db.get_raw_item(&id))
|
||||||
.await
|
.await
|
||||||
|
|
@ -121,15 +121,15 @@ impl StrataManager {
|
||||||
|
|
||||||
let item = item.ok_or_else(|| zbus::fdo::Error::Failed("Item not found".into()))?;
|
let item = item.ok_or_else(|| zbus::fdo::Error::Failed("Item not found".into()))?;
|
||||||
|
|
||||||
let content_b64 = if let Some(text) = item.content_text {
|
let content = if let Some(text) = item.content_text {
|
||||||
base64::engine::general_purpose::STANDARD.encode(text.as_bytes())
|
text.into_bytes()
|
||||||
} else if let Some(blob) = item.content_blob {
|
} else if let Some(blob) = item.content_blob {
|
||||||
base64::engine::general_purpose::STANDARD.encode(&blob)
|
blob
|
||||||
} else {
|
} else {
|
||||||
return Err(zbus::fdo::Error::Failed("Item has no content".into()));
|
return Err(zbus::fdo::Error::Failed("Item has no content".into()));
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((item.mime_type, content_b64))
|
Ok((item.mime_type, content))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restore a clipboard item to the system clipboard.
|
/// Restore a clipboard item to the system clipboard.
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ const STRATA_IFACE_XML = `
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
<method name="GetItemContent">
|
<method name="GetItemContent">
|
||||||
<arg type="s" direction="in" name="id"/>
|
<arg type="s" direction="in" name="id"/>
|
||||||
<arg type="s" direction="out" name="mime_type"/>
|
<arg type="s" direction="out" name="mime_type"/>
|
||||||
<arg type="s" direction="out" name="content_b64"/>
|
<arg type="ay" direction="out" name="content"/>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
<method name="SetClipboard">
|
<method name="SetClipboard">
|
||||||
|
|
|
||||||
|
|
@ -471,8 +471,8 @@ export class StrataPanel {
|
||||||
|
|
||||||
async _onItemActivated(id) {
|
async _onItemActivated(id) {
|
||||||
try {
|
try {
|
||||||
const [mimeType, contentB64] = await this._proxy.GetItemContentAsync(id);
|
const [mimeType, content] = await this._proxy.GetItemContentAsync(id);
|
||||||
this._writeToClipboard(mimeType, GLib.base64_decode(contentB64));
|
this._writeToClipboard(mimeType, content);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[Strata] Paste error:', e);
|
console.error('[Strata] Paste error:', e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue