Skip to content

Commit b8a1341

Browse files
committed
clean up engine event
1 parent 90e4de9 commit b8a1341

12 files changed

Lines changed: 87 additions & 129 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ async-stream = { version = "0.3.6" }
4848
async-tar = { version = "0.5" }
4949
async_zip = { version = "0.0.17" }
5050
bimap = { version = "0.6" }
51-
blocking = { version = "1.6" }
5251
bytes = { version = "1.10" }
5352
bzip2 = { version = "0.5" }
5453
cfg-if = { version = "1.0" }
5554
clap = { version = "4.5" }
5655
data-encoding = { version = "2.9" }
5756
derive_more = { version = "2.0" }
5857
directories = { version = "6.0" }
59-
either = { version = "1.15" }
6058
foldhash = { version = "0.1.4" }
6159
form_urlencoded = { version = "1.2" }
6260
futures = { version = "0.3" }
@@ -77,7 +75,6 @@ pipewire = { version = "0.8" }
7775
poem = { version = "3.1.9" }
7876
poem-openapi = { version = "5.1" }
7977
rand = { version = "0.9" }
80-
rayon = { version = "1.10" }
8178
regex = { version = "1.11" }
8279
relm4 = { version = "0.9.1" }
8380
relm4-components = { version = "0.9.1" }
@@ -97,7 +94,6 @@ tokio-tungstenite = { version = "0.26" }
9794
tokio-util = { version = "0.7" }
9895
tracing = { version = "0.1" }
9996
tracing-subscriber = { version = "0.3" }
100-
unicode-segmentation = { version = "1.12" }
10197
uniffi = { version = "0.29.2" }
10298
webkit6 = { version = "0.4" }
10399
xz2 = { version = "0.1" }

crates/wordbase-cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ wordbase = { workspace = true, features = ["desktop"] }
2020

2121
anyhow = { workspace = true }
2222
ascii_table = { workspace = true, features = ["wide_characters"] }
23-
bytes = { workspace = true }
2423
clap = { workspace = true, features = ["derive"] }
2524
futures = { workspace = true }
2625
tokio = { workspace = true, features = ["full"] }

crates/wordbase-sys/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,3 @@ name = "wordbase"
2222

2323
[dependencies]
2424
wordbase = { workspace = true, features = ["uniffi"] }
25-
26-
uniffi = { workspace = true }
27-
28-
[build-dependencies]
29-
uniffi = { workspace = true, features = ["build"] }

crates/wordbase/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ all-features = true
2020
[features]
2121
poem = ["wordbase-api/poem", "dep:poem-openapi"]
2222
uniffi = ["wordbase-api/uniffi", "dep:uniffi"]
23-
desktop = ["dep:directories"]
23+
desktop = ["dep:directories", "dep:tokio-tungstenite"]
2424

