@@ -11,10 +11,28 @@ object ModuleDatabase {
1111
1212 fun enableModule (packageName : String ): Boolean {
1313 if (packageName == " lspd" ) return false
14- val values = ContentValues ().apply { put(" enabled" , 1 ) }
15- val changed =
16- ConfigCache .dbHelper.writableDatabase.update(
17- " modules" , values, " module_pkg_name = ?" , arrayOf(packageName)) > 0
14+ val db = ConfigCache .dbHelper.writableDatabase
15+ var changed = false
16+
17+ // First, check if it exists. If not, we need to "discover" it.
18+ val exists =
19+ db.compileStatement(" SELECT COUNT(*) FROM modules WHERE module_pkg_name = ?" )
20+ .apply { bindString(1 , packageName) }
21+ .simpleQueryForLong() > 0
22+ if (! exists) {
23+ val values =
24+ ContentValues ().apply {
25+ put(" module_pkg_name" , packageName)
26+ put(" apk_path" , " " ) // defer to cache updating
27+ put(" enabled" , 1 )
28+ }
29+ db.insert(" modules" , null , values)
30+ changed = true
31+ } else {
32+ val values = ContentValues ().apply { put(" enabled" , 1 ) }
33+ changed = db.update(" modules" , values, " module_pkg_name = ?" , arrayOf(packageName)) > 0
34+ }
35+
1836 if (changed) ConfigCache .requestCacheUpdate()
1937 return changed
2038 }
0 commit comments