-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
350 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/AndroidPlatformContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package io.rebble.cobble.shared | ||
|
||
import android.content.Context | ||
import io.rebble.libpebblecommon.packets.PhoneAppVersion | ||
|
||
class AndroidPlatformContext( | ||
val applicationContext: android.content.Context | ||
val applicationContext: Context | ||
) : PlatformContext { | ||
override val osType: PhoneAppVersion.OSType = PhoneAppVersion.OSType.Android | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/domain/pbw/PbwApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package io.rebble.cobble.shared.domain.pbw | ||
|
||
import io.rebble.cobble.shared.Logging | ||
import io.rebble.cobble.shared.PlatformContext | ||
import io.rebble.cobble.shared.database.AppDatabase | ||
import io.rebble.cobble.shared.database.NextSyncAction | ||
import io.rebble.cobble.shared.database.dao.LockerDao | ||
import io.rebble.cobble.shared.database.entity.SyncedLockerEntry | ||
import io.rebble.cobble.shared.database.entity.SyncedLockerEntryPlatform | ||
import io.rebble.cobble.shared.database.entity.SyncedLockerEntryPlatformImages | ||
import io.rebble.cobble.shared.database.getDatabase | ||
import io.rebble.cobble.shared.handlers.savePbwFile | ||
import io.rebble.cobble.shared.jobs.LockerSyncJob | ||
import io.rebble.cobble.shared.util.* | ||
import io.rebble.libpebblecommon.disk.PbwBinHeader | ||
import io.rebble.libpebblecommon.metadata.WatchType | ||
import io.rebble.libpebblecommon.util.DataBuffer | ||
import okio.buffer | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
class PbwApp(uri: String): KoinComponent { | ||
private val platformContext: PlatformContext by inject() | ||
private val file = File(uri) | ||
private val lockerDao: LockerDao by inject() | ||
init { | ||
require(file.exists()) | ||
} | ||
|
||
val info by lazy { requirePbwAppInfo(file) } | ||
|
||
fun getManifest(watchType: WatchType) = requirePbwManifest(file, watchType) | ||
|
||
suspend fun installToLockerCache(): Boolean { | ||
val exists = lockerDao.getEntryByUuid(info.uuid) | ||
lockerDao.insertOrReplace( | ||
SyncedLockerEntry( | ||
id = exists?.entry?.id ?: "", | ||
uuid = info.uuid, | ||
version = info.versionLabel, | ||
title = info.shortName, | ||
type = if (info.watchapp.watchface) "watchface" else "watchapp", | ||
hearts = 0, | ||
developerName = info.companyName, | ||
developerId = null, | ||
configurable = info.capabilities.any { it == "configurable" }, | ||
timelineEnabled = false, //TODO | ||
removeLink = "", | ||
shareLink = "", | ||
pbwLink = "", | ||
pbwReleaseId = info.versionCode.toString(), | ||
pbwIconResourceId = 0, //TODO, | ||
NextSyncAction.Upload, | ||
order = -1, | ||
lastOpened = null, | ||
local = true | ||
) | ||
) | ||
|
||
val inserted = lockerDao.getEntryByUuid(info.uuid) ?: return false | ||
|
||
if (exists != null) { | ||
lockerDao.clearPlatformsFor(exists.entry.id) | ||
} | ||
|
||
val platforms = WatchType.entries.mapNotNull { | ||
val manifest = getPbwManifest(file, it) | ||
if (manifest != null) { | ||
val header = PbwBinHeader().apply { | ||
fromBytes(DataBuffer(requirePbwBinaryBlob(file, it, "pebble-app.bin") | ||
.buffer() | ||
.readByteArray((PbwBinHeader.SIZE+1).toLong()).asUByteArray() | ||
)) | ||
} | ||
|
||
SyncedLockerEntryPlatform( | ||
platformEntryId = 0, | ||
lockerEntryId = inserted.entry.id, | ||
sdkVersion = "${header.sdkVersionMajor.get()}.${header.sdkVersionMinor.get()}", | ||
processInfoFlags = header.flags.get().toInt(), | ||
name = it.codename, | ||
description = "", | ||
images = SyncedLockerEntryPlatformImages( | ||
null, | ||
null, | ||
null | ||
) | ||
) | ||
} else { | ||
null | ||
} | ||
} | ||
if (platforms.isEmpty()) { | ||
Logging.e("No platforms in PBW") | ||
return false | ||
} | ||
|
||
lockerDao.insertOrReplaceAllPlatforms(platforms) | ||
|
||
savePbwFile(platformContext, info.uuid, file.readChannel()) | ||
if (!LockerSyncJob().syncToDevice()) { | ||
Logging.e("Failed to sync locker to device") | ||
return false | ||
} | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/ui/nav/Routes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.