2525
[dependencies]
2626
wordbase-api = { workspace = true, features = ["render-html"] }
@@ -31,11 +31,9 @@ async-compression = { workspace = true, features = ["xz"] }
3131
async-stream = { workspace = true }
3232
async-tar = { workspace = true }
3333
async_zip = { workspace = true, features = ["deflate", "tokio"] }
34-
blocking = { workspace = true }
3534
bytes = { workspace = true }
3635
data-encoding = { workspace = true }
3736
directories = { workspace = true, optional = true }
38-
either = { workspace = true }
3937
foldhash = { workspace = true }
4038
futures = { workspace = true }
4139
indexmap = { workspace = true, features = ["serde"] }
@@ -45,7 +43,6 @@ maud = { workspace = true }
4543
paste = { workspace = true }
4644
pin-project = { version = "1.1" }
4745
poem-openapi = { workspace = true, optional = true }
48-
rayon = { workspace = true }
4946
regex = { workspace = true }
5047
reqwest = { workspace = true, features = ["json"] }
5148
rmp-serde = { workspace = true }
@@ -56,10 +53,9 @@ sqlx = { workspace = true, features = ["runtime-tokio", "sqlite"
5653
tera = { workspace = true, features = ["preserve_order"] }
5754
tokio = { workspace = true, features = ["sync", "macros"] }
5855
tokio-stream = { workspace = true }
59-
tokio-tungstenite = { workspace = true }
56+
tokio-tungstenite = { workspace = true, optional = true }
6057
tokio-util = { workspace = true, features = ["rt"] }
6158
tracing = { workspace = true }
62-
unicode-segmentation = { workspace = true }
6359
uniffi = { workspace = true, optional = true, features = ["tokio"] }
6460

6561
derive_more = { workspace = true, features = [

crates/wordbase/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod import;
99
pub mod lookup;
1010
pub mod profile;
1111
pub mod render;
12+
#[cfg(feature = "desktop")]
1213
pub mod texthook;
1314

1415
pub use wordbase_api::*;
@@ -23,7 +24,6 @@ use {
2324
sqlx::{Pool, Sqlite},
2425
std::path::Path,
2526
tera::Tera,
26-
texthook::Texthookers,
2727
tokio::sync::broadcast,
2828
tracing::info,
2929
};
@@ -36,7 +36,8 @@ pub struct Engine {
3636
profiles: ArcSwap<Profiles>,
3737
dictionaries: ArcSwap<Dictionaries>,
3838
renderer: Tera,
39-
texthookers: Texthookers,
39+
#[cfg(feature = "desktop")]
40+
texthookers: texthook::Texthookers,
4041
deinflectors: Deinflectors,
4142
anki: Anki,
4243
event_tx: broadcast::Sender<EngineEvent>,
@@ -138,7 +139,8 @@ impl Engine {
138139
.unwrap();
139140
tera
140141
},
141-
texthookers: Texthookers::new(&db, event_tx.clone())
142+
#[cfg(feature = "desktop")]
143+
texthookers: texthook::Texthookers::new(&db, event_tx.clone())
142144
.await
143145
.context("failed to create texthooker listener")?,
144146
deinflectors: Deinflectors::new().context("failed to create deinflectors")?,

record-templates/records.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
body {
7575
padding: 0;
7676
margin: 0 0 var(--content-margin) 0;
77+
word-break: break-all;
78+
overflow-wrap: break-word;
7779
}
7880

7981
a {

wordbase-android/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
minSdk = 24
1515
targetSdk = 35
1616
versionCode = 1
17-
versionName = "0.1.0"
17+
versionName = "0.2.0"
1818

1919
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2020
}

wordbase-android/app/src/main/java/io/github/aecsocket/wordbase/App.kt

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import kotlinx.coroutines.Deferred
1515
import kotlinx.coroutines.Dispatchers
1616
import kotlinx.coroutines.SupervisorJob
1717
import kotlinx.coroutines.async
18-
import kotlinx.coroutines.launch
19-
import uniffi.wordbase.DictionaryEvent
20-
import uniffi.wordbase.EngineEvent
2118
import uniffi.wordbase.Wordbase
2219
import uniffi.wordbase.wordbase
2320
import uniffi.wordbase_api.Dictionary
@@ -42,42 +39,15 @@ class App : Application() {
4239
val engine = wordbase(filesDir.absolutePath)
4340
_dictionaries = engine.dictionaries()
4441
_profiles = engine.profiles()
45-
46-
appScope.launch {
47-
val eventRx = engine.eventRx()
48-
while (true) {
49-
val event = eventRx.recv() ?: return@launch
50-
onWordbaseEvent(engine, event)
51-
}
52-
}
53-
5442
engine
5543
}
5644
}
5745

58-
private fun onWordbaseEvent(wordbase: Wordbase, event: EngineEvent) {
59-
// TODO clean this up on rust side as well
60-
when (event) {
61-
is EngineEvent.TexthookerConnected -> {}
62-
is EngineEvent.TexthookerDisconnected -> {}
63-
is EngineEvent.Sentence -> {}
64-
is EngineEvent.Dictionary -> {
65-
if (event.v1 !is DictionaryEvent.PositionsSwapped) {
66-
_dictionaries = wordbase.dictionaries()
67-
_profiles = wordbase.profiles()
68-
}
69-
}
70-
else -> {
71-
_dictionaries = wordbase.dictionaries()
72-
_profiles = wordbase.profiles()
73-
}
74-
}
75-
}
76-
77-
suspend fun swapDictionaryPositions(aId: DictionaryId, bId: DictionaryId) {
78-
val wordbase = wordbase.await()
79-
wordbase.swapDictionaryPositions(aId, bId)
46+
suspend fun <R> writeToWordbase(wordbase: Wordbase, block: suspend () -> R): R {
47+
val r = block()
8048
_dictionaries = wordbase.dictionaries()
49+
_profiles = wordbase.profiles()
50+
return r
8151
}
8252
}
8353

wordbase-android/app/src/main/java/io/github/aecsocket/wordbase/MainActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import androidx.compose.ui.res.stringResource
4848
import androidx.compose.ui.text.style.TextAlign
4949
import androidx.compose.ui.tooling.preview.Preview
5050
import androidx.compose.ui.unit.dp
51+
import androidx.compose.ui.zIndex
5152
import androidx.window.core.layout.WindowWidthSizeClass
5253
import io.github.aecsocket.wordbase.ui.theme.WordbaseTheme
5354
import kotlinx.coroutines.launch
@@ -139,7 +140,7 @@ fun Ui(manageContent: @Composable (Modifier) -> Unit) {
139140
top = padding.calculateTopPadding(),
140141
bottom = padding.calculateBottomPadding()
141142
),
142-
query = query
143+
query = query,
143144
)
144145
}
145146
}

0 commit comments

Comments
 (0)