Skip to content

Commit 63c9da7

Browse files
committed
feat(getter): add manager module (AppManager, HubManager, Updater, VersionMap)
Ports Kotlin core manager logic to Rust: - manager/app_status: AppStatus enum (6 variants) - manager/version: VersionInfo (regex-filtered, libversion-comparable), Version, VersionWrapper - manager/version_map: VersionMap with per-hub status tracking and sorted version cache - manager/updater: get_release_status() mirrors Kotlin Updater.getReleaseStatus() - manager/data_getter: DataGetter with per-hub async mutex, batch/full release fetching - manager/hub_manager: HubManager backed by JSONL database - manager/app_manager: AppManager with saved/virtual app lists, semaphore-limited renew_all()
1 parent 6820f9b commit 63c9da7

12 files changed

Lines changed: 1053 additions & 14 deletions

File tree

src/database/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ static DB: OnceCell<Database> = OnceCell::new();
130130
/// Initialize the global database. Must be called once before `get_db()`.
131131
pub fn init_db(data_dir: &Path) -> Result<()> {
132132
let db = Database::open(data_dir)?;
133-
DB.set(db).map_err(|_| {
134-
crate::error::Error::Other("Database already initialized".to_string())
135-
})
133+
DB.set(db)
134+
.map_err(|_| crate::error::Error::Other("Database already initialized".to_string()))
136135
}
137136

138137
/// Get the global database instance. Panics if `init_db` was not called.
139138
pub fn get_db() -> &'static Database {
140-
DB.get().expect("Database not initialized. Call init_db() first.")
139+
DB.get()
140+
.expect("Database not initialized. Call init_db() first.")
141141
}
142142

143143
#[cfg(test)]
@@ -192,7 +192,10 @@ mod tests {
192192
base_version: 6,
193193
config_version: 1,
194194
uuid: "fd9b2602-62c5-4d55-bd1e-0d6537714ca0".to_string(),
195-
info: Info { hub_name: "GitHub".to_string(), hub_icon_url: None },
195+
info: Info {
196+
hub_name: "GitHub".to_string(),
197+
hub_icon_url: None,
198+
},
196199
api_keywords: vec!["owner".to_string(), "repo".to_string()],
197200
app_url_templates: vec![],
198201
target_check_api: None,
@@ -203,7 +206,9 @@ mod tests {
203206
assert_eq!(hubs.len(), 1);
204207
assert_eq!(hubs[0].uuid, "fd9b2602-62c5-4d55-bd1e-0d6537714ca0");
205208

206-
let deleted = db.delete_hub("fd9b2602-62c5-4d55-bd1e-0d6537714ca0").unwrap();
209+
let deleted = db
210+
.delete_hub("fd9b2602-62c5-4d55-bd1e-0d6537714ca0")
211+
.unwrap();
207212
assert!(deleted);
208213
assert!(db.load_hubs().unwrap().is_empty());
209214
}

src/database/models/extra_app.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ mod tests {
2828
fn test_serialization_roundtrip() {
2929
let record = ExtraAppRecord {
3030
id: "test-uuid".to_string(),
31-
app_id: HashMap::from([("android_app_package".to_string(), Some("com.foo".to_string()))]),
31+
app_id: HashMap::from([(
32+
"android_app_package".to_string(),
33+
Some("com.foo".to_string()),
34+
)]),
3235
mark_version_number: Some("1.2.3".to_string()),
3336
};
3437
let json = serde_json::to_string(&record).unwrap();

src/database/store.rs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ mod tests {
162162
#[test]
163163
fn test_upsert_and_load() {
164164
let (store, _tmp) = make_store();
165-
let r = TestRecord { id: "1".to_string(), value: "hello".to_string() };
165+
let r = TestRecord {
166+
id: "1".to_string(),
167+
value: "hello".to_string(),
168+
};
166169
store.upsert(&r).unwrap();
167170
let records: Vec<TestRecord> = store.load_all().unwrap();
168171
assert_eq!(records.len(), 1);
@@ -172,8 +175,18 @@ mod tests {
172175
#[test]
173176
fn test_upsert_updates_existing() {
174177
let (store, _tmp) = make_store();
175-
store.upsert(&TestRecord { id: "1".to_string(), value: "old".to_string() }).unwrap();
176-
store.upsert(&TestRecord { id: "1".to_string(), value: "new".to_string() }).unwrap();
178+
store
179+
.upsert(&TestRecord {
180+
id: "1".to_string(),
181+
value: "old".to_string(),
182+
})
183+
.unwrap();
184+
store
185+
.upsert(&TestRecord {
186+
id: "1".to_string(),
187+
value: "new".to_string(),
188+
})
189+
.unwrap();
177190
let records: Vec<TestRecord> = store.load_all().unwrap();
178191
assert_eq!(records.len(), 1);
179192
assert_eq!(records[0].value, "new");
@@ -183,7 +196,12 @@ mod tests {
183196
fn test_multiple_records() {
184197
let (store, _tmp) = make_store();
185198
for i in 0..5 {
186-
store.upsert(&TestRecord { id: i.to_string(), value: format!("v{i}") }).unwrap();
199+
store
200+
.upsert(&TestRecord {
201+
id: i.to_string(),
202+
value: format!("v{i}"),
203+
})
204+
.unwrap();
187205
}
188206
let records: Vec<TestRecord> = store.load_all().unwrap();
189207
assert_eq!(records.len(), 5);
@@ -192,8 +210,18 @@ mod tests {
192210
#[test]
193211
fn test_delete() {
194212
let (store, _tmp) = make_store();
195-
store.upsert(&TestRecord { id: "1".to_string(), value: "a".to_string() }).unwrap();
196-
store.upsert(&TestRecord { id: "2".to_string(), value: "b".to_string() }).unwrap();
213+
store
214+
.upsert(&TestRecord {
215+
id: "1".to_string(),
216+
value: "a".to_string(),
217+
})
218+
.unwrap();
219+
store
220+
.upsert(&TestRecord {
221+
id: "2".to_string(),
222+
value: "b".to_string(),
223+
})
224+
.unwrap();
197225
let deleted = store.delete::<TestRecord>("1").unwrap();
198226
assert!(deleted);
199227
let records: Vec<TestRecord> = store.load_all().unwrap();
@@ -211,7 +239,12 @@ mod tests {
211239
#[test]
212240
fn test_find_by_id() {
213241
let (store, _tmp) = make_store();
214-
store.upsert(&TestRecord { id: "42".to_string(), value: "answer".to_string() }).unwrap();
242+
store
243+
.upsert(&TestRecord {
244+
id: "42".to_string(),
245+
value: "answer".to_string(),
246+
})
247+
.unwrap();
215248
let found: Option<TestRecord> = store.find_by_id("42").unwrap();
216249
assert!(found.is_some());
217250
assert_eq!(found.unwrap().value, "answer");

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod database;
55
pub mod downloader;
66
mod error;
77
mod locale;
8+
pub mod manager;
89
pub mod rpc;
910
mod utils;
1011
mod websdk;

0 commit comments

Comments
 (0)