Skip to content

Commit

Permalink
Implement built in updater (#6)
Browse files Browse the repository at this point in the history
* implement release check api

* add options for updater

* fix settings scroll

* minor preference reorganization

* implement initial release properties

* add downloading code

* change download api

* add extraction code

* fix modifier padding

* update geode status after update

* set stored release after update

* disable updater by default for armv8

* add settings toasts

* use snackbar instead of toast

* small cleanup

* remove unused constant

* implement stable channel

* child doesn't require viewmodel

* update release format

* enable updater by default for all archs

* modify updater to be global

* fix copyfile reference

* correct state ordering issue

* only allow one update at a time

* show message in settings on second update

* allow update cancellation and retry

* disable start until update finished

* fix countdown lifecycle

* always sync release state to main activity

* allow scrolling main activity

* use a library for internal downloads
mat allowed me to

* show download progress in settings

* no internet messages

* enable api request cache

* delete old library before extracting

* oops....
  • Loading branch information
qimiko authored Jan 6, 2024
1 parent c421e37 commit 4c55588
Show file tree
Hide file tree
Showing 17 changed files with 1,181 additions and 206 deletions.
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.plugin.serialization'
}

android {
Expand Down Expand Up @@ -65,10 +66,16 @@ dependencies {
implementation 'androidx.compose.material3:material3:1.1.2'
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2"
implementation 'androidx.activity:activity-compose:1.8.2'
implementation 'androidx.activity:activity-ktx:1.8.2'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation "com.squareup.okio:okio:3.7.0"
implementation "com.squareup.okhttp3:okhttp:4.12.0"
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0'
implementation 'org.jetbrains.kotlinx:kotlinx-datetime:0.5.0'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json-okio:1.6.0"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
51 changes: 0 additions & 51 deletions app/src/main/java/com/geode/launcher/DownloadGeode.kt

This file was deleted.

43 changes: 15 additions & 28 deletions app/src/main/java/com/geode/launcher/GeometryDashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import androidx.core.view.WindowInsetsControllerCompat
import com.customRobTop.BaseRobTopActivity
import com.customRobTop.JniToCpp
import com.geode.launcher.utils.Constants
import com.geode.launcher.utils.DownloadUtils
import com.geode.launcher.utils.LaunchUtils
import com.geode.launcher.utils.GeodeUtils
import com.geode.launcher.utils.PreferenceUtils
import org.cocos2dx.lib.Cocos2dxEditText
import org.cocos2dx.lib.Cocos2dxGLSurfaceView
import org.cocos2dx.lib.Cocos2dxHelper
Expand All @@ -33,8 +35,6 @@ import org.fmod.FMOD
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream


class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperListener {
Expand Down Expand Up @@ -149,7 +149,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
// there doesn't seem to be a way to load a library from a file descriptor
val libraryCopy = File(cacheDir, "lib$libraryName.so")
val libraryOutput = libraryCopy.outputStream()
copyFile(libraryFd.createInputStream(), libraryOutput)
DownloadUtils.copyFile(libraryFd.createInputStream(), libraryOutput)

System.load(libraryCopy.path)

Expand Down Expand Up @@ -190,7 +190,8 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
return true
} catch (e: UnsatisfiedLinkError) {
// but users may prefer it stored with data
val geodePath = File(filesDir.path, "launcher/Geode.so")
val geodeFilename = LaunchUtils.getGeodeFilename()
val geodePath = File(filesDir.path, "launcher/$geodeFilename")
if (geodePath.exists()) {
System.load(geodePath.path)
return true
Expand All @@ -211,7 +212,10 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
val geodePath = File(copiedPath.path, "Geode.so")

if (externalGeodePath.exists()) {
copyFile(FileInputStream(externalGeodePath), FileOutputStream(geodePath))
DownloadUtils.copyFile(
FileInputStream(externalGeodePath),
FileOutputStream(geodePath)
)

if (geodePath.exists()) {
try {
Expand Down Expand Up @@ -395,9 +399,8 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
}

private fun getLoadTesting(): Boolean {
val preferences = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE)

return preferences.getBoolean(getString(R.string.preference_load_testing), false)
val preferences = PreferenceUtils.get(this)
return preferences.getBoolean(PreferenceUtils.Key.LOAD_TESTING)
}

@SuppressLint("UnsafeDynamicallyLoadedCode")
Expand All @@ -416,7 +419,10 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
if (it.isFile) {
// welcome to the world of Android classloader permissions
val outputFile = File(testDirPath.path + File.separator + it.name)
copyFile(FileInputStream(it), FileOutputStream(outputFile))
DownloadUtils.copyFile(
FileInputStream(it),
FileOutputStream(outputFile)
)

try {
println("Loading test library ${outputFile.name}")
Expand All @@ -428,23 +434,4 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
}
}
}

private fun copyFile(inputStream: InputStream, outputStream: OutputStream) {
// gotta love copying
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
FileUtils.copy(inputStream, outputStream)
} else {
inputStream.use { input ->
outputStream.use { output ->
val buffer = ByteArray(4 * 1024)
while (true) {
val byteCount = input.read(buffer)
if (byteCount < 0) break
output.write(buffer, 0, byteCount)
}
output.flush()
}
}
}
}
}
Loading

0 comments on commit 4c55588

Please sign in to comment.