mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-21 00:18:18 +00:00
Compare commits
139
Commits
1.3.3
...
multiline-input
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d2b5e0091 | ||
|
|
0b92f4a318 | ||
|
|
7d75825d01 | ||
|
|
c77271f45c | ||
|
|
09bb28d66f | ||
|
|
157952b6f7 | ||
|
|
352ff63ab0 | ||
|
|
91fc804dee | ||
|
|
87808b56b3 | ||
|
|
2c2884c3b8 | ||
|
|
74e91e7dc1 | ||
|
|
e3ffbf311e | ||
|
|
5ad77bca57 | ||
|
|
3be0127e04 | ||
|
|
458c837aba | ||
|
|
67ca7707d8 | ||
|
|
776a4fa468 | ||
|
|
9528eef313 | ||
|
|
9827fe36c1 | ||
|
|
ce44270b7a | ||
|
|
34e324c54d | ||
|
|
986e33ce03 | ||
|
|
91c06bde8c | ||
|
|
a9d40a7594 | ||
|
|
bb6146be37 | ||
|
|
071cf40d42 | ||
|
|
19f47f138a | ||
|
|
c070b5cfe0 | ||
|
|
4782431bae | ||
|
|
b63073c135 | ||
|
|
c029fed37d | ||
|
|
dacabda792 | ||
|
|
824d4395c7 | ||
|
|
bd502b56c2 | ||
|
|
6991598fcb | ||
|
|
2cc8e7215a | ||
|
|
5e81d1c70e | ||
|
|
b03ff6b735 | ||
|
|
220c1b0dd6 | ||
|
|
0a4fb091f4 | ||
|
|
110f74400c | ||
|
|
eed8020229 | ||
|
|
ceb3d5b461 | ||
|
|
53cd339213 | ||
|
|
327e9b4d39 | ||
|
|
10a0670a47 | ||
|
|
500d3ba015 | ||
|
|
1236180425 | ||
|
|
129ee40c0d | ||
|
|
a687f8464e | ||
|
|
b409a200bb | ||
|
|
acb07db6f2 | ||
|
|
0ae65971fc | ||
|
|
c4bd4333ca | ||
|
|
f9e30e549a | ||
|
|
1583f259b9 | ||
|
|
c090754129 | ||
|
|
31227860f4 | ||
|
|
edc2428f48 | ||
|
|
6f3473b4ca | ||
|
|
f0af12f466 | ||
|
|
5bea87f98c | ||
|
|
8617d900ee | ||
|
|
1d91357cad | ||
|
|
1d495cb26e | ||
|
|
31b5a8f16e | ||
|
|
b1c8690872 | ||
|
|
c01470ac5a | ||
|
|
98d3b76e4b | ||
|
|
4a5e4ce85c | ||
|
|
d3a3ab57a1 | ||
|
|
86a79f8cda | ||
|
|
5fdf3127ae | ||
|
|
e9635160d1 | ||
|
|
4e6f99c745 | ||
|
|
1fd72ba8bc | ||
|
|
03e12bf701 | ||
|
|
4ae10dba7b | ||
|
|
cad559f1d9 | ||
|
|
b60c564173 | ||
|
|
7c21431efe | ||
|
|
d345f4ccf8 | ||
|
|
6b70d8c6d0 | ||
|
|
5f8e2b0ac3 | ||
|
|
fa7a8d96ea | ||
|
|
291237d4f5 | ||
|
|
d4e85e3055 | ||
|
|
78992316e5 | ||
|
|
70333e3b5f | ||
|
|
492e1ac11c | ||
|
|
3daf5c48f0 | ||
|
|
e9e250191c | ||
|
|
9f5ccd9ef1 | ||
|
|
3661df2667 | ||
|
|
759ee4afd7 | ||
|
|
375f771e8a | ||
|
|
e6fa0d491d | ||
|
|
fa397dc036 | ||
|
|
c61d652229 | ||
|
|
63b697e25c | ||
|
|
d3fe2f0f41 | ||
|
|
cb50acca09 | ||
|
|
bdce61d160 | ||
|
|
a562f5ec75 | ||
|
|
d21ab708dc | ||
|
|
ba642fb2d3 | ||
|
|
70934a95ad | ||
|
|
50f4a5d8e3 | ||
|
|
d4bacc4afb | ||
|
|
8942971368 | ||
|
|
f801993d0e | ||
|
|
0c551c8276 | ||
|
|
4d189f44a9 | ||
|
|
044af3d50b | ||
|
|
e092c15004 | ||
|
|
03bb6cd8b8 | ||
|
|
b1daf9c6b1 | ||
|
|
317a4b52cc | ||
|
|
033057fb6b | ||
|
|
1c463da5c7 | ||
|
|
f8fcd81057 | ||
|
|
97576dbfb4 | ||
|
|
0bd64b7578 | ||
|
|
b59cde68b0 | ||
|
|
8ea6589ab6 | ||
|
|
79bed774aa | ||
|
|
b919736ce1 | ||
|
|
d9a4f12902 | ||
|
|
6258700bc4 | ||
|
|
a62bdcc51c | ||
|
|
8341c15475 | ||
|
|
ce8c9496de | ||
|
|
779a099c16 | ||
|
|
031c7d215f | ||
|
|
75596fefd2 | ||
|
|
efaeeba5ec | ||
|
|
3161ee0974 | ||
|
|
127fd1bfd1 | ||
|
|
b7be446ecd |
No files matched your search
@@ -1,9 +1,9 @@
|
|||||||
name: Update Website
|
name: Update Website
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
# release:
|
||||||
types:
|
# types:
|
||||||
- released
|
# - released
|
||||||
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
|||||||
@@ -10,3 +10,4 @@
|
|||||||
local.properties
|
local.properties
|
||||||
app/release/
|
app/release/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.kotlin/
|
||||||
+28
-21
@@ -1,21 +1,27 @@
|
|||||||
val composeCompiler: String by rootProject.extra
|
|
||||||
val composeBOM: String by rootProject.extra
|
val composeBOM: String by rootProject.extra
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
compilerOptions {
|
||||||
|
extraWarnings.set(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
id("org.jetbrains.kotlin.android")
|
id("org.jetbrains.kotlin.android")
|
||||||
id("org.jetbrains.kotlin.plugin.serialization")
|
id("org.jetbrains.kotlin.plugin.serialization")
|
||||||
|
id("org.jetbrains.kotlin.plugin.compose")
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdk = 34
|
compileSdk = 36
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.geode.launcher"
|
applicationId = "com.geode.launcher"
|
||||||
minSdk = 23
|
minSdk = 23
|
||||||
targetSdk = 34
|
targetSdk = 35
|
||||||
versionCode = 15
|
versionCode = 22
|
||||||
versionName = "1.3.3"
|
versionName = "1.6.1"
|
||||||
|
|
||||||
vectorDrawables {
|
vectorDrawables {
|
||||||
useSupportLibrary = true
|
useSupportLibrary = true
|
||||||
@@ -24,7 +30,7 @@ android {
|
|||||||
@Suppress("UnstableApiUsage")
|
@Suppress("UnstableApiUsage")
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
arguments("-DUSE_TULIPHOOK:BOOL=OFF", "-DANDROID_STL=c++_shared")
|
arguments("-DUSE_TULIPHOOK:BOOL=OFF", "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES:BOOL=OFF")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,9 +75,6 @@ android {
|
|||||||
compose = true
|
compose = true
|
||||||
buildConfig = true
|
buildConfig = true
|
||||||
}
|
}
|
||||||
composeOptions {
|
|
||||||
kotlinCompilerExtensionVersion = composeCompiler
|
|
||||||
}
|
|
||||||
packaging {
|
packaging {
|
||||||
resources {
|
resources {
|
||||||
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
||||||
@@ -79,30 +82,34 @@ android {
|
|||||||
}
|
}
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
|
version = "3.25.0+"
|
||||||
path = file("src/main/cpp/CMakeLists.txt")
|
path = file("src/main/cpp/CMakeLists.txt")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
namespace = "com.geode.launcher"
|
namespace = "com.geode.launcher"
|
||||||
ndkVersion = "26.3.11579264"
|
ndkVersion = "28.1.13356709"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation (platform("androidx.compose:compose-bom:$composeBOM"))
|
implementation (platform("androidx.compose:compose-bom:$composeBOM"))
|
||||||
implementation ("androidx.core:core-ktx:1.13.1")
|
implementation ("androidx.core:core-ktx:1.16.0")
|
||||||
implementation ("androidx.compose.ui:ui")
|
implementation ("androidx.compose.ui:ui")
|
||||||
implementation ("androidx.compose.material3:material3")
|
implementation ("androidx.compose.material3:material3")
|
||||||
implementation ("androidx.compose.ui:ui-tooling-preview")
|
implementation ("androidx.compose.ui:ui-tooling-preview")
|
||||||
implementation ("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0")
|
implementation ("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
|
||||||
implementation ("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.0")
|
implementation ("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.7")
|
||||||
implementation ("androidx.activity:activity-compose:1.9.0")
|
implementation ("androidx.activity:activity-compose:1.10.1")
|
||||||
implementation ("androidx.activity:activity-ktx:1.9.0")
|
implementation ("androidx.activity:activity-ktx:1.10.1")
|
||||||
implementation ("androidx.appcompat:appcompat:1.6.1")
|
implementation ("androidx.appcompat:appcompat:1.7.0")
|
||||||
implementation ("androidx.documentfile:documentfile:1.0.1")
|
implementation ("androidx.documentfile:documentfile:1.0.1")
|
||||||
implementation ("com.squareup.okio:okio:3.9.0")
|
implementation ("com.squareup.okio:okio:3.11.0")
|
||||||
implementation ("com.squareup.okhttp3:okhttp:4.12.0")
|
implementation ("com.squareup.okhttp3:okhttp:4.12.0")
|
||||||
implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
|
implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1")
|
||||||
implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json-okio:1.6.3")
|
implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json-okio:1.8.1")
|
||||||
implementation ("org.jetbrains.kotlinx:kotlinx-datetime:0.6.0")
|
implementation ("org.jetbrains.kotlinx:kotlinx-datetime:0.6.2")
|
||||||
|
implementation ("com.mikepenz:multiplatform-markdown-renderer-android:0.33.0")
|
||||||
|
implementation ("com.mikepenz:multiplatform-markdown-renderer-m3:0.33.0")
|
||||||
|
implementation ("androidx.browser:browser:1.8.0")
|
||||||
debugImplementation ("androidx.compose.ui:ui-tooling")
|
debugImplementation ("androidx.compose.ui:ui-tooling")
|
||||||
coreLibraryDesugaring ("com.android.tools:desugar_jdk_libs:2.0.4")
|
coreLibraryDesugaring ("com.android.tools:desugar_jdk_libs:2.1.5")
|
||||||
}
|
}
|
||||||
@@ -9,15 +9,19 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
|
<uses-permission
|
||||||
|
android:name="android.permission.READ_EXTERNAL_STORAGE"
|
||||||
android:maxSdkVersion="32" />
|
android:maxSdkVersion="32" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
<uses-permission
|
||||||
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
android:maxSdkVersion="32" />
|
android:maxSdkVersion="32" />
|
||||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
|
||||||
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.wifi"
|
android:name="android.hardware.wifi"
|
||||||
@@ -33,16 +37,27 @@
|
|||||||
android:fullBackupContent="@xml/backup_rules"
|
android:fullBackupContent="@xml/backup_rules"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
android:hasFragileUserData="true"
|
||||||
android:requestLegacyExternalStorage="true"
|
android:requestLegacyExternalStorage="true"
|
||||||
|
android:enableOnBackInvokedCallback="true"
|
||||||
android:theme="@style/Theme.GeodeLauncher"
|
android:theme="@style/Theme.GeodeLauncher"
|
||||||
tools:targetApi="31">
|
tools:targetApi="35">
|
||||||
<activity
|
<activity
|
||||||
android:name=".ApplicationLogsActivity"
|
android:name=".AltMainActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:theme="@style/Theme.GeodeLauncher" />
|
||||||
|
<activity
|
||||||
|
android:name=".preferences.DeveloperSettingsActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:label="@string/title_activity_developer_settings"
|
||||||
|
android:theme="@style/Theme.GeodeLauncher" />
|
||||||
|
<activity
|
||||||
|
android:name=".preferences.ApplicationLogsActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/title_activity_application_logs"
|
android:label="@string/title_activity_application_logs"
|
||||||
android:theme="@style/Theme.GeodeLauncher" />
|
android:theme="@style/Theme.GeodeLauncher" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".SettingsActivity"
|
android:name=".preferences.SettingsActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/title_activity_settings"
|
android:label="@string/title_activity_settings"
|
||||||
android:theme="@style/Theme.GeodeLauncher">
|
android:theme="@style/Theme.GeodeLauncher">
|
||||||
@@ -92,6 +107,10 @@
|
|||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/provider_paths" />
|
android:resource="@xml/provider_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.game_mode_config"
|
||||||
|
android:resource="@xml/game_mode_config" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -13,7 +13,7 @@ option(USE_TULIPHOOK "enables choice of hooking library" OFF)
|
|||||||
if (USE_TULIPHOOK)
|
if (USE_TULIPHOOK)
|
||||||
FetchContent_Declare(TulipHook
|
FetchContent_Declare(TulipHook
|
||||||
GIT_REPOSITORY https://github.com/geode-sdk/TulipHook.git
|
GIT_REPOSITORY https://github.com/geode-sdk/TulipHook.git
|
||||||
GIT_TAG 70122be72da7787dc42813ba0a992f3612e7871e
|
GIT_TAG 9aa1f95091ebac18c657d57b755f59d00fe6f1f8
|
||||||
)
|
)
|
||||||
|
|
||||||
set(TULIP_LINK_SOURCE ON CACHE INTERNAL "")
|
set(TULIP_LINK_SOURCE ON CACHE INTERNAL "")
|
||||||
@@ -24,8 +24,9 @@ if (USE_TULIPHOOK)
|
|||||||
target_link_libraries(launcherfix PRIVATE TulipHook TulipHookInclude)
|
target_link_libraries(launcherfix PRIVATE TulipHook TulipHookInclude)
|
||||||
else()
|
else()
|
||||||
FetchContent_Declare(dobby
|
FetchContent_Declare(dobby
|
||||||
|
# this is the last version that builds on android at all
|
||||||
GIT_REPOSITORY https://github.com/jmpews/Dobby
|
GIT_REPOSITORY https://github.com/jmpews/Dobby
|
||||||
GIT_TAG 6a80a61ea062424d1595613058a174c64454fa57
|
GIT_TAG 0932d69c320e786672361ab53825ba8f4245e9d3
|
||||||
)
|
)
|
||||||
|
|
||||||
FetchContent_GetProperties(dobby)
|
FetchContent_GetProperties(dobby)
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdint>
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
#include <link.h>
|
||||||
|
|
||||||
#ifndef DISABLE_LAUNCHER_FIX
|
#ifndef DISABLE_LAUNCHER_FIX
|
||||||
|
|
||||||
@@ -15,8 +19,9 @@
|
|||||||
|
|
||||||
class DataPaths {
|
class DataPaths {
|
||||||
public:
|
public:
|
||||||
std::string original_data_path;
|
std::string original_data_path{};
|
||||||
std::string data_path;
|
std::string data_path{};
|
||||||
|
std::string load_symbols_from{};
|
||||||
|
|
||||||
static DataPaths& get_instance() {
|
static DataPaths& get_instance() {
|
||||||
static auto paths_instance = DataPaths();
|
static auto paths_instance = DataPaths();
|
||||||
@@ -24,7 +29,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DataPaths() : original_data_path(), data_path() {}
|
DataPaths() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@@ -41,6 +46,20 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setDataPath(
|
|||||||
env->ReleaseStringUTFChars(data_path, data_path_str);
|
env->ReleaseStringUTFChars(data_path, data_path_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_enableCustomSymbolList(
|
||||||
|
JNIEnv* env,
|
||||||
|
jobject,
|
||||||
|
jstring symbol_path
|
||||||
|
) {
|
||||||
|
auto is_copy = jboolean();
|
||||||
|
auto symbol_path_str = env->GetStringUTFChars(symbol_path, &is_copy);
|
||||||
|
|
||||||
|
DataPaths::get_instance().load_symbols_from = std::string(symbol_path_str);
|
||||||
|
|
||||||
|
env->ReleaseStringUTFChars(symbol_path, symbol_path_str);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setOriginalDataPath(
|
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setOriginalDataPath(
|
||||||
JNIEnv *env,
|
JNIEnv *env,
|
||||||
@@ -55,9 +74,200 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setOriginalDataPath(
|
|||||||
env->ReleaseStringUTFChars(data_path, data_path_str);
|
env->ReleaseStringUTFChars(data_path, data_path_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string redirect_path(const char* pathname) {
|
// i copied this function from the android linker
|
||||||
auto data_path = DataPaths::get_instance().data_path;
|
std::uint32_t elfhash(const char *_name) {
|
||||||
auto original_data_path = DataPaths::get_instance().original_data_path;
|
const unsigned char *name = reinterpret_cast<const unsigned char*>(_name);
|
||||||
|
std::uint32_t h = 0, g;
|
||||||
|
|
||||||
|
while (*name) {
|
||||||
|
h = (h << 4) + *name++;
|
||||||
|
g = h & 0xf0000000;
|
||||||
|
h ^= g;
|
||||||
|
h ^= g >> 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::array<std::uint8_t, 3> SYMBOL_PATCH_VALUE{":3"};
|
||||||
|
|
||||||
|
bool patch_symbol(std::uint32_t* hash_table, char* str_table, ElfW(Sym)* sym_table, const char* orig_name) {
|
||||||
|
auto hash = elfhash(orig_name);
|
||||||
|
|
||||||
|
auto nbucket = hash_table[0];
|
||||||
|
auto nchain = hash_table[1];
|
||||||
|
auto bucket = &hash_table[2];
|
||||||
|
auto chain = &bucket[nbucket];
|
||||||
|
|
||||||
|
for (auto i = bucket[hash % nbucket]; i != 0; i = chain[i]) {
|
||||||
|
auto sym = sym_table + i;
|
||||||
|
auto sym_name = str_table + sym->st_name;
|
||||||
|
|
||||||
|
if (strcmp(sym_name, orig_name) == 0) {
|
||||||
|
// there's probably no point to checking this, honestly
|
||||||
|
if (ELF_ST_BIND(sym->st_info) == STB_GLOBAL && ELF_ST_TYPE(sym->st_info) == STT_FUNC) {
|
||||||
|
// we found it! now go rename the symbol
|
||||||
|
|
||||||
|
#ifdef USE_TULIPHOOK
|
||||||
|
auto res = tulip::hook::writeMemory(sym_name, SYMBOL_PATCH_VALUE.data(), SYMBOL_PATCH_VALUE.size());
|
||||||
|
if (!res) {
|
||||||
|
__android_log_print(ANDROID_LOG_WARN, "GeodeLauncher-fix", "failed to patch symbol: %s", res.unwrapErr().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
DobbyCodePatch(reinterpret_cast<void*>(sym_name), SYMBOL_PATCH_VALUE.data(), SYMBOL_PATCH_VALUE.size());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__android_log_print(ANDROID_LOG_WARN, "GeodeLauncher-fix", "could not find symbol %s to patch (hash: %u)", orig_name, hash);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> get_symbols_listing() {
|
||||||
|
auto symbol_path = DataPaths::get_instance().load_symbols_from;
|
||||||
|
if (symbol_path.empty()) {
|
||||||
|
// this is every function that i thought would be relevant
|
||||||
|
return {
|
||||||
|
"__gxx_personality_v0",
|
||||||
|
"__cxa_throw",
|
||||||
|
"__cxa_rethrow",
|
||||||
|
"__cxa_allocate_exception",
|
||||||
|
"__cxa_end_catch",
|
||||||
|
"__cxa_begin_catch",
|
||||||
|
"__cxa_guard_abort",
|
||||||
|
"__cxa_guard_acquire",
|
||||||
|
"__cxa_guard_release",
|
||||||
|
"__cxa_free_exception"
|
||||||
|
|
||||||
|
// android 10's libc doesn't have these symbols
|
||||||
|
// and the ndk is forbidden from exporting them!! so keep it for old mods...
|
||||||
|
// "_Unwind_RaiseException",
|
||||||
|
// "_Unwind_Resume"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream symbol_file{symbol_path};
|
||||||
|
if (!symbol_file) {
|
||||||
|
__android_log_print(ANDROID_LOG_WARN, "GeodeLauncher-fix", "failed to read symbol file at %s", symbol_path.c_str());
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> symbols_list{};
|
||||||
|
std::string current_line{};
|
||||||
|
while (std::getline(symbol_file, current_line)) {
|
||||||
|
if (!current_line.empty()) {
|
||||||
|
symbols_list.push_back(current_line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return symbols_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
int on_dl_iterate(dl_phdr_info* info, size_t size, void* data) {
|
||||||
|
// this is probably going to be gd
|
||||||
|
if (info->dlpi_name != nullptr && strstr(info->dlpi_name, "libcocos2dcpp.so") != nullptr) {
|
||||||
|
// step 1: get the dynamic table
|
||||||
|
std::uintptr_t dyn_addr = 0u;
|
||||||
|
|
||||||
|
for (auto i = 0u; i < info->dlpi_phnum; i++) {
|
||||||
|
auto phdr = info->dlpi_phdr + i;
|
||||||
|
|
||||||
|
if (phdr->p_type == PT_DYNAMIC) {
|
||||||
|
dyn_addr = info->dlpi_addr + phdr->p_vaddr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dyn_addr == 0u) {
|
||||||
|
__android_log_print(ANDROID_LOG_WARN, "GeodeLauncher-fix", "failed to find libcocos dynamic section");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// step 2: get the symbol table
|
||||||
|
auto dyn_entry = reinterpret_cast<ElfW(Dyn)*>(dyn_addr);
|
||||||
|
auto dyn_end_reached = false;
|
||||||
|
|
||||||
|
std::uintptr_t sym_table_addr = 0u;
|
||||||
|
std::uintptr_t str_table_addr = 0u;
|
||||||
|
std::uintptr_t hash_table_addr = 0u;
|
||||||
|
std::uintptr_t soname_idx = 0u;
|
||||||
|
|
||||||
|
while (!dyn_end_reached) {
|
||||||
|
auto tag = dyn_entry->d_tag;
|
||||||
|
|
||||||
|
switch (dyn_entry->d_tag) {
|
||||||
|
case DT_SYMTAB:
|
||||||
|
sym_table_addr = info->dlpi_addr + dyn_entry->d_un.d_val;
|
||||||
|
break;
|
||||||
|
case DT_STRTAB:
|
||||||
|
str_table_addr = info->dlpi_addr + dyn_entry->d_un.d_val;
|
||||||
|
break;
|
||||||
|
case DT_HASH:
|
||||||
|
hash_table_addr = info->dlpi_addr + dyn_entry->d_un.d_val;
|
||||||
|
break;
|
||||||
|
case DT_SONAME:
|
||||||
|
soname_idx = dyn_entry->d_un.d_val;
|
||||||
|
break;
|
||||||
|
case DT_NULL:
|
||||||
|
dyn_end_reached = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dyn_entry++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hash_table_addr == 0u || str_table_addr == 0u || sym_table_addr == 0u) {
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR, "GeodeLauncher-fix", "failed to parse dynamic section (at least one table is null)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// patch symbol names
|
||||||
|
auto hash_table = reinterpret_cast<std::uint32_t*>(hash_table_addr);
|
||||||
|
auto str_table = reinterpret_cast<char*>(str_table_addr);
|
||||||
|
auto sym_table = reinterpret_cast<ElfW(Sym)*>(sym_table_addr);
|
||||||
|
|
||||||
|
auto so_name = str_table + soname_idx;
|
||||||
|
if (strcmp(so_name, "libcocos2dcpp.so") != 0) {
|
||||||
|
__android_log_print(ANDROID_LOG_WARN, "GeodeLauncher-fix", "DT_SONAME gives us %s! that's not good", so_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto has_error = false;
|
||||||
|
auto symbols_listing = get_symbols_listing();
|
||||||
|
for (const auto& symbol : symbols_listing) {
|
||||||
|
if (!patch_symbol(hash_table, str_table, sym_table, symbol.c_str())) {
|
||||||
|
has_error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_error) {
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO,
|
||||||
|
"GeodeLauncher-fix",
|
||||||
|
"symbol patch diagnostics\nlibrary path: %s\naddrs: base=%p sym=%p str=%p hash=%p",
|
||||||
|
info->dlpi_name, reinterpret_cast<void*>(info->dlpi_addr), sym_table, str_table, hash_table
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// this should be called after gd is loaded but before geode
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT int JNICALL Java_com_geode_launcher_LauncherFix_performExceptionsRenaming(JNIEnv*, jobject) {
|
||||||
|
return dl_iterate_phdr(on_dl_iterate, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> redirect_path(const char* pathname) {
|
||||||
|
auto& data_path = DataPaths::get_instance().data_path;
|
||||||
|
auto& original_data_path = DataPaths::get_instance().original_data_path;
|
||||||
|
|
||||||
if (!data_path.empty() && !original_data_path.empty()) {
|
if (!data_path.empty() && !original_data_path.empty()) {
|
||||||
// call this a c string optimization
|
// call this a c string optimization
|
||||||
@@ -68,22 +278,26 @@ std::string redirect_path(const char* pathname) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathname;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* (*fopen_original)(const char *pathname, const char *mode);
|
FILE* (*fopen_original)(const char *pathname, const char *mode);
|
||||||
FILE* fopen_hook(const char* pathname, const char* mode) {
|
FILE* fopen_hook(const char* pathname, const char* mode) {
|
||||||
auto path_str = redirect_path(pathname);
|
auto path_str = redirect_path(pathname);
|
||||||
|
auto redirect = path_str.has_value() ? path_str->c_str() : pathname;
|
||||||
|
|
||||||
return fopen_original(path_str.c_str(), mode);
|
return fopen_original(redirect, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int (*rename_original)(const char* old_path, const char* new_path);
|
int (*rename_original)(const char* old_path, const char* new_path);
|
||||||
int rename_hook(const char* old_path, const char* new_path) {
|
int rename_hook(const char* old_path, const char* new_path) {
|
||||||
auto old_path_str = redirect_path(old_path);
|
auto old_path_str = redirect_path(old_path);
|
||||||
auto new_path_str = redirect_path(new_path);
|
auto old_redirect = old_path_str ? old_path_str->c_str() : old_path;
|
||||||
|
|
||||||
return rename_original(old_path_str.c_str(), new_path_str.c_str());
|
auto new_path_str = redirect_path(new_path);
|
||||||
|
auto new_redirect = new_path_str ? new_path_str->c_str() : new_path;
|
||||||
|
|
||||||
|
return rename_original(old_redirect, new_redirect);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hook_function(void* addr, auto* hook, auto** orig) {
|
bool hook_function(void* addr, auto* hook, auto** orig) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.customRobTop
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.KeyguardManager
|
|
||||||
import android.content.*
|
import android.content.*
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.NetworkCapabilities
|
import android.net.NetworkCapabilities
|
||||||
@@ -11,7 +10,6 @@ import android.os.Build
|
|||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.customRobTop.JniToCpp.resumeSound
|
|
||||||
import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.closeIMEKeyboard
|
import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.closeIMEKeyboard
|
||||||
import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.openIMEKeyboard
|
import org.cocos2dx.lib.Cocos2dxGLSurfaceView.Companion.openIMEKeyboard
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
@@ -259,29 +257,4 @@ object BaseRobTopActivity {
|
|||||||
level = DeprecationLevel.HIDDEN
|
level = DeprecationLevel.HIDDEN
|
||||||
)
|
)
|
||||||
fun logEvent(event: String) {}
|
fun logEvent(event: String) {}
|
||||||
|
|
||||||
class ReceiverScreen : BroadcastReceiver() {
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
|
||||||
when (intent.action) {
|
|
||||||
Intent.ACTION_SCREEN_ON -> {
|
|
||||||
Log.d("TAG", "ACTION_SCREEN_ON")
|
|
||||||
if (!(me.get()?.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isKeyguardLocked) {
|
|
||||||
shouldResumeSound = true
|
|
||||||
}
|
|
||||||
if (!isPaused && shouldResumeSound) {
|
|
||||||
resumeSound()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Intent.ACTION_SCREEN_OFF -> {
|
|
||||||
shouldResumeSound = false
|
|
||||||
}
|
|
||||||
Intent.ACTION_USER_PRESENT -> {
|
|
||||||
shouldResumeSound = true
|
|
||||||
if (!isPaused) {
|
|
||||||
resumeSound()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,522 @@
|
|||||||
|
package com.geode.launcher
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.text.format.Formatter
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.activity.compose.setContent
|
||||||
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||||
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Info
|
||||||
|
import androidx.compose.material.icons.filled.PlayArrow
|
||||||
|
import androidx.compose.material.icons.filled.Refresh
|
||||||
|
import androidx.compose.material.icons.filled.Settings
|
||||||
|
import androidx.compose.material.icons.filled.Warning
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.FilledTonalButton
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
|
import androidx.compose.material3.LocalTextStyle
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import com.geode.launcher.main.*
|
||||||
|
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
||||||
|
import com.geode.launcher.ui.theme.LocalTheme
|
||||||
|
import com.geode.launcher.ui.theme.Theme
|
||||||
|
import com.geode.launcher.utils.Constants
|
||||||
|
import com.geode.launcher.utils.GamePackageUtils
|
||||||
|
import com.geode.launcher.utils.LaunchUtils
|
||||||
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class AltMainActivity : ComponentActivity() {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
enableEdgeToEdge()
|
||||||
|
clearDownloadedApks(this)
|
||||||
|
|
||||||
|
val gdInstalled = GamePackageUtils.isGameInstalled(packageManager)
|
||||||
|
val geodeInstalled = LaunchUtils.isGeodeInstalled(this)
|
||||||
|
|
||||||
|
val returnMessage = intent.extras?.getString(LaunchUtils.LAUNCHER_KEY_RETURN_MESSAGE)
|
||||||
|
val returnExtendedMessage = intent.extras?.getString(LaunchUtils.LAUNCHER_KEY_RETURN_EXTENDED_MESSAGE)
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION") // the new api is android 13 only (why)
|
||||||
|
val returnError = intent.extras?.getSerializable(LaunchUtils.LAUNCHER_KEY_RETURN_ERROR)
|
||||||
|
as? LaunchUtils.LauncherError
|
||||||
|
|
||||||
|
val loadFailureInfo = if (returnError != null && returnMessage != null) {
|
||||||
|
LoadFailureInfo(returnError, returnMessage, returnExtendedMessage)
|
||||||
|
} else if (LaunchUtils.lastSessionCrashed(this)) {
|
||||||
|
LoadFailureInfo(LaunchUtils.LauncherError.CRASHED)
|
||||||
|
} else { null }
|
||||||
|
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
|
||||||
|
val theme = Theme.fromInt(themeOption)
|
||||||
|
|
||||||
|
val backgroundOption by PreferenceUtils.useBooleanPreference(PreferenceUtils.Key.BLACK_BACKGROUND)
|
||||||
|
|
||||||
|
val launchViewModel = viewModel<LaunchViewModel>(factory = LaunchViewModel.Factory)
|
||||||
|
|
||||||
|
if (loadFailureInfo != null) {
|
||||||
|
launchViewModel.loadFailure = loadFailureInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
CompositionLocalProvider(LocalTheme provides theme) {
|
||||||
|
GeodeLauncherTheme(theme = theme, blackBackground = backgroundOption) {
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier.fillMaxSize()
|
||||||
|
) {
|
||||||
|
AltMainScreen(launchViewModel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gdInstalled && geodeInstalled) {
|
||||||
|
intent.getBooleanExtra("restarted", false).let {
|
||||||
|
if (it) {
|
||||||
|
onLaunch(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class LaunchStatusInfo(
|
||||||
|
val title: String?,
|
||||||
|
val details: String? = null,
|
||||||
|
val progress: (() -> Float)? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LaunchCancelledIcon(cancelReason: LaunchViewModel.LaunchCancelReason, modifier: Modifier = Modifier) {
|
||||||
|
when (cancelReason) {
|
||||||
|
LaunchViewModel.LaunchCancelReason.GAME_OUTDATED,
|
||||||
|
LaunchViewModel.LaunchCancelReason.GAME_MISSING -> Icon(painterResource(R.drawable.icon_error), contentDescription = null, modifier)
|
||||||
|
LaunchViewModel.LaunchCancelReason.LAST_LAUNCH_CRASHED,
|
||||||
|
LaunchViewModel.LaunchCancelReason.GEODE_NOT_FOUND -> Icon(Icons.Default.Warning, contentDescription = null, modifier)
|
||||||
|
else -> Icon(Icons.Default.Info, contentDescription = null, modifier)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun mapCancelReasonToInfo(cancelReason: LaunchViewModel.LaunchCancelReason): LaunchStatusInfo {
|
||||||
|
return when (cancelReason) {
|
||||||
|
LaunchViewModel.LaunchCancelReason.LAST_LAUNCH_CRASHED -> LaunchStatusInfo(
|
||||||
|
title = stringResource(R.string.launcher_cancelled_crash)
|
||||||
|
)
|
||||||
|
LaunchViewModel.LaunchCancelReason.GEODE_NOT_FOUND -> LaunchStatusInfo(
|
||||||
|
title = stringResource(R.string.geode_download_title)
|
||||||
|
)
|
||||||
|
LaunchViewModel.LaunchCancelReason.GAME_MISSING -> LaunchStatusInfo(
|
||||||
|
title = stringResource(R.string.launcher_cancelled_error),
|
||||||
|
details = stringResource(R.string.game_not_found)
|
||||||
|
)
|
||||||
|
LaunchViewModel.LaunchCancelReason.GAME_OUTDATED -> LaunchStatusInfo(
|
||||||
|
title = stringResource(R.string.launcher_cancelled_error),
|
||||||
|
details = stringResource(R.string.launcher_cancelled_outdated)
|
||||||
|
)
|
||||||
|
LaunchViewModel.LaunchCancelReason.AUTOMATIC,
|
||||||
|
LaunchViewModel.LaunchCancelReason.MANUAL-> LaunchStatusInfo(
|
||||||
|
title = null
|
||||||
|
)
|
||||||
|
else -> LaunchStatusInfo(
|
||||||
|
title = stringResource(R.string.launcher_cancelled_manual)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun mapLaunchStatusToInfo(state: LaunchViewModel.LaunchUIState, inSafeMode: Boolean = false): LaunchStatusInfo {
|
||||||
|
return when (state) {
|
||||||
|
is LaunchViewModel.LaunchUIState.Initial,
|
||||||
|
is LaunchViewModel.LaunchUIState.Working,
|
||||||
|
is LaunchViewModel.LaunchUIState.Ready -> LaunchStatusInfo(
|
||||||
|
title = stringResource(R.string.launcher_starting_game),
|
||||||
|
details = if (inSafeMode) stringResource(R.string.launcher_in_safe_mode) else null
|
||||||
|
)
|
||||||
|
is LaunchViewModel.LaunchUIState.UpdateCheck -> LaunchStatusInfo(
|
||||||
|
title = stringResource(R.string.release_fetch_in_progress)
|
||||||
|
)
|
||||||
|
is LaunchViewModel.LaunchUIState.Updating -> {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val downloaded = remember(state.downloaded) {
|
||||||
|
Formatter.formatShortFileSize(context, state.downloaded)
|
||||||
|
}
|
||||||
|
|
||||||
|
val outOf = remember(state.outOf) {
|
||||||
|
state.outOf?.run {
|
||||||
|
Formatter.formatShortFileSize(context, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchStatusInfo(
|
||||||
|
title = stringResource(R.string.launcher_downloading_update),
|
||||||
|
details = stringResource(R.string.launcher_downloading_update_details, downloaded, outOf ?: "…"),
|
||||||
|
progress = {
|
||||||
|
val progress = state.downloaded / state.outOf!!.toDouble()
|
||||||
|
progress.toFloat()
|
||||||
|
}.takeIf { state.outOf != null }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
is LaunchViewModel.LaunchUIState.Cancelled -> {
|
||||||
|
return mapCancelReasonToInfo(state.reason)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LaunchCancelledBody(statusInfo: LaunchStatusInfo, icon: @Composable () -> Unit, inProgress: Boolean, modifier: Modifier = Modifier) {
|
||||||
|
if (statusInfo.title == null && statusInfo.details == null && !inProgress) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
modifier = modifier.width(300.dp)
|
||||||
|
) {
|
||||||
|
if (statusInfo.title != null) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center) {
|
||||||
|
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) {
|
||||||
|
icon()
|
||||||
|
Spacer(Modifier.size(8.dp))
|
||||||
|
Text(statusInfo.title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inProgress) {
|
||||||
|
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusInfo.details != null) {
|
||||||
|
Text(
|
||||||
|
statusInfo.details,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LaunchProgressBody(statusInfo: LaunchStatusInfo, modifier: Modifier = Modifier) {
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
horizontalAlignment = Alignment.Start,
|
||||||
|
modifier = modifier.width(300.dp)
|
||||||
|
) {
|
||||||
|
if (statusInfo.title != null) {
|
||||||
|
Text(statusInfo.title, style = MaterialTheme.typography.bodyLarge)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusInfo.progress != null) {
|
||||||
|
LinearProgressIndicator(
|
||||||
|
statusInfo.progress,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusInfo.details != null) {
|
||||||
|
Text(statusInfo.details, style = MaterialTheme.typography.bodyMedium)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun RetryButtonContents(reason: LaunchViewModel.LaunchCancelReason) {
|
||||||
|
when (reason) {
|
||||||
|
LaunchViewModel.LaunchCancelReason.LAST_LAUNCH_CRASHED -> {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.icon_resume),
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(stringResource(R.string.launcher_cancelled_resume))
|
||||||
|
}
|
||||||
|
LaunchViewModel.LaunchCancelReason.MANUAL,
|
||||||
|
LaunchViewModel.LaunchCancelReason.AUTOMATIC -> {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.PlayArrow,
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(stringResource(R.string.launcher_launch))
|
||||||
|
}
|
||||||
|
LaunchViewModel.LaunchCancelReason.GEODE_NOT_FOUND -> {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Refresh,
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(stringResource(R.string.launcher_cancelled_retry))
|
||||||
|
}
|
||||||
|
// these shouldn't be allowing retries anyways
|
||||||
|
LaunchViewModel.LaunchCancelReason.GAME_MISSING,
|
||||||
|
LaunchViewModel.LaunchCancelReason.GAME_OUTDATED -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
|
@Composable
|
||||||
|
fun LaunchProgressCard(
|
||||||
|
uiState: LaunchViewModel.LaunchUIState,
|
||||||
|
crashInfo: LoadFailureInfo?,
|
||||||
|
onCancel: () -> Unit,
|
||||||
|
onResume: (safeMode: Boolean) -> Unit,
|
||||||
|
onMore: () -> Unit,
|
||||||
|
extraOptions: @Composable () -> Unit,
|
||||||
|
safeModeEnabled: Boolean,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
var showSafeModeDialog by remember { mutableStateOf(false) }
|
||||||
|
val status = mapLaunchStatusToInfo(uiState, safeModeEnabled)
|
||||||
|
|
||||||
|
Box(modifier = modifier) {
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
|
if (uiState is LaunchViewModel.LaunchUIState.Cancelled) {
|
||||||
|
LaunchCancelledBody(
|
||||||
|
statusInfo = status,
|
||||||
|
icon = { LaunchCancelledIcon(uiState.reason, Modifier.size(32.dp)) },
|
||||||
|
inProgress = uiState.inProgress
|
||||||
|
)
|
||||||
|
|
||||||
|
if (uiState.reason.isGameInstallIssue()) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val showDownload = remember { GamePackageUtils.showDownloadBadge(context.packageManager) }
|
||||||
|
|
||||||
|
if (showDownload) {
|
||||||
|
GooglePlayBadge(modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uiState.reason.allowsRetry()) {
|
||||||
|
FlowRow(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp, alignment = Alignment.CenterHorizontally),
|
||||||
|
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||||
|
) {
|
||||||
|
LongPressButton(onClick = { onResume(false) }, onLongPress = {
|
||||||
|
showSafeModeDialog = true
|
||||||
|
}) {
|
||||||
|
RetryButtonContents(uiState.reason)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crashInfo != null) {
|
||||||
|
FilledTonalButton(onClick = onMore) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.icon_question_mark),
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(stringResource(R.string.launcher_cancelled_help_alt))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extraOptions()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LaunchProgressBody(statusInfo = status, modifier = Modifier.padding(top = 16.dp))
|
||||||
|
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.width(300.dp)) {
|
||||||
|
TextButton(onClick = onCancel) {
|
||||||
|
Text(stringResource(R.string.release_fetch_button_cancel))
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(Modifier.weight(1.0f))
|
||||||
|
|
||||||
|
extraOptions()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showSafeModeDialog) {
|
||||||
|
SafeModeDialog(
|
||||||
|
onDismiss = {
|
||||||
|
showSafeModeDialog = false
|
||||||
|
},
|
||||||
|
onLaunch = {
|
||||||
|
onResume(true)
|
||||||
|
showSafeModeDialog = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ExtraOptions(onSettings: () -> Unit) {
|
||||||
|
IconButton(
|
||||||
|
onClick = onSettings,
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Settings,
|
||||||
|
contentDescription = stringResource(R.string.launcher_settings_icon_alt)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun GeodeLogo(modifier: Modifier = Modifier) {
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.Center,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = modifier
|
||||||
|
) {
|
||||||
|
Image(
|
||||||
|
painter = painterResource(id = R.drawable.geode_logo),
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(76.dp, 76.dp)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.launcher_title),
|
||||||
|
style = MaterialTheme.typography.displayMedium,
|
||||||
|
modifier = Modifier.padding(12.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun AltMainScreen(
|
||||||
|
launchViewModel: LaunchViewModel = viewModel(factory = LaunchViewModel.Factory)
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
launchViewModel.beginLaunchFlow()
|
||||||
|
}
|
||||||
|
|
||||||
|
val launchUIState by launchViewModel.uiState.collectAsState()
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
var launchInSafeMode by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
var showErrorInfo by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.safeDrawingPadding(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(8.dp)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
) {
|
||||||
|
GeodeLogo()
|
||||||
|
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
) {
|
||||||
|
LaunchProgressCard(
|
||||||
|
launchUIState,
|
||||||
|
crashInfo = launchViewModel.currentCrashInfo(),
|
||||||
|
onCancel = {
|
||||||
|
launchInSafeMode = false
|
||||||
|
coroutineScope.launch {
|
||||||
|
launchViewModel.cancelLaunch()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onResume = { safeMode ->
|
||||||
|
launchInSafeMode = safeMode
|
||||||
|
|
||||||
|
launchViewModel.clearCrashInfo()
|
||||||
|
coroutineScope.launch {
|
||||||
|
launchViewModel.beginLaunchFlow(true)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onMore = {
|
||||||
|
showErrorInfo = true
|
||||||
|
},
|
||||||
|
extraOptions = {
|
||||||
|
ExtraOptions(
|
||||||
|
onSettings = {
|
||||||
|
coroutineScope.launch {
|
||||||
|
launchViewModel.cancelLaunch(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
onSettings(context)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
safeModeEnabled = launchInSafeMode
|
||||||
|
)
|
||||||
|
|
||||||
|
// only show launcher update in a case where a user won't see it ingame
|
||||||
|
if (launchUIState is LaunchViewModel.LaunchUIState.Cancelled) {
|
||||||
|
val gameVersion = remember { GamePackageUtils.getGameVersionCodeOrNull(context.packageManager) }
|
||||||
|
|
||||||
|
if (gameVersion != null && gameVersion < Constants.SUPPORTED_VERSION_CODE_MIN_WARNING) {
|
||||||
|
UnsupportedVersionWarning()
|
||||||
|
}
|
||||||
|
|
||||||
|
val nextLauncherUpdate by launchViewModel.nextLauncherUpdate.collectAsState()
|
||||||
|
if (nextLauncherUpdate != null) {
|
||||||
|
LauncherUpdateIndicator()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (launchUIState is LaunchViewModel.LaunchUIState.Ready) {
|
||||||
|
UpdateWarning(launchInSafeMode) {
|
||||||
|
launchInSafeMode = false
|
||||||
|
coroutineScope.launch {
|
||||||
|
launchViewModel.cancelLaunch()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val loadFailure = launchViewModel.currentCrashInfo()
|
||||||
|
if (showErrorInfo && loadFailure != null) {
|
||||||
|
ErrorInfoSheet(loadFailure, onDismiss = { showErrorInfo = false })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,31 @@
|
|||||||
package com.geode.launcher
|
package com.geode.launcher
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.pm.ApplicationInfo
|
import android.content.pm.ApplicationInfo
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
|
import android.opengl.GLSurfaceView
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
|
import android.text.InputType
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.widget.AppCompatEditText
|
||||||
|
import androidx.compose.ui.platform.ComposeView
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.WindowInsetsControllerCompat
|
import androidx.core.view.WindowInsetsControllerCompat
|
||||||
import com.customRobTop.BaseRobTopActivity
|
import com.customRobTop.BaseRobTopActivity
|
||||||
import com.customRobTop.JniToCpp
|
import com.customRobTop.JniToCpp
|
||||||
|
import com.geode.launcher.main.LaunchNotification
|
||||||
|
import com.geode.launcher.main.determineDisplayedCards
|
||||||
import com.geode.launcher.utils.Constants
|
import com.geode.launcher.utils.Constants
|
||||||
import com.geode.launcher.utils.ConstrainedFrameLayout
|
import com.geode.launcher.utils.ConstrainedFrameLayout
|
||||||
import com.geode.launcher.utils.DownloadUtils
|
import com.geode.launcher.utils.DownloadUtils
|
||||||
@@ -28,7 +33,6 @@ import com.geode.launcher.utils.GamePackageUtils
|
|||||||
import com.geode.launcher.utils.GeodeUtils
|
import com.geode.launcher.utils.GeodeUtils
|
||||||
import com.geode.launcher.utils.LaunchUtils
|
import com.geode.launcher.utils.LaunchUtils
|
||||||
import com.geode.launcher.utils.PreferenceUtils
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
import org.cocos2dx.lib.Cocos2dxEditText
|
|
||||||
import org.cocos2dx.lib.Cocos2dxGLSurfaceView
|
import org.cocos2dx.lib.Cocos2dxGLSurfaceView
|
||||||
import org.cocos2dx.lib.Cocos2dxHelper
|
import org.cocos2dx.lib.Cocos2dxHelper
|
||||||
import org.cocos2dx.lib.Cocos2dxRenderer
|
import org.cocos2dx.lib.Cocos2dxRenderer
|
||||||
@@ -37,6 +41,9 @@ import java.io.File
|
|||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import javax.microedition.khronos.egl.EGL10
|
||||||
|
import javax.microedition.khronos.egl.EGLConfig
|
||||||
|
import javax.microedition.khronos.egl.EGLDisplay
|
||||||
|
|
||||||
enum class DisplayMode {
|
enum class DisplayMode {
|
||||||
DEFAULT, LIMITED, FULLSCREEN;
|
DEFAULT, LIMITED, FULLSCREEN;
|
||||||
@@ -50,18 +57,29 @@ enum class DisplayMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun ratioForPreference(value: String) = when (value) {
|
||||||
|
"4_3" -> 4/3.0f
|
||||||
|
"1_1" -> 1.0f
|
||||||
|
"16_10" -> 16/10.0f
|
||||||
|
else -> 1.77f
|
||||||
|
}
|
||||||
|
|
||||||
class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperListener, GeodeUtils.CapabilityListener {
|
class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperListener, GeodeUtils.CapabilityListener {
|
||||||
private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null
|
private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null
|
||||||
private val sTag = GeometryDashActivity::class.simpleName
|
|
||||||
private var mIsRunning = false
|
private var mIsRunning = false
|
||||||
private var mIsOnPause = false
|
private var mIsOnPause = false
|
||||||
private var mHasWindowFocus = false
|
private var mHasWindowFocus = false
|
||||||
private var mReceiver: BroadcastReceiver? = null
|
|
||||||
|
|
||||||
private var displayMode = DisplayMode.DEFAULT
|
private var displayMode = DisplayMode.DEFAULT
|
||||||
|
private var mForceRefreshRate = false
|
||||||
|
private var mLimitedRefreshRate: Int? = null
|
||||||
|
private var mAspectRatio = 0.0f
|
||||||
|
private var mScreenZoom = 1.0f
|
||||||
|
private var mScreenZoomFit = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
setupUIState()
|
setupUIState()
|
||||||
|
FMOD.init(this)
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
@@ -72,6 +90,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
createVersionFile()
|
||||||
tryLoadGame()
|
tryLoadGame()
|
||||||
} catch (e: UnsatisfiedLinkError) {
|
} catch (e: UnsatisfiedLinkError) {
|
||||||
Log.e("GeodeLauncher", "Library linkage failure", e)
|
Log.e("GeodeLauncher", "Library linkage failure", e)
|
||||||
@@ -84,6 +103,8 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
val errorMessage = when {
|
val errorMessage = when {
|
||||||
abiMismatch && is64bit -> LaunchUtils.LauncherError.LINKER_NEEDS_32BIT
|
abiMismatch && is64bit -> LaunchUtils.LauncherError.LINKER_NEEDS_32BIT
|
||||||
abiMismatch -> LaunchUtils.LauncherError.LINKER_NEEDS_64BIT
|
abiMismatch -> LaunchUtils.LauncherError.LINKER_NEEDS_64BIT
|
||||||
|
e.message?.contains("__gxx_personality_v0") == true ->
|
||||||
|
LaunchUtils.LauncherError.LINKER_FAILED_STL
|
||||||
else -> LaunchUtils.LauncherError.LINKER_FAILED
|
else -> LaunchUtils.LauncherError.LINKER_FAILED
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +122,20 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
mGLSurfaceView?.sendKeyBack()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
mGLSurfaceView?.manualBackEvents = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createVersionFile() {
|
||||||
|
val versionPath = File(filesDir, "game_version.txt")
|
||||||
|
val gameVersion = GamePackageUtils.getGameVersionCode(packageManager)
|
||||||
|
|
||||||
|
versionPath.writeText("$gameVersion")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun returnToMain(
|
private fun returnToMain(
|
||||||
@@ -134,6 +169,20 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
tryLoadLibrary(gdPackageInfo, Constants.FMOD_LIB_NAME)
|
tryLoadLibrary(gdPackageInfo, Constants.FMOD_LIB_NAME)
|
||||||
tryLoadLibrary(gdPackageInfo, Constants.COCOS_LIB_NAME)
|
tryLoadLibrary(gdPackageInfo, Constants.COCOS_LIB_NAME)
|
||||||
|
|
||||||
|
if (GamePackageUtils.getGameVersionCode(packageManager) >= 39L) {
|
||||||
|
/*
|
||||||
|
val customSymbols = PreferenceUtils.get(this).getBoolean(PreferenceUtils.Key.CUSTOM_SYMBOL_LIST)
|
||||||
|
if (customSymbols) {
|
||||||
|
val symbolFile = File(LaunchUtils.getBaseDirectory(this), "exception_symbols.txt")
|
||||||
|
LauncherFix.enableCustomSymbolList(symbolFile.path)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// this fix requires geode v3, which is 2.206+
|
||||||
|
// there is a short period in which 2.206 users will still have geode v2, but whatever. ig
|
||||||
|
LauncherFix.performExceptionsRenaming()
|
||||||
|
}
|
||||||
|
|
||||||
loadInternalMods()
|
loadInternalMods()
|
||||||
|
|
||||||
setContentView(createView())
|
setContentView(createView())
|
||||||
@@ -151,7 +200,12 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
|
|
||||||
private fun handleGeodeException(e: Throwable) {
|
private fun handleGeodeException(e: Throwable) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
throw e
|
|
||||||
|
// ignore load failures if the game is newer than what's supported
|
||||||
|
// so people in the future can use their save data
|
||||||
|
if (GamePackageUtils.getGameVersionCode(packageManager) <= Constants.SUPPORTED_VERSION_CODE) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRedirection(packageInfo: PackageInfo) {
|
private fun setupRedirection(packageInfo: PackageInfo) {
|
||||||
@@ -166,6 +220,9 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
val saveDir = LaunchUtils.getSaveDirectory(this)
|
val saveDir = LaunchUtils.getSaveDirectory(this)
|
||||||
saveDir.mkdir()
|
saveDir.mkdir()
|
||||||
|
|
||||||
|
// make sure it's loaded, just in case
|
||||||
|
System.loadLibrary("c++_shared")
|
||||||
|
|
||||||
LauncherFix.loadLibrary()
|
LauncherFix.loadLibrary()
|
||||||
LauncherFix.setOriginalDataPath(Constants.GJ_DATA_DIR)
|
LauncherFix.setOriginalDataPath(Constants.GJ_DATA_DIR)
|
||||||
LauncherFix.setDataPath(saveDir.path)
|
LauncherFix.setDataPath(saveDir.path)
|
||||||
@@ -175,22 +232,19 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupPostLibraryLoad(packageInfo: PackageInfo) {
|
private fun setupPostLibraryLoad(packageInfo: PackageInfo) {
|
||||||
FMOD.init(this)
|
|
||||||
|
|
||||||
// call native functions after native libraries init
|
// call native functions after native libraries init
|
||||||
JniToCpp.setupHSSAssets(
|
JniToCpp.setupHSSAssets(
|
||||||
packageInfo.applicationInfo.sourceDir,
|
packageInfo.applicationInfo!!.sourceDir,
|
||||||
Environment.getExternalStorageDirectory().absolutePath
|
Environment.getExternalStorageDirectory().absolutePath
|
||||||
)
|
)
|
||||||
Cocos2dxHelper.nativeSetApkPath(packageInfo.applicationInfo.sourceDir)
|
Cocos2dxHelper.nativeSetApkPath(packageInfo.applicationInfo!!.sourceDir)
|
||||||
|
|
||||||
BaseRobTopActivity.setCurrentActivity(this)
|
BaseRobTopActivity.setCurrentActivity(this)
|
||||||
registerReceiver()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("UnsafeDynamicallyLoadedCode")
|
@SuppressLint("UnsafeDynamicallyLoadedCode")
|
||||||
private fun tryLoadLibrary(packageInfo: PackageInfo, libraryName: String) {
|
private fun tryLoadLibrary(packageInfo: PackageInfo, libraryName: String) {
|
||||||
val nativeDir = getNativeLibraryDirectory(packageInfo.applicationInfo)
|
val nativeDir = getNativeLibraryDirectory(packageInfo.applicationInfo!!)
|
||||||
val libraryPath = if (nativeDir.endsWith('/')) "${nativeDir}lib$libraryName.so" else "$nativeDir/lib$libraryName.so"
|
val libraryPath = if (nativeDir.endsWith('/')) "${nativeDir}lib$libraryName.so" else "$nativeDir/lib$libraryName.so"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -337,15 +391,22 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
frameLayout.layoutParams = frameLayoutParams
|
frameLayout.layoutParams = frameLayoutParams
|
||||||
|
|
||||||
if (displayMode == DisplayMode.LIMITED) {
|
if (displayMode == DisplayMode.LIMITED) {
|
||||||
// despite not being perfectly 16:9, this is what Android calls "16:9"
|
frameLayout.aspectRatio = mAspectRatio
|
||||||
frameLayout.aspectRatio = 1.86f
|
}
|
||||||
|
|
||||||
|
if (mScreenZoomFit && mScreenZoom != 1.0f) {
|
||||||
|
frameLayout.fitZoom = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mScreenZoom != 1.0f) {
|
||||||
|
frameLayout.zoom = mScreenZoom
|
||||||
}
|
}
|
||||||
|
|
||||||
val editTextLayoutParams = ViewGroup.LayoutParams(
|
val editTextLayoutParams = ViewGroup.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
)
|
)
|
||||||
val editText = Cocos2dxEditText(this)
|
val editText = AppCompatEditText(this)
|
||||||
editText.layoutParams = editTextLayoutParams
|
editText.layoutParams = editTextLayoutParams
|
||||||
frameLayout.addView(editText)
|
frameLayout.addView(editText)
|
||||||
|
|
||||||
@@ -354,17 +415,35 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
this.mGLSurfaceView = glSurfaceView
|
this.mGLSurfaceView = glSurfaceView
|
||||||
frameLayout.addView(this.mGLSurfaceView)
|
frameLayout.addView(this.mGLSurfaceView)
|
||||||
|
|
||||||
glSurfaceView.setEGLContextClientVersion(2)
|
val showNotification = PreferenceUtils.get(this).getBoolean(PreferenceUtils.Key.ENABLE_REDESIGN)
|
||||||
glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8)
|
if (showNotification) {
|
||||||
|
val hasCards = determineDisplayedCards(this)
|
||||||
|
if (hasCards.isNotEmpty()) {
|
||||||
|
val notificationView = ComposeView(this)
|
||||||
|
frameLayout.addView(notificationView)
|
||||||
|
|
||||||
if (isAndroidEmulator()) {
|
notificationView.setContent {
|
||||||
glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0)
|
LaunchNotification()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glSurfaceView.initView()
|
glSurfaceView.setEGLContextClientVersion(2)
|
||||||
glSurfaceView.setCocos2dxRenderer(Cocos2dxRenderer())
|
glSurfaceView.setEGLConfigChooser(EGLConfigChooser())
|
||||||
|
|
||||||
editText.inputType = 145
|
glSurfaceView.initView()
|
||||||
|
|
||||||
|
val renderer = Cocos2dxRenderer(glSurfaceView)
|
||||||
|
glSurfaceView.setCocos2dxRenderer(renderer)
|
||||||
|
|
||||||
|
renderer.setFrameRate = mForceRefreshRate
|
||||||
|
|
||||||
|
val frameRate = mLimitedRefreshRate
|
||||||
|
if (frameRate != null) {
|
||||||
|
renderer.limitFrameRate(frameRate)
|
||||||
|
}
|
||||||
|
|
||||||
|
editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
|
||||||
glSurfaceView.cocos2dxEditText = editText
|
glSurfaceView.cocos2dxEditText = editText
|
||||||
|
|
||||||
return frameLayout
|
return frameLayout
|
||||||
@@ -373,12 +452,37 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
private fun setupUIState() {
|
private fun setupUIState() {
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
||||||
|
|
||||||
|
val preferenceUtils = PreferenceUtils.get(this)
|
||||||
|
|
||||||
displayMode = DisplayMode.fromInt(
|
displayMode = DisplayMode.fromInt(
|
||||||
PreferenceUtils.get(this).getInt(PreferenceUtils.Key.DISPLAY_MODE)
|
preferenceUtils.getInt(PreferenceUtils.Key.DISPLAY_MODE)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mAspectRatio = ratioForPreference(preferenceUtils.getString(PreferenceUtils.Key.CUSTOM_ASPECT_RATIO) ?: "16_9")
|
||||||
|
mScreenZoom = preferenceUtils.getInt(PreferenceUtils.Key.SCREEN_ZOOM) / 100.0f
|
||||||
|
mScreenZoomFit = preferenceUtils.getBoolean(PreferenceUtils.Key.SCREEN_ZOOM_FIT)
|
||||||
|
|
||||||
|
val limitedRefreshRate = preferenceUtils.getInt(PreferenceUtils.Key.LIMIT_FRAME_RATE).takeIf { it != 0 }
|
||||||
|
mLimitedRefreshRate = limitedRefreshRate
|
||||||
|
|
||||||
|
mForceRefreshRate = preferenceUtils.getBoolean(PreferenceUtils.Key.FORCE_HRR)
|
||||||
|
if (mForceRefreshRate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
val chosenDisplay = display.supportedModes?.maxByOrNull { it.refreshRate }
|
||||||
|
if (chosenDisplay != null) {
|
||||||
|
var chosenRefreshRate = chosenDisplay.refreshRate
|
||||||
|
println("setupUIState: Forcing a refresh rate of $chosenRefreshRate (display ${chosenDisplay.modeId})")
|
||||||
|
|
||||||
|
window.attributes.preferredRefreshRate = chosenRefreshRate
|
||||||
|
} else {
|
||||||
|
println("setupUIState could not find a display to select refresh rate of...")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (displayMode == DisplayMode.FULLSCREEN && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (displayMode == DisplayMode.FULLSCREEN && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||||
|
GeodeUtils.handleSafeArea = true
|
||||||
|
} else {
|
||||||
|
GeodeUtils.handleSafeArea = false
|
||||||
}
|
}
|
||||||
|
|
||||||
hideSystemUi()
|
hideSystemUi()
|
||||||
@@ -406,19 +510,18 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
unregisterReceivers()
|
|
||||||
FMOD.close()
|
FMOD.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resumeGame() {
|
private fun resumeGame() {
|
||||||
mIsRunning = true
|
mIsRunning = true
|
||||||
// Cocos2dxHelper.onResume()
|
Cocos2dxHelper.onResume()
|
||||||
mGLSurfaceView?.onResume()
|
mGLSurfaceView?.onResume()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun pauseGame() {
|
private fun pauseGame() {
|
||||||
mIsRunning = false
|
mIsRunning = false
|
||||||
// Cocos2dxHelper.onPause()
|
Cocos2dxHelper.onPause()
|
||||||
mGLSurfaceView?.onPause()
|
mGLSurfaceView?.onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,25 +552,6 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun registerReceiver() {
|
|
||||||
unregisterReceivers()
|
|
||||||
try {
|
|
||||||
val filter = IntentFilter(Intent.ACTION_SCREEN_ON)
|
|
||||||
filter.addAction(Intent.ACTION_SCREEN_OFF)
|
|
||||||
filter.addAction(Intent.ACTION_USER_PRESENT)
|
|
||||||
mReceiver = BaseRobTopActivity.ReceiverScreen()
|
|
||||||
registerReceiver(mReceiver, filter)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun unregisterReceivers() {
|
|
||||||
if (mReceiver != null) {
|
|
||||||
unregisterReceiver(mReceiver)
|
|
||||||
mReceiver = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun runOnGLThread(runnable: Runnable) {
|
override fun runOnGLThread(runnable: Runnable) {
|
||||||
mGLSurfaceView?.queueEvent(runnable)
|
mGLSurfaceView?.queueEvent(runnable)
|
||||||
}
|
}
|
||||||
@@ -494,18 +578,6 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isAndroidEmulator(): Boolean {
|
|
||||||
Log.d(sTag, "model=" + Build.MODEL)
|
|
||||||
val product = Build.PRODUCT
|
|
||||||
Log.d(sTag, "product=$product")
|
|
||||||
var isEmulator = false
|
|
||||||
if (product != null) {
|
|
||||||
isEmulator = product == "sdk" || product.contains("_sdk") || product.contains("sdk_")
|
|
||||||
}
|
|
||||||
Log.d(sTag, "isEmulator=$isEmulator")
|
|
||||||
return isEmulator
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCapabilityAdded(capability: String): Boolean {
|
override fun onCapabilityAdded(capability: String): Boolean {
|
||||||
return when (capability) {
|
return when (capability) {
|
||||||
GeodeUtils.CAPABILITY_EXTENDED_INPUT -> {
|
GeodeUtils.CAPABILITY_EXTENDED_INPUT -> {
|
||||||
@@ -516,6 +588,10 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
mGLSurfaceView?.sendTimestampEvents = true
|
mGLSurfaceView?.sendTimestampEvents = true
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
GeodeUtils.CAPABILITY_INTERNAL_CALLBACKS -> {
|
||||||
|
mGLSurfaceView?.sendInternalTimestampEvents = true
|
||||||
|
true
|
||||||
|
}
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -529,7 +605,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
|
|
||||||
val modListing = try {
|
val modListing = try {
|
||||||
assets.list(internalModBase)
|
assets.list(internalModBase)
|
||||||
} catch (ioe: IOException) {
|
} catch (_: IOException) {
|
||||||
emptyArray<String>()
|
emptyArray<String>()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,4 +627,78 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EGLConfigChooser : GLSurfaceView.EGLConfigChooser {
|
||||||
|
// this comes from EGL14, but is unavailable on EGL10
|
||||||
|
// also EGL14 is incompatible with EGL10. so whatever
|
||||||
|
private var EGL_OPENGL_ES2_BIT: Int = 0x04
|
||||||
|
|
||||||
|
private data class ConfigValues(
|
||||||
|
val redSize: Int,
|
||||||
|
val greenSize: Int,
|
||||||
|
val blueSize: Int,
|
||||||
|
val alphaSize: Int,
|
||||||
|
val depthSize: Int,
|
||||||
|
val stencilSize: Int,
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun getAttribValue(egl: EGL10, display: EGLDisplay, config: EGLConfig, attrib: Int): Int {
|
||||||
|
val value = IntArray(1)
|
||||||
|
egl.eglGetConfigAttrib(display, config, attrib, value)
|
||||||
|
|
||||||
|
return value[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun testConfig(egl: EGL10, display: EGLDisplay, attrib: ConfigValues): EGLConfig? {
|
||||||
|
val attribList = intArrayOf(
|
||||||
|
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||||
|
EGL10.EGL_RED_SIZE, attrib.redSize,
|
||||||
|
EGL10.EGL_GREEN_SIZE, attrib.greenSize,
|
||||||
|
EGL10.EGL_BLUE_SIZE, attrib.blueSize,
|
||||||
|
EGL10.EGL_ALPHA_SIZE, attrib.alphaSize,
|
||||||
|
EGL10.EGL_DEPTH_SIZE, attrib.depthSize,
|
||||||
|
EGL10.EGL_STENCIL_SIZE, attrib.stencilSize,
|
||||||
|
EGL10.EGL_NONE
|
||||||
|
)
|
||||||
|
|
||||||
|
val configs = arrayOfNulls<EGLConfig>(1)
|
||||||
|
val numConfigs = IntArray(1)
|
||||||
|
|
||||||
|
val res = egl.eglChooseConfig(display, attribList, configs, configs.size, numConfigs)
|
||||||
|
if (res && numConfigs[0] > 0 && configs[0] != null) {
|
||||||
|
return configs[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun printConfig(egl: EGL10, display: EGLDisplay, config: EGLConfig) {
|
||||||
|
val id = getAttribValue(egl, display, config, EGL10.EGL_CONFIG_ID)
|
||||||
|
val red = getAttribValue(egl, display, config, EGL10.EGL_RED_SIZE)
|
||||||
|
val green = getAttribValue(egl, display, config, EGL10.EGL_GREEN_SIZE)
|
||||||
|
val blue = getAttribValue(egl, display, config, EGL10.EGL_BLUE_SIZE)
|
||||||
|
val alpha = getAttribValue(egl, display, config, EGL10.EGL_ALPHA_SIZE)
|
||||||
|
val depth = getAttribValue(egl, display, config, EGL10.EGL_DEPTH_SIZE)
|
||||||
|
val stencil = getAttribValue(egl, display, config, EGL10.EGL_STENCIL_SIZE)
|
||||||
|
println("EGLConfig $id: (red = $red, green = $green, blue = $blue, alpha = $alpha, depth = $depth, stencil = $stencil)")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun chooseConfig(egl: EGL10, display: EGLDisplay): EGLConfig {
|
||||||
|
val configs = listOf(
|
||||||
|
ConfigValues(8, 8, 8, 8, 16, 8),
|
||||||
|
ConfigValues(8, 8, 8, 0, 16, 8),
|
||||||
|
ConfigValues(5, 6, 5, 0, 16, 8),
|
||||||
|
ConfigValues(0, 0, 0, 0, 0, 0),
|
||||||
|
)
|
||||||
|
|
||||||
|
return configs.firstNotNullOf {
|
||||||
|
val config = testConfig(egl, display, it)
|
||||||
|
if (config != null) {
|
||||||
|
printConfig(egl, display, config)
|
||||||
|
}
|
||||||
|
|
||||||
|
config
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -12,4 +12,8 @@ object LauncherFix {
|
|||||||
external fun setDataPath(dataPath: String)
|
external fun setDataPath(dataPath: String)
|
||||||
|
|
||||||
external fun setOriginalDataPath(dataPath: String)
|
external fun setOriginalDataPath(dataPath: String)
|
||||||
|
|
||||||
|
external fun performExceptionsRenaming()
|
||||||
|
|
||||||
|
external fun enableCustomSymbolList(symbolsPath: String)
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,16 @@
|
|||||||
package com.geode.launcher
|
package com.geode.launcher
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.DocumentsContract
|
|
||||||
import android.text.format.Formatter.formatShortFileSize
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
||||||
import androidx.compose.foundation.interaction.PressInteraction
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.shape.AbsoluteRoundedCornerShape
|
|
||||||
import androidx.compose.foundation.text.ClickableText
|
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.PlayArrow
|
|
||||||
import androidx.compose.material.icons.filled.Refresh
|
|
||||||
import androidx.compose.material.icons.filled.Settings
|
import androidx.compose.material.icons.filled.Settings
|
||||||
import androidx.compose.material.icons.filled.Share
|
|
||||||
import androidx.compose.material.icons.filled.Warning
|
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
@@ -38,51 +22,27 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
|
||||||
import androidx.compose.ui.platform.LocalUriHandler
|
|
||||||
import androidx.compose.ui.platform.LocalViewConfiguration
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.pluralStringResource
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import androidx.compose.ui.text.TextStyle
|
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextDecoration
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import com.geode.launcher.main.*
|
||||||
import com.geode.launcher.updater.ReleaseViewModel
|
import com.geode.launcher.updater.ReleaseViewModel
|
||||||
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
||||||
import com.geode.launcher.ui.theme.LocalTheme
|
import com.geode.launcher.ui.theme.LocalTheme
|
||||||
import com.geode.launcher.ui.theme.Theme
|
import com.geode.launcher.ui.theme.Theme
|
||||||
import com.geode.launcher.ui.theme.Typography
|
|
||||||
import com.geode.launcher.utils.Constants
|
import com.geode.launcher.utils.Constants
|
||||||
import com.geode.launcher.utils.LaunchUtils
|
import com.geode.launcher.utils.LaunchUtils
|
||||||
import com.geode.launcher.utils.PreferenceUtils
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
import com.geode.launcher.updater.ReleaseManager
|
|
||||||
import com.geode.launcher.utils.GamePackageUtils
|
import com.geode.launcher.utils.GamePackageUtils
|
||||||
import com.geode.launcher.utils.GeodeUtils
|
|
||||||
import com.geode.launcher.utils.useCountdownTimer
|
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
|
||||||
import java.net.ConnectException
|
|
||||||
import java.net.UnknownHostException
|
|
||||||
|
|
||||||
data class LoadFailureInfo(
|
|
||||||
val title: LaunchUtils.LauncherError,
|
|
||||||
val description: String? = null,
|
|
||||||
val extendedMessage: String? = null
|
|
||||||
)
|
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
clearDownloadedApks(this)
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
@@ -102,6 +62,15 @@ class MainActivity : ComponentActivity() {
|
|||||||
LoadFailureInfo(LaunchUtils.LauncherError.CRASHED)
|
LoadFailureInfo(LaunchUtils.LauncherError.CRASHED)
|
||||||
} else { null }
|
} else { null }
|
||||||
|
|
||||||
|
val redirectToAlt = PreferenceUtils.get(this).getBoolean(PreferenceUtils.Key.ENABLE_REDESIGN)
|
||||||
|
if (redirectToAlt) {
|
||||||
|
val launchIntent = Intent(this, AltMainActivity::class.java)
|
||||||
|
launchIntent.putExtras(intent)
|
||||||
|
startActivity(launchIntent)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
|
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
|
||||||
val theme = Theme.fromInt(themeOption)
|
val theme = Theme.fromInt(themeOption)
|
||||||
@@ -129,768 +98,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun LauncherUpdateIndicator(modifier: Modifier = Modifier, openTo: String, onDismiss: () -> Unit) {
|
|
||||||
val uriHandler = LocalUriHandler.current
|
|
||||||
|
|
||||||
ElevatedCard(modifier) {
|
|
||||||
Column(
|
|
||||||
// buttons add enough padding already, lower to compensate
|
|
||||||
modifier = Modifier.padding(
|
|
||||||
top = 20.dp,
|
|
||||||
start = 12.dp,
|
|
||||||
end = 12.dp,
|
|
||||||
bottom = 8.dp
|
|
||||||
),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.launcher_update_available),
|
|
||||||
modifier = Modifier.padding(horizontal = 10.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
Row(modifier = Modifier.align(Alignment.End)) {
|
|
||||||
TextButton(onClick = onDismiss) {
|
|
||||||
Text(stringResource(R.string.launcher_update_dismiss))
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(Modifier.size(4.dp))
|
|
||||||
|
|
||||||
TextButton(onClick = { uriHandler.openUri(openTo) }) {
|
|
||||||
Text(stringResource(R.string.launcher_download))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun UpdateProgressIndicator(
|
|
||||||
message: String,
|
|
||||||
releaseViewModel: ReleaseViewModel,
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
progress: (() -> Float)? = null
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
horizontalAlignment = Alignment.Start,
|
|
||||||
modifier = modifier
|
|
||||||
) {
|
|
||||||
Text(message)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.padding(4.dp))
|
|
||||||
|
|
||||||
if (progress == null) {
|
|
||||||
LinearProgressIndicator()
|
|
||||||
} else {
|
|
||||||
LinearProgressIndicator(progress = progress)
|
|
||||||
}
|
|
||||||
|
|
||||||
TextButton(
|
|
||||||
onClick = {
|
|
||||||
releaseViewModel.cancelUpdate()
|
|
||||||
},
|
|
||||||
modifier = Modifier.offset((-12).dp)
|
|
||||||
) {
|
|
||||||
Text(stringResource(R.string.release_fetch_button_cancel))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun UpdateMessageIndicator(
|
|
||||||
message: String,
|
|
||||||
releaseViewModel: ReleaseViewModel,
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
allowRetry: Boolean = false
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
modifier = modifier
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
message,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.padding(4.dp))
|
|
||||||
|
|
||||||
if (allowRetry) {
|
|
||||||
OutlinedButton(
|
|
||||||
onClick = {
|
|
||||||
releaseViewModel.runReleaseCheck(true)
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.Refresh,
|
|
||||||
contentDescription = stringResource(R.string.launcher_retry_icon_alt)
|
|
||||||
)
|
|
||||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
|
||||||
Text(stringResource(R.string.release_fetch_button_retry))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun UpdateWarning(inSafeMode: Boolean = false, onDismiss: () -> Unit) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
val packageManager = context.packageManager
|
|
||||||
|
|
||||||
val gdVersionCode = remember { GamePackageUtils.getGameVersionCode(packageManager) }
|
|
||||||
val gdVersionString = remember { GamePackageUtils.getGameVersionString(packageManager) }
|
|
||||||
|
|
||||||
var lastDismissedVersion by PreferenceUtils.useLongPreference(
|
|
||||||
preferenceKey = PreferenceUtils.Key.DISMISSED_GJ_UPDATE
|
|
||||||
)
|
|
||||||
|
|
||||||
val canDismissRelease = gdVersionCode >= Constants.SUPPORTED_VERSION_CODE
|
|
||||||
val shouldDismiss = canDismissRelease && gdVersionCode == lastDismissedVersion
|
|
||||||
|
|
||||||
if (gdVersionCode != Constants.SUPPORTED_VERSION_CODE && !shouldDismiss) {
|
|
||||||
AlertDialog(
|
|
||||||
icon = {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.Warning,
|
|
||||||
contentDescription = stringResource(R.string.launcher_warning_icon_alt)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
title = {
|
|
||||||
Text(stringResource(R.string.launcher_unsupported_version_title))
|
|
||||||
},
|
|
||||||
text = {
|
|
||||||
val message = if (gdVersionCode >= Constants.SUPPORTED_VERSION_CODE) {
|
|
||||||
R.string.launcher_unsupported_version_description
|
|
||||||
} else {
|
|
||||||
R.string.launcher_outdated_version_description
|
|
||||||
}
|
|
||||||
|
|
||||||
Text(stringResource(
|
|
||||||
message, gdVersionString, Constants.SUPPORTED_VERSION_STRING
|
|
||||||
))
|
|
||||||
},
|
|
||||||
confirmButton = {
|
|
||||||
TextButton(onClick = {
|
|
||||||
onDismiss()
|
|
||||||
lastDismissedVersion = gdVersionCode
|
|
||||||
|
|
||||||
onLaunch(context, inSafeMode)
|
|
||||||
}) {
|
|
||||||
Text(stringResource(R.string.message_box_accept))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dismissButton = {
|
|
||||||
TextButton(onClick = { onDismiss() }) {
|
|
||||||
Text(stringResource(R.string.message_box_cancel))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onDismissRequest = { onDismiss() }
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
LaunchedEffect(gdVersionCode) {
|
|
||||||
onLaunch(context, inSafeMode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SafeModeDialog(onDismiss: () -> Unit, onLaunch: () -> Unit) {
|
|
||||||
AlertDialog(
|
|
||||||
icon = {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.Warning,
|
|
||||||
contentDescription = stringResource(R.string.launcher_warning_icon_alt)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
title = { Text(stringResource(R.string.safe_mode_enable_title)) },
|
|
||||||
text = { Text(stringResource(R.string.safe_mode_enable_description)) },
|
|
||||||
dismissButton = {
|
|
||||||
TextButton(onClick = onDismiss) {
|
|
||||||
Text(stringResource(R.string.message_box_cancel))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
confirmButton = {
|
|
||||||
TextButton(onClick = onLaunch) {
|
|
||||||
Text(stringResource(R.string.message_box_continue))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onDismissRequest = onDismiss
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun UpdateCard(releaseViewModel: ReleaseViewModel, modifier: Modifier = Modifier) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
val releaseState by releaseViewModel.uiState.collectAsState()
|
|
||||||
|
|
||||||
when (val state = releaseState) {
|
|
||||||
is ReleaseViewModel.ReleaseUIState.Failure -> {
|
|
||||||
val message = when (state.exception) {
|
|
||||||
is UnknownHostException, is ConnectException ->
|
|
||||||
stringResource(R.string.release_fetch_no_internet)
|
|
||||||
is ReleaseManager.UpdateException -> {
|
|
||||||
when (state.exception.reason) {
|
|
||||||
ReleaseManager.UpdateException.Reason.EXTERNAL_FILE_IN_USE -> stringResource(
|
|
||||||
R.string.release_fetch_manual_check_required
|
|
||||||
)
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateMessageIndicator(
|
|
||||||
stringResource(
|
|
||||||
R.string.release_fetch_failed,
|
|
||||||
message ?: stringResource(R.string.release_fetch_try_later)
|
|
||||||
),
|
|
||||||
modifier = modifier,
|
|
||||||
allowRetry = true,
|
|
||||||
releaseViewModel = releaseViewModel
|
|
||||||
)
|
|
||||||
}
|
|
||||||
is ReleaseViewModel.ReleaseUIState.InDownload -> {
|
|
||||||
val downloaded = remember(state.downloaded) {
|
|
||||||
formatShortFileSize(context, state.downloaded)
|
|
||||||
}
|
|
||||||
|
|
||||||
val outOf = remember(state.outOf) {
|
|
||||||
formatShortFileSize(context, state.outOf)
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateProgressIndicator(
|
|
||||||
stringResource(
|
|
||||||
R.string.release_fetch_downloading,
|
|
||||||
downloaded,
|
|
||||||
outOf
|
|
||||||
),
|
|
||||||
modifier = modifier,
|
|
||||||
releaseViewModel = releaseViewModel,
|
|
||||||
progress = {
|
|
||||||
val progress = state.downloaded / state.outOf.toDouble()
|
|
||||||
progress.toFloat()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
is ReleaseViewModel.ReleaseUIState.InUpdateCheck -> {
|
|
||||||
UpdateProgressIndicator(
|
|
||||||
stringResource(R.string.release_fetch_in_progress),
|
|
||||||
modifier = modifier,
|
|
||||||
releaseViewModel = releaseViewModel
|
|
||||||
)
|
|
||||||
}
|
|
||||||
is ReleaseViewModel.ReleaseUIState.Finished -> {
|
|
||||||
if (state.hasUpdated) {
|
|
||||||
UpdateMessageIndicator(
|
|
||||||
stringResource(R.string.release_fetch_success),
|
|
||||||
modifier = modifier,
|
|
||||||
releaseViewModel = releaseViewModel
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is ReleaseViewModel.ReleaseUIState.Cancelled -> {
|
|
||||||
if (state.isCancelling) {
|
|
||||||
UpdateProgressIndicator(
|
|
||||||
stringResource(R.string.release_fetch_cancelling),
|
|
||||||
modifier = modifier,
|
|
||||||
releaseViewModel = releaseViewModel
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
UpdateMessageIndicator(
|
|
||||||
stringResource(R.string.release_fetch_cancelled),
|
|
||||||
modifier = modifier,
|
|
||||||
allowRetry = true,
|
|
||||||
releaseViewModel = releaseViewModel
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val nextUpdate by releaseViewModel.nextLauncherUpdate.collectAsState()
|
|
||||||
val nextUpdateValue = nextUpdate
|
|
||||||
|
|
||||||
if (!releaseViewModel.isInUpdate && nextUpdateValue != null) {
|
|
||||||
val updateUrl = nextUpdateValue.getLauncherDownload()?.browserDownloadUrl
|
|
||||||
?: nextUpdateValue.htmlUrl
|
|
||||||
|
|
||||||
LauncherUpdateIndicator(
|
|
||||||
modifier = modifier,
|
|
||||||
openTo = updateUrl,
|
|
||||||
onDismiss = {
|
|
||||||
releaseViewModel.dismissLauncherUpdate()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ErrorInfoBody(failureReason: LaunchUtils.LauncherError, modifier: Modifier = Modifier) {
|
|
||||||
val headline = when (failureReason) {
|
|
||||||
LaunchUtils.LauncherError.LINKER_FAILED -> stringResource(R.string.load_failed_link_error_description)
|
|
||||||
LaunchUtils.LauncherError.CRASHED -> stringResource(R.string.load_failed_crashed_description)
|
|
||||||
else -> stringResource(R.string.load_failed_generic_error_description)
|
|
||||||
}
|
|
||||||
|
|
||||||
val recommendations = when (failureReason) {
|
|
||||||
LaunchUtils.LauncherError.LINKER_FAILED -> listOf(
|
|
||||||
stringResource(R.string.load_failed_recommendation_reinstall),
|
|
||||||
stringResource(R.string.load_failed_recommendation_update),
|
|
||||||
)
|
|
||||||
LaunchUtils.LauncherError.CRASHED -> listOf(
|
|
||||||
stringResource(R.string.load_failed_recommendation_safe_mode),
|
|
||||||
stringResource(R.string.load_failed_recommendation_report)
|
|
||||||
)
|
|
||||||
else -> listOf(
|
|
||||||
stringResource(R.string.load_failed_recommendation_reinstall),
|
|
||||||
stringResource(R.string.load_failed_recommendation_update),
|
|
||||||
stringResource(R.string.load_failed_recommendation_report)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(modifier = modifier) {
|
|
||||||
Text(headline)
|
|
||||||
|
|
||||||
recommendations.forEach { r ->
|
|
||||||
Text("\u2022\u00A0\u00A0$r")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ErrorInfoTitle(failureReason: LaunchUtils.LauncherError) {
|
|
||||||
val message = when (failureReason) {
|
|
||||||
LaunchUtils.LauncherError.LINKER_NEEDS_64BIT,
|
|
||||||
LaunchUtils.LauncherError.LINKER_NEEDS_32BIT,
|
|
||||||
LaunchUtils.LauncherError.LINKER_FAILED -> stringResource(R.string.load_failed_link_error)
|
|
||||||
LaunchUtils.LauncherError.GENERIC -> stringResource(R.string.load_failed_generic_error)
|
|
||||||
LaunchUtils.LauncherError.CRASHED -> stringResource(R.string.load_failed_crashed)
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
painterResource(R.drawable.icon_error),
|
|
||||||
contentDescription = stringResource(R.string.launcher_error_icon_alt),
|
|
||||||
modifier = Modifier.size(28.dp)
|
|
||||||
)
|
|
||||||
Text(message, style = Typography.headlineMedium)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onShareCrash(context: Context) {
|
|
||||||
val lastCrash = LaunchUtils.getLastCrash(context)
|
|
||||||
if (lastCrash == null) {
|
|
||||||
Toast.makeText(context, R.string.launcher_error_export_missing, Toast.LENGTH_SHORT).show()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val baseDirectory = LaunchUtils.getBaseDirectory(context)
|
|
||||||
|
|
||||||
val providerLocation = lastCrash.toRelativeString(baseDirectory)
|
|
||||||
val documentsPath = "${UserDirectoryProvider.ROOT}${providerLocation}"
|
|
||||||
|
|
||||||
val uri = DocumentsContract.buildDocumentUri("${context.packageName}.user", documentsPath)
|
|
||||||
|
|
||||||
val shareIntent = Intent(Intent.ACTION_SEND).apply {
|
|
||||||
putExtra(Intent.EXTRA_STREAM, uri)
|
|
||||||
type = "application/octet-stream"
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
context.startActivity(shareIntent)
|
|
||||||
} catch (_: ActivityNotFoundException) {
|
|
||||||
Toast.makeText(context, R.string.no_activity_found, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onShowLogs(context: Context) {
|
|
||||||
val launchIntent = Intent(context, ApplicationLogsActivity::class.java)
|
|
||||||
context.startActivity(launchIntent)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ErrorInfoDescription(description: String, modifier: Modifier = Modifier) {
|
|
||||||
Column(modifier = modifier) {
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.launcher_error_details),
|
|
||||||
style = Typography.headlineSmall
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(Modifier.size(8.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
description,
|
|
||||||
fontFamily = FontFamily.Monospace,
|
|
||||||
style = Typography.bodyMedium
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(Modifier.size(4.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.launcher_error_device_info, Build.MODEL, Build.VERSION.RELEASE),
|
|
||||||
style = Typography.labelMedium
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
|
||||||
fun ErrorInfoActions(extraDetails: String?, modifier: Modifier = Modifier) {
|
|
||||||
val clipboardManager = LocalClipboardManager.current
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
FlowRow(
|
|
||||||
modifier = modifier,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(
|
|
||||||
12.dp, alignment = Alignment.CenterHorizontally
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
if (extraDetails != null) {
|
|
||||||
Button(onClick = { onShowLogs(context) }) {
|
|
||||||
Icon(
|
|
||||||
painterResource(R.drawable.icon_description),
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
|
||||||
Text(stringResource(R.string.launcher_error_view_logs))
|
|
||||||
}
|
|
||||||
|
|
||||||
FilledTonalButton(onClick = {
|
|
||||||
clipboardManager.setText(AnnotatedString(extraDetails))
|
|
||||||
}) {
|
|
||||||
Icon(
|
|
||||||
painterResource(R.drawable.icon_content_copy),
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
|
||||||
Text(stringResource(R.string.launcher_error_copy))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Button(onClick = { onShareCrash(context) }) {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.Share,
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
|
||||||
Text(stringResource(R.string.launcher_error_export_crash))
|
|
||||||
}
|
|
||||||
|
|
||||||
FilledTonalButton(onClick = { onShowLogs(context) }) {
|
|
||||||
Icon(
|
|
||||||
painterResource(R.drawable.icon_description),
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
|
||||||
Text(stringResource(R.string.launcher_error_view_logs))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onDownloadGame(context: Context) {
|
|
||||||
val appUrl = "https://play.google.com/store/apps/details?id=${Constants.PACKAGE_NAME}"
|
|
||||||
try {
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
|
||||||
data = Uri.parse(appUrl)
|
|
||||||
setPackage("com.android.vending")
|
|
||||||
}
|
|
||||||
context.startActivity(intent)
|
|
||||||
} catch (_: ActivityNotFoundException) {
|
|
||||||
Toast.makeText(context, R.string.no_activity_found, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun GooglePlayBadge(modifier: Modifier = Modifier) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.drawable.google_play_badge),
|
|
||||||
contentDescription = stringResource(R.string.launcher_download_game),
|
|
||||||
modifier = modifier
|
|
||||||
.width(196.dp)
|
|
||||||
.clip(AbsoluteRoundedCornerShape(4.dp))
|
|
||||||
.clickable { onDownloadGame(context) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun DownloadRecommendation(needsUniversal: Boolean, modifier: Modifier = Modifier) {
|
|
||||||
val uriHandler = LocalUriHandler.current
|
|
||||||
val context = LocalContext.current
|
|
||||||
val version = BuildConfig.VERSION_NAME
|
|
||||||
|
|
||||||
val showDownload = remember {
|
|
||||||
!GamePackageUtils.isGameInstalled(context.packageManager) ||
|
|
||||||
!GamePackageUtils.identifyGameLegitimacy(context.packageManager)
|
|
||||||
}
|
|
||||||
|
|
||||||
val downloadBase = "https://github.com/geode-sdk/android-launcher/releases/download/$version"
|
|
||||||
val legacyDownloadUrl = "$downloadBase/geode-launcher-v$version-android32.apk"
|
|
||||||
val universalDownloadUrl = "$downloadBase/geode-launcher-v$version.apk"
|
|
||||||
|
|
||||||
val downloadUrl = if (needsUniversal)
|
|
||||||
universalDownloadUrl else legacyDownloadUrl
|
|
||||||
|
|
||||||
val downloadText = if (needsUniversal)
|
|
||||||
stringResource(R.string.launcher_download_universal)
|
|
||||||
else
|
|
||||||
stringResource(R.string.launcher_download_32bit)
|
|
||||||
|
|
||||||
val promptTitle = stringResource(R.string.load_failed_abi_error)
|
|
||||||
val reinstallText = stringResource(R.string.load_failed_recommendation_reinstall)
|
|
||||||
val recommendationText = if (needsUniversal)
|
|
||||||
stringResource(R.string.load_failed_recommendation_switch_64bit_abi)
|
|
||||||
else
|
|
||||||
stringResource(R.string.load_failed_recommendation_switch_32bit_abi)
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = modifier,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(
|
|
||||||
12.dp, alignment = Alignment.CenterVertically
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Text(promptTitle)
|
|
||||||
Text("\u2022\u00A0\u00A0$reinstallText")
|
|
||||||
|
|
||||||
if (showDownload) {
|
|
||||||
GooglePlayBadge()
|
|
||||||
}
|
|
||||||
|
|
||||||
Text("\u2022\u00A0\u00A0$recommendationText")
|
|
||||||
|
|
||||||
ClickableText(
|
|
||||||
text = AnnotatedString(downloadText),
|
|
||||||
onClick = {
|
|
||||||
uriHandler.openUri(downloadUrl)
|
|
||||||
},
|
|
||||||
|
|
||||||
style = TextStyle.Default.copy(
|
|
||||||
color = MaterialTheme.colorScheme.primary,
|
|
||||||
textDecoration = TextDecoration.Underline
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun ErrorInfoSheet(failureInfo: LoadFailureInfo, onDismiss: () -> Unit) {
|
|
||||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
|
||||||
|
|
||||||
ModalBottomSheet(onDismissRequest = { onDismiss() }, sheetState = sheetState) {
|
|
||||||
// second container created for scroll (before padding is added)
|
|
||||||
Box(Modifier.verticalScroll(rememberScrollState())) {
|
|
||||||
Column(modifier = Modifier
|
|
||||||
.padding(horizontal = 24.dp)
|
|
||||||
) {
|
|
||||||
ErrorInfoTitle(failureInfo.title)
|
|
||||||
|
|
||||||
Spacer(Modifier.size(16.dp))
|
|
||||||
|
|
||||||
if (failureInfo.title.isAbiFailure()) {
|
|
||||||
DownloadRecommendation(
|
|
||||||
needsUniversal = failureInfo.title == LaunchUtils.LauncherError.LINKER_NEEDS_64BIT,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(top = 8.dp, bottom = 16.dp)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
ErrorInfoBody(failureInfo.title)
|
|
||||||
|
|
||||||
if (failureInfo.description != null) {
|
|
||||||
ErrorInfoDescription(
|
|
||||||
failureInfo.description,
|
|
||||||
modifier = Modifier.padding(vertical = 8.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorInfoActions(
|
|
||||||
extraDetails = failureInfo.extendedMessage ?: failureInfo.description,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(top = 8.dp, bottom = 16.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onLaunch(context: Context, safeMode: Boolean = false) {
|
|
||||||
if (safeMode) {
|
|
||||||
GeodeUtils.setAdditionalLaunchArguments(GeodeUtils.ARGUMENT_SAFE_MODE)
|
|
||||||
} else {
|
|
||||||
GeodeUtils.clearLaunchArguments()
|
|
||||||
}
|
|
||||||
|
|
||||||
val launchIntent = Intent(context, GeometryDashActivity::class.java)
|
|
||||||
launchIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
|
|
||||||
|
|
||||||
context.startActivity(launchIntent)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onSettings(context: Context) {
|
|
||||||
val launchIntent = Intent(context, SettingsActivity::class.java)
|
|
||||||
context.startActivity(launchIntent)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun showFailureSnackbar(
|
|
||||||
context: Context,
|
|
||||||
loadFailureInfo: LoadFailureInfo,
|
|
||||||
snackbarHostState: SnackbarHostState,
|
|
||||||
onActionPerformed: () -> Unit
|
|
||||||
) {
|
|
||||||
val message = if (loadFailureInfo.title == LaunchUtils.LauncherError.CRASHED) {
|
|
||||||
context.getString(R.string.launcher_crashed)
|
|
||||||
} else {
|
|
||||||
context.getString(R.string.launcher_failed_to_load)
|
|
||||||
}
|
|
||||||
|
|
||||||
val res = snackbarHostState.showSnackbar(
|
|
||||||
message = message,
|
|
||||||
actionLabel = context.getString(R.string.launcher_error_more),
|
|
||||||
duration = SnackbarDuration.Indefinite,
|
|
||||||
)
|
|
||||||
|
|
||||||
when (res) {
|
|
||||||
SnackbarResult.ActionPerformed -> {
|
|
||||||
onActionPerformed()
|
|
||||||
}
|
|
||||||
SnackbarResult.Dismissed -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun PlayButton(
|
|
||||||
stopAutomaticLaunch: Boolean,
|
|
||||||
blockLaunch: Boolean,
|
|
||||||
onPlayGame: (Boolean) -> Unit
|
|
||||||
) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
var showSafeModeDialog by remember { mutableStateOf(false) }
|
|
||||||
var launchInSafeMode by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
val shouldAutomaticallyLaunch by PreferenceUtils.useBooleanPreference(
|
|
||||||
preferenceKey = PreferenceUtils.Key.LOAD_AUTOMATICALLY
|
|
||||||
)
|
|
||||||
|
|
||||||
if (shouldAutomaticallyLaunch && !stopAutomaticLaunch && !showSafeModeDialog) {
|
|
||||||
val countdownTimer = useCountdownTimer(
|
|
||||||
time = 3000,
|
|
||||||
onCountdownFinish = { onPlayGame(launchInSafeMode) }
|
|
||||||
)
|
|
||||||
|
|
||||||
if (countdownTimer != 0L) {
|
|
||||||
Text(
|
|
||||||
pluralStringResource(
|
|
||||||
R.plurals.automatically_load_countdown,
|
|
||||||
countdownTimer.toInt(),
|
|
||||||
countdownTimer
|
|
||||||
),
|
|
||||||
style = Typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
|
||||||
)
|
|
||||||
Spacer(Modifier.size(12.dp))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// compose apis don't provide a good way of adding long press to a button
|
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
|
||||||
val viewConfiguration = LocalViewConfiguration.current
|
|
||||||
val haptics = LocalHapticFeedback.current
|
|
||||||
|
|
||||||
LaunchedEffect(interactionSource) {
|
|
||||||
interactionSource.interactions.collectLatest { interaction ->
|
|
||||||
when (interaction) {
|
|
||||||
is PressInteraction.Press -> {
|
|
||||||
launchInSafeMode = false
|
|
||||||
|
|
||||||
delay(viewConfiguration.longPressTimeoutMillis)
|
|
||||||
|
|
||||||
// perform a second delay to make the action more obvious
|
|
||||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
|
||||||
delay(viewConfiguration.longPressTimeoutMillis)
|
|
||||||
|
|
||||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
|
||||||
|
|
||||||
showSafeModeDialog = true
|
|
||||||
}
|
|
||||||
|
|
||||||
is PressInteraction.Release -> {
|
|
||||||
if (!showSafeModeDialog) {
|
|
||||||
onPlayGame(launchInSafeMode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row {
|
|
||||||
Button(
|
|
||||||
onClick = { },
|
|
||||||
enabled = !blockLaunch,
|
|
||||||
interactionSource = interactionSource
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.PlayArrow,
|
|
||||||
contentDescription = context.getString(R.string.launcher_launch_icon_alt)
|
|
||||||
)
|
|
||||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
|
||||||
Text(context.getString(R.string.launcher_launch))
|
|
||||||
}
|
|
||||||
Spacer(Modifier.size(2.dp))
|
|
||||||
IconButton(onClick = { onSettings(context) }) {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.Settings,
|
|
||||||
contentDescription = context.getString(R.string.launcher_settings_icon_alt)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showSafeModeDialog) {
|
|
||||||
SafeModeDialog(
|
|
||||||
onDismiss = {
|
|
||||||
launchInSafeMode = false
|
|
||||||
showSafeModeDialog = false
|
|
||||||
},
|
|
||||||
onLaunch = {
|
|
||||||
launchInSafeMode = true
|
|
||||||
|
|
||||||
onPlayGame(true)
|
|
||||||
|
|
||||||
showSafeModeDialog = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun LaunchBlockedLabel(text: String) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
val showDownload = remember {
|
|
||||||
GamePackageUtils.isGameInstalled(context.packageManager) &&
|
|
||||||
!GamePackageUtils.identifyGameLegitimacy(context.packageManager)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
|
||||||
Text(text, textAlign = TextAlign.Center, modifier = Modifier.padding(12.dp))
|
|
||||||
|
|
||||||
if (showDownload) {
|
|
||||||
GooglePlayBadge()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(
|
fun MainScreen(
|
||||||
gdInstalled: Boolean = true,
|
gdInstalled: Boolean = true,
|
||||||
@@ -904,7 +111,7 @@ fun MainScreen(
|
|||||||
val autoUpdateState by releaseViewModel.uiState.collectAsState()
|
val autoUpdateState by releaseViewModel.uiState.collectAsState()
|
||||||
|
|
||||||
val geodeJustInstalled = (autoUpdateState as? ReleaseViewModel.ReleaseUIState.Finished)
|
val geodeJustInstalled = (autoUpdateState as? ReleaseViewModel.ReleaseUIState.Finished)
|
||||||
?.hasUpdated ?: false
|
?.hasUpdated == true
|
||||||
val geodeInstalled = geodePreinstalled || geodeJustInstalled
|
val geodeInstalled = geodePreinstalled || geodeJustInstalled
|
||||||
|
|
||||||
var beginLaunch by remember { mutableStateOf(false) }
|
var beginLaunch by remember { mutableStateOf(false) }
|
||||||
@@ -952,7 +159,7 @@ fun MainScreen(
|
|||||||
Image(
|
Image(
|
||||||
painter = painterResource(id = R.drawable.geode_logo),
|
painter = painterResource(id = R.drawable.geode_logo),
|
||||||
contentDescription = context.getString(R.string.launcher_logo_alt),
|
contentDescription = context.getString(R.string.launcher_logo_alt),
|
||||||
modifier = Modifier.size(136.dp, 136.dp)
|
modifier = Modifier.size(100.dp, 100.dp)
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
context.getString(R.string.launcher_title),
|
context.getString(R.string.launcher_title),
|
||||||
@@ -966,7 +173,7 @@ fun MainScreen(
|
|||||||
GamePackageUtils.getGameVersionCode(context.packageManager)
|
GamePackageUtils.getGameVersionCode(context.packageManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gdVersion < Constants.SUPPORTED_VERSION_CODE) {
|
if (gdVersion < Constants.SUPPORTED_VERSION_CODE_MIN) {
|
||||||
val versionName = remember {
|
val versionName = remember {
|
||||||
GamePackageUtils.getUnifiedVersionName(context.packageManager)
|
GamePackageUtils.getUnifiedVersionName(context.packageManager)
|
||||||
}
|
}
|
||||||
@@ -982,6 +189,10 @@ fun MainScreen(
|
|||||||
beginLaunch = true
|
beginLaunch = true
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (gdVersion < Constants.SUPPORTED_VERSION_CODE_MIN_WARNING) {
|
||||||
|
UnsupportedVersionWarning()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gdInstalled -> {
|
gdInstalled -> {
|
||||||
|
|||||||
@@ -1,366 +0,0 @@
|
|||||||
package com.geode.launcher
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.selection.toggleable
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.Clear
|
|
||||||
import androidx.compose.material3.AlertDialog
|
|
||||||
import androidx.compose.material3.Card
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.OutlinedTextField
|
|
||||||
import androidx.compose.material3.RadioButton
|
|
||||||
import androidx.compose.material3.Switch
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.TextButton
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.semantics.Role
|
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
|
||||||
import com.geode.launcher.ui.theme.Typography
|
|
||||||
import com.geode.launcher.utils.PreferenceUtils
|
|
||||||
|
|
||||||
|
|
||||||
fun toggleSetting(context: Context, preferenceKey: PreferenceUtils.Key): Boolean {
|
|
||||||
val preferences = PreferenceUtils.get(context)
|
|
||||||
|
|
||||||
return preferences.toggleBoolean(preferenceKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getSetting(context: Context, preferenceKey: PreferenceUtils.Key): Boolean {
|
|
||||||
val preferences = PreferenceUtils.get(context)
|
|
||||||
|
|
||||||
return preferences.getBoolean(preferenceKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun OptionsGroup(title: String, content: @Composable () -> Unit) {
|
|
||||||
Column {
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style = Typography.titleMedium,
|
|
||||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
|
||||||
)
|
|
||||||
content()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SettingsSelectCard(
|
|
||||||
title: String,
|
|
||||||
dialogTitle: String,
|
|
||||||
maxVal: Int,
|
|
||||||
preferenceKey: PreferenceUtils.Key,
|
|
||||||
toLabel: @Composable (Int) -> String,
|
|
||||||
extraSelectBehavior: ((Int) -> Unit)? = null
|
|
||||||
) {
|
|
||||||
val preferenceValue by PreferenceUtils.useIntPreference(preferenceKey)
|
|
||||||
|
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
OptionsCard(
|
|
||||||
title = { OptionsTitle(title = title) },
|
|
||||||
modifier = Modifier
|
|
||||||
.clickable(
|
|
||||||
onClick = {
|
|
||||||
showDialog = true
|
|
||||||
},
|
|
||||||
role = Role.Button
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Text(toLabel(preferenceValue))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showDialog) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
SelectDialog(
|
|
||||||
title = dialogTitle,
|
|
||||||
onDismissRequest = {
|
|
||||||
showDialog = false
|
|
||||||
},
|
|
||||||
onSelect = { selected ->
|
|
||||||
showDialog = false
|
|
||||||
PreferenceUtils.get(context)
|
|
||||||
.setInt(preferenceKey, selected)
|
|
||||||
extraSelectBehavior?.invoke(selected)
|
|
||||||
},
|
|
||||||
initialValue = preferenceValue,
|
|
||||||
toLabel = toLabel,
|
|
||||||
optionsCount = 0..maxVal
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SettingsStringCard(
|
|
||||||
title: String,
|
|
||||||
dialogTitle: String,
|
|
||||||
preferenceKey: PreferenceUtils.Key,
|
|
||||||
filterInput: ((String) -> String)? = null
|
|
||||||
) {
|
|
||||||
var preferenceValue by PreferenceUtils.useStringPreference(preferenceKey)
|
|
||||||
|
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
OptionsCard(
|
|
||||||
title = {
|
|
||||||
OptionsTitle(title = title, description = preferenceValue)
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.clickable(
|
|
||||||
onClick = {
|
|
||||||
showDialog = true
|
|
||||||
},
|
|
||||||
role = Role.Button
|
|
||||||
)
|
|
||||||
) { }
|
|
||||||
|
|
||||||
if (showDialog) {
|
|
||||||
StringDialog(
|
|
||||||
title = dialogTitle,
|
|
||||||
onDismissRequest = { showDialog = false },
|
|
||||||
onSelect = {
|
|
||||||
preferenceValue = it
|
|
||||||
showDialog = false
|
|
||||||
},
|
|
||||||
initialValue = preferenceValue ?: "",
|
|
||||||
filterInput = filterInput
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun StringDialog(
|
|
||||||
title: String,
|
|
||||||
onDismissRequest: () -> Unit,
|
|
||||||
onSelect: (String) -> Unit,
|
|
||||||
initialValue: String,
|
|
||||||
filterInput: ((String) -> String)? = null
|
|
||||||
) {
|
|
||||||
var enteredValue by remember { mutableStateOf(initialValue) }
|
|
||||||
|
|
||||||
AlertDialog(
|
|
||||||
onDismissRequest = { onDismissRequest() },
|
|
||||||
title = {
|
|
||||||
Text(title)
|
|
||||||
},
|
|
||||||
text = {
|
|
||||||
OutlinedTextField(
|
|
||||||
value = enteredValue,
|
|
||||||
onValueChange = {
|
|
||||||
enteredValue = filterInput?.invoke(it) ?: it
|
|
||||||
},
|
|
||||||
singleLine = true,
|
|
||||||
keyboardOptions = KeyboardOptions(
|
|
||||||
keyboardType = KeyboardType.Ascii,
|
|
||||||
autoCorrect = false
|
|
||||||
),
|
|
||||||
trailingIcon = {
|
|
||||||
if (enteredValue.isNotEmpty()) {
|
|
||||||
IconButton(onClick = { enteredValue = "" }) {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.Clear,
|
|
||||||
contentDescription = stringResource(R.string.preference_text_clear)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
confirmButton = {
|
|
||||||
TextButton(onClick = { onSelect(enteredValue) }) {
|
|
||||||
Text(stringResource(R.string.message_box_accept))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dismissButton = {
|
|
||||||
TextButton(onClick = onDismissRequest) {
|
|
||||||
Text(stringResource(R.string.message_box_cancel))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun <T> SelectDialog(
|
|
||||||
title: String,
|
|
||||||
onDismissRequest: () -> Unit,
|
|
||||||
onSelect: (T) -> Unit,
|
|
||||||
initialValue: T,
|
|
||||||
toLabel: @Composable (T) -> String,
|
|
||||||
optionsCount: Iterable<T>,
|
|
||||||
) {
|
|
||||||
var selectedValue by remember { mutableStateOf(initialValue) }
|
|
||||||
|
|
||||||
Dialog(onDismissRequest = onDismissRequest) {
|
|
||||||
Card(
|
|
||||||
shape = RoundedCornerShape(16.dp)
|
|
||||||
) {
|
|
||||||
// styling a dialog is actually a little hard if you're doing what i'm doing
|
|
||||||
// maybe there's a better way to make these padding values...
|
|
||||||
Column {
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style = Typography.titleLarge,
|
|
||||||
modifier = Modifier.padding(
|
|
||||||
start = 28.dp,
|
|
||||||
top = 24.dp,
|
|
||||||
bottom = 12.dp
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
// do not give the row or column padding!! it messes up the selection effect
|
|
||||||
optionsCount.forEach { id ->
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable(
|
|
||||||
onClick = { selectedValue = id },
|
|
||||||
role = Role.RadioButton
|
|
||||||
)
|
|
||||||
.padding(horizontal = 12.dp)
|
|
||||||
) {
|
|
||||||
RadioButton(
|
|
||||||
selected = selectedValue == id,
|
|
||||||
onClick = { selectedValue = id }
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
toLabel(id),
|
|
||||||
style = Typography.bodyMedium
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.End,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(
|
|
||||||
bottom = 16.dp,
|
|
||||||
end = 16.dp,
|
|
||||||
top = 4.dp
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
TextButton(onClick = onDismissRequest) {
|
|
||||||
Text(stringResource(R.string.message_box_cancel))
|
|
||||||
}
|
|
||||||
|
|
||||||
TextButton(onClick = { onSelect(selectedValue) }) {
|
|
||||||
Text(stringResource(R.string.message_box_accept))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun OptionsButton(title: String, description: String? = null, onClick: () -> Unit) {
|
|
||||||
OptionsCard(
|
|
||||||
title = {
|
|
||||||
OptionsTitle(
|
|
||||||
title = title,
|
|
||||||
description = description
|
|
||||||
)
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.clickable(onClick = onClick, role = Role.Button)
|
|
||||||
) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SettingsCard(title: String, description: String? = null, preferenceKey: PreferenceUtils.Key) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
val settingEnabled = remember {
|
|
||||||
mutableStateOf(getSetting(context, preferenceKey))
|
|
||||||
}
|
|
||||||
|
|
||||||
OptionsCard(
|
|
||||||
title = {
|
|
||||||
OptionsTitle(
|
|
||||||
Modifier.fillMaxWidth(0.75f),
|
|
||||||
title = title,
|
|
||||||
description = description
|
|
||||||
)
|
|
||||||
},
|
|
||||||
modifier = Modifier.toggleable(
|
|
||||||
value = settingEnabled.value,
|
|
||||||
onValueChange = { settingEnabled.value = toggleSetting(context, preferenceKey) },
|
|
||||||
role = Role.Switch,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Switch(checked = settingEnabled.value, onCheckedChange = null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun OptionsTitle(modifier: Modifier = Modifier, title: String, description: String? = null) {
|
|
||||||
Column(
|
|
||||||
modifier,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
|
||||||
) {
|
|
||||||
Text(title)
|
|
||||||
if (!description.isNullOrEmpty()) {
|
|
||||||
Text(
|
|
||||||
description,
|
|
||||||
style = Typography.labelMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSecondaryContainer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun OptionsCard(modifier: Modifier = Modifier, title: @Composable () -> Unit, content: @Composable () -> Unit) {
|
|
||||||
Row(
|
|
||||||
modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(64.dp)
|
|
||||||
.padding(horizontal = 16.dp),
|
|
||||||
Arrangement.SpaceBetween,
|
|
||||||
Alignment.CenterVertically,
|
|
||||||
) {
|
|
||||||
title()
|
|
||||||
content()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
|
||||||
@Composable
|
|
||||||
fun OptionsCardPreview() {
|
|
||||||
GeodeLauncherTheme {
|
|
||||||
OptionsGroup(title = "Preview Group") {
|
|
||||||
SettingsCard(
|
|
||||||
title = "Load files from /test",
|
|
||||||
description = "Very long testing description goes here. It is incredibly long, it should wrap onto a new line.",
|
|
||||||
preferenceKey = PreferenceUtils.Key.BLACK_BACKGROUND
|
|
||||||
)
|
|
||||||
SettingsCard(
|
|
||||||
title = "Testing option 2",
|
|
||||||
preferenceKey = PreferenceUtils.Key.LOAD_AUTOMATICALLY
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -40,7 +40,7 @@ class UserDirectoryProvider : DocumentsProvider() {
|
|||||||
|
|
||||||
override fun onCreate(): Boolean {
|
override fun onCreate(): Boolean {
|
||||||
val context = context ?: return false
|
val context = context ?: return false
|
||||||
rootDir = LaunchUtils.getBaseDirectory(context)
|
rootDir = LaunchUtils.getBaseDirectory(context, true)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import kotlinx.datetime.Instant
|
|||||||
import kotlinx.datetime.TimeZone
|
import kotlinx.datetime.TimeZone
|
||||||
import kotlinx.datetime.toJavaInstant
|
import kotlinx.datetime.toJavaInstant
|
||||||
import kotlinx.datetime.toLocalDateTime
|
import kotlinx.datetime.toLocalDateTime
|
||||||
|
import okio.Buffer
|
||||||
import okio.BufferedSource
|
import okio.BufferedSource
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@@ -161,7 +162,7 @@ data class LogLine(
|
|||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* val payloadLength = */ source.readShortLe()
|
val payloadLength = source.readShortLe().toLong()
|
||||||
val headerSize = source.readShortLe().toUShort()
|
val headerSize = source.readShortLe().toUShort()
|
||||||
|
|
||||||
val entryVersion = headerSizeToVersion(headerSize)
|
val entryVersion = headerSizeToVersion(headerSize)
|
||||||
@@ -177,11 +178,17 @@ data class LogLine(
|
|||||||
val processInformation = ProcessInformation(pid, tid, uid)
|
val processInformation = ProcessInformation(pid, tid, uid)
|
||||||
val time = Instant.fromEpochSeconds(sec, nSec)
|
val time = Instant.fromEpochSeconds(sec, nSec)
|
||||||
|
|
||||||
val priorityByte = source.readByte()
|
// the payload is split into three parts
|
||||||
|
// initial priority byte -> null terminated tag -> non null terminated message
|
||||||
|
|
||||||
|
val packetBuffer = Buffer()
|
||||||
|
source.readFully(packetBuffer, payloadLength)
|
||||||
|
|
||||||
|
val priorityByte = packetBuffer.readByte()
|
||||||
val priority = LogPriority.fromByte(priorityByte)
|
val priority = LogPriority.fromByte(priorityByte)
|
||||||
|
|
||||||
val tag = source.readCString()
|
val tag = packetBuffer.readCString()
|
||||||
val message = source.readCString()
|
val message = packetBuffer.readUtf8()
|
||||||
|
|
||||||
return LogLine(
|
return LogLine(
|
||||||
process = processInformation,
|
process = processInformation,
|
||||||
@@ -205,7 +212,9 @@ data class LogLine(
|
|||||||
|
|
||||||
val identifier = time.toJavaInstant()
|
val identifier = time.toJavaInstant()
|
||||||
|
|
||||||
val messageTrimmed by lazy { this.message.trim() }
|
val messageTrimmed by lazy {
|
||||||
|
this.message.trim { it <= ' ' }
|
||||||
|
}
|
||||||
|
|
||||||
val formattedTime by lazy { this.time.toLocalDateTime(TimeZone.currentSystemDefault()) }
|
val formattedTime by lazy { this.time.toLocalDateTime(TimeZone.currentSystemDefault()) }
|
||||||
val asSimpleString by lazy {
|
val asSimpleString by lazy {
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import kotlinx.coroutines.coroutineScope
|
|||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
|
import okio.Buffer
|
||||||
import okio.buffer
|
import okio.buffer
|
||||||
import okio.source
|
import okio.source
|
||||||
import java.io.EOFException
|
import java.io.EOFException
|
||||||
@@ -61,7 +63,9 @@ class LogViewModel: ViewModel() {
|
|||||||
else "logcat -B -d"
|
else "logcat -B -d"
|
||||||
|
|
||||||
val logProcess = try {
|
val logProcess = try {
|
||||||
Runtime.getRuntime().exec(logCommand)
|
withContext(Dispatchers.IO) {
|
||||||
|
Runtime.getRuntime().exec(logCommand)
|
||||||
|
}
|
||||||
} catch (ioe: IOException) {
|
} catch (ioe: IOException) {
|
||||||
ioe.printStackTrace()
|
ioe.printStackTrace()
|
||||||
logLines += LogLine.showException(ioe)
|
logLines += LogLine.showException(ioe)
|
||||||
@@ -71,13 +75,15 @@ class LogViewModel: ViewModel() {
|
|||||||
return logLines
|
return logLines
|
||||||
}
|
}
|
||||||
|
|
||||||
val logSource = logProcess.inputStream.source().buffer()
|
// read entire log into a buffer so no logs are added to the buffer during processing
|
||||||
|
val logBuffer = Buffer()
|
||||||
|
logProcess.inputStream.source().buffer().readAll(logBuffer)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
coroutineScope {
|
coroutineScope {
|
||||||
// this runs until the stream is exhausted
|
// this runs until the stream is exhausted
|
||||||
while (true) {
|
while (true) {
|
||||||
val line = LogLine.fromBufferedSource(logSource)
|
val line = LogLine.fromBufferedSource(logBuffer)
|
||||||
|
|
||||||
if (line.priority >= logLevel) {
|
if (line.priority >= logLevel) {
|
||||||
logLines += line
|
logLines += line
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package com.geode.launcher.main
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.sizeIn
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.shape.AbsoluteRoundedCornerShape
|
||||||
|
import androidx.compose.material3.ElevatedCard
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.geode.launcher.R
|
||||||
|
import com.geode.launcher.utils.Constants
|
||||||
|
|
||||||
|
fun onDownloadGame(context: Context) {
|
||||||
|
val appUrl = "https://play.google.com/store/apps/details?id=${Constants.PACKAGE_NAME}"
|
||||||
|
try {
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||||
|
data = Uri.parse(appUrl)
|
||||||
|
setPackage("com.android.vending")
|
||||||
|
}
|
||||||
|
context.startActivity(intent)
|
||||||
|
} catch (_: ActivityNotFoundException) {
|
||||||
|
Toast.makeText(context, R.string.no_activity_found, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun GooglePlayBadge(modifier: Modifier = Modifier) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
Image(
|
||||||
|
painter = painterResource(id = R.drawable.google_play_badge),
|
||||||
|
contentDescription = stringResource(R.string.launcher_download_game),
|
||||||
|
modifier = modifier
|
||||||
|
.width(196.dp)
|
||||||
|
.clip(AbsoluteRoundedCornerShape(4.dp))
|
||||||
|
.clickable { onDownloadGame(context) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun StatusIndicator(
|
||||||
|
icon: @Composable () -> Unit,
|
||||||
|
text: @Composable () -> Unit,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
ElevatedCard(modifier = modifier, onClick = onClick) {
|
||||||
|
Row(modifier = Modifier.padding(8.dp)) {
|
||||||
|
icon()
|
||||||
|
Spacer(Modifier.size(8.dp))
|
||||||
|
text()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun InlineDialog(headline: @Composable () -> Unit, body: @Composable () -> Unit, modifier: Modifier = Modifier) {
|
||||||
|
ElevatedCard(modifier = modifier) {
|
||||||
|
Column(modifier = Modifier.padding(18.dp).sizeIn(maxWidth = 512.dp)) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
modifier = Modifier.padding(bottom = 8.dp)
|
||||||
|
) {
|
||||||
|
headline()
|
||||||
|
}
|
||||||
|
|
||||||
|
body()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,391 @@
|
|||||||
|
package com.geode.launcher.main
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
|
import android.provider.DocumentsContract
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||||
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Share
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.FilledTonalButton
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
|
import androidx.compose.material3.SnackbarDuration
|
||||||
|
import androidx.compose.material3.SnackbarHostState
|
||||||
|
import androidx.compose.material3.SnackbarResult
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
|
import androidx.compose.ui.text.LinkAnnotation
|
||||||
|
import androidx.compose.ui.text.SpanStyle
|
||||||
|
import androidx.compose.ui.text.TextLinkStyles
|
||||||
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
|
import androidx.compose.ui.text.withLink
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.geode.launcher.preferences.ApplicationLogsActivity
|
||||||
|
import com.geode.launcher.BuildConfig
|
||||||
|
import com.geode.launcher.R
|
||||||
|
import com.geode.launcher.UserDirectoryProvider
|
||||||
|
import com.geode.launcher.ui.theme.Typography
|
||||||
|
import com.geode.launcher.utils.GamePackageUtils
|
||||||
|
import com.geode.launcher.utils.LaunchUtils
|
||||||
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
|
|
||||||
|
data class LoadFailureInfo(
|
||||||
|
val title: LaunchUtils.LauncherError,
|
||||||
|
val description: String? = null,
|
||||||
|
val extendedMessage: String? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ErrorInfoBody(failureReason: LaunchUtils.LauncherError, modifier: Modifier = Modifier) {
|
||||||
|
val headline = when (failureReason) {
|
||||||
|
LaunchUtils.LauncherError.LINKER_FAILED -> stringResource(R.string.load_failed_link_error_description)
|
||||||
|
LaunchUtils.LauncherError.CRASHED -> stringResource(R.string.load_failed_crashed_description)
|
||||||
|
else -> stringResource(R.string.load_failed_generic_error_description)
|
||||||
|
}
|
||||||
|
|
||||||
|
val context = LocalContext.current
|
||||||
|
val recommendations = when (failureReason) {
|
||||||
|
LaunchUtils.LauncherError.LINKER_FAILED_STL -> {
|
||||||
|
val isDeveloper = PreferenceUtils.get(context).getBoolean(PreferenceUtils.Key.DEVELOPER_MODE)
|
||||||
|
|
||||||
|
buildList {
|
||||||
|
add(stringResource(R.string.load_failed_recommendation_update))
|
||||||
|
add(stringResource(R.string.load_failed_recommendation_report))
|
||||||
|
|
||||||
|
if (isDeveloper)
|
||||||
|
add(stringResource(R.string.load_failed_recommendation_dev_stl))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LaunchUtils.LauncherError.LINKER_FAILED -> listOfNotNull(
|
||||||
|
stringResource(R.string.load_failed_recommendation_reinstall),
|
||||||
|
stringResource(R.string.load_failed_recommendation_update),
|
||||||
|
)
|
||||||
|
LaunchUtils.LauncherError.CRASHED -> listOf(
|
||||||
|
stringResource(R.string.load_failed_recommendation_safe_mode),
|
||||||
|
stringResource(R.string.load_failed_recommendation_report)
|
||||||
|
)
|
||||||
|
else -> listOf(
|
||||||
|
stringResource(R.string.load_failed_recommendation_reinstall),
|
||||||
|
stringResource(R.string.load_failed_recommendation_update),
|
||||||
|
stringResource(R.string.load_failed_recommendation_report)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(modifier = modifier) {
|
||||||
|
Text(headline)
|
||||||
|
|
||||||
|
recommendations.forEach { r ->
|
||||||
|
Text("\u2022\u00A0\u00A0$r")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ErrorInfoTitle(failureReason: LaunchUtils.LauncherError) {
|
||||||
|
val message = when (failureReason) {
|
||||||
|
LaunchUtils.LauncherError.LINKER_NEEDS_64BIT,
|
||||||
|
LaunchUtils.LauncherError.LINKER_NEEDS_32BIT,
|
||||||
|
LaunchUtils.LauncherError.LINKER_FAILED_STL,
|
||||||
|
LaunchUtils.LauncherError.LINKER_FAILED -> stringResource(R.string.load_failed_link_error)
|
||||||
|
LaunchUtils.LauncherError.GENERIC -> stringResource(R.string.load_failed_generic_error)
|
||||||
|
LaunchUtils.LauncherError.CRASHED -> stringResource(R.string.load_failed_crashed)
|
||||||
|
}
|
||||||
|
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.icon_error),
|
||||||
|
contentDescription = stringResource(R.string.launcher_error_icon_alt),
|
||||||
|
modifier = Modifier.size(28.dp)
|
||||||
|
)
|
||||||
|
Text(message, style = Typography.headlineMedium)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onShareCrash(context: Context) {
|
||||||
|
val lastCrash = LaunchUtils.getLastCrash(context)
|
||||||
|
if (lastCrash == null) {
|
||||||
|
Toast.makeText(context, R.string.launcher_error_export_missing, Toast.LENGTH_SHORT).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val baseDirectory = LaunchUtils.getBaseDirectory(context)
|
||||||
|
|
||||||
|
val providerLocation = lastCrash.toRelativeString(baseDirectory)
|
||||||
|
val documentsPath = "${UserDirectoryProvider.ROOT}${providerLocation}"
|
||||||
|
|
||||||
|
val uri = DocumentsContract.buildDocumentUri("${context.packageName}.user", documentsPath)
|
||||||
|
|
||||||
|
val shareIntent = Intent(Intent.ACTION_SEND).apply {
|
||||||
|
putExtra(Intent.EXTRA_STREAM, uri)
|
||||||
|
type = "application/octet-stream"
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
context.startActivity(shareIntent)
|
||||||
|
} catch (_: ActivityNotFoundException) {
|
||||||
|
Toast.makeText(context, R.string.no_activity_found, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onShowLogs(context: Context) {
|
||||||
|
val launchIntent = Intent(context, ApplicationLogsActivity::class.java)
|
||||||
|
context.startActivity(launchIntent)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ErrorInfoDescription(description: String, modifier: Modifier = Modifier) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val currentRelease = remember {
|
||||||
|
PreferenceUtils.get(context).getString(PreferenceUtils.Key.CURRENT_VERSION_TAG)
|
||||||
|
}
|
||||||
|
|
||||||
|
val gameVersion = remember {
|
||||||
|
GamePackageUtils.getUnifiedVersionName(context.packageManager)
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(modifier = modifier) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.launcher_error_details),
|
||||||
|
style = Typography.headlineSmall
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(Modifier.size(8.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
description,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
style = Typography.bodyMedium
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(Modifier.size(4.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.launcher_error_device_info,
|
||||||
|
Build.MODEL,
|
||||||
|
Build.VERSION.RELEASE,
|
||||||
|
currentRelease ?: "unknown",
|
||||||
|
gameVersion,
|
||||||
|
LaunchUtils.applicationArchitecture,
|
||||||
|
BuildConfig.VERSION_NAME
|
||||||
|
),
|
||||||
|
style = Typography.labelMedium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
|
fun ErrorInfoActions(extraDetails: String?, modifier: Modifier = Modifier) {
|
||||||
|
val clipboardManager = LocalClipboardManager.current
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
FlowRow(
|
||||||
|
modifier = modifier,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(
|
||||||
|
12.dp, alignment = Alignment.CenterHorizontally
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
if (extraDetails != null) {
|
||||||
|
Button(onClick = { onShowLogs(context) }) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.icon_description),
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(stringResource(R.string.launcher_error_view_logs))
|
||||||
|
}
|
||||||
|
|
||||||
|
FilledTonalButton(onClick = {
|
||||||
|
clipboardManager.setText(AnnotatedString(extraDetails))
|
||||||
|
}) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.icon_content_copy),
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(stringResource(R.string.launcher_error_copy))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Button(onClick = { onShareCrash(context) }) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Share,
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(stringResource(R.string.launcher_error_export_crash))
|
||||||
|
}
|
||||||
|
|
||||||
|
FilledTonalButton(onClick = { onShowLogs(context) }) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.icon_description),
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(stringResource(R.string.launcher_error_view_logs))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun DownloadRecommendation(needsUniversal: Boolean, modifier: Modifier = Modifier) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val version = BuildConfig.VERSION_NAME
|
||||||
|
|
||||||
|
val showDownload = remember { GamePackageUtils.showDownloadBadge(context.packageManager) }
|
||||||
|
|
||||||
|
val downloadBase = "https://github.com/geode-sdk/android-launcher/releases/download/$version"
|
||||||
|
val legacyDownloadUrl = "$downloadBase/geode-launcher-v$version-android32.apk"
|
||||||
|
val universalDownloadUrl = "$downloadBase/geode-launcher-v$version.apk"
|
||||||
|
|
||||||
|
val downloadUrl = if (needsUniversal)
|
||||||
|
universalDownloadUrl else legacyDownloadUrl
|
||||||
|
|
||||||
|
val downloadText = if (needsUniversal)
|
||||||
|
stringResource(R.string.launcher_download_universal)
|
||||||
|
else
|
||||||
|
stringResource(R.string.launcher_download_32bit)
|
||||||
|
|
||||||
|
val promptTitle = stringResource(R.string.load_failed_abi_error)
|
||||||
|
val reinstallText = stringResource(R.string.load_failed_recommendation_reinstall)
|
||||||
|
val recommendationText = if (needsUniversal)
|
||||||
|
stringResource(R.string.load_failed_recommendation_switch_64bit_abi)
|
||||||
|
else
|
||||||
|
stringResource(R.string.load_failed_recommendation_switch_32bit_abi)
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = modifier,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(
|
||||||
|
12.dp, alignment = Alignment.CenterVertically
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Text(promptTitle)
|
||||||
|
Text("\u2022\u00A0\u00A0$reinstallText")
|
||||||
|
|
||||||
|
if (showDownload) {
|
||||||
|
GooglePlayBadge()
|
||||||
|
}
|
||||||
|
|
||||||
|
Text("\u2022\u00A0\u00A0$recommendationText")
|
||||||
|
|
||||||
|
Text(
|
||||||
|
buildAnnotatedString {
|
||||||
|
withLink(LinkAnnotation.Url(
|
||||||
|
downloadUrl,
|
||||||
|
TextLinkStyles(
|
||||||
|
style = SpanStyle(
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
textDecoration = TextDecoration.Underline
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)) {
|
||||||
|
append(downloadText)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun ErrorInfoSheet(failureInfo: LoadFailureInfo, onDismiss: () -> Unit) {
|
||||||
|
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||||
|
|
||||||
|
ModalBottomSheet(onDismissRequest = { onDismiss() }, sheetState = sheetState) {
|
||||||
|
// second container created for scroll (before padding is added)
|
||||||
|
Box(Modifier.verticalScroll(rememberScrollState())) {
|
||||||
|
Column(modifier = Modifier
|
||||||
|
.padding(horizontal = 24.dp)
|
||||||
|
) {
|
||||||
|
ErrorInfoTitle(failureInfo.title)
|
||||||
|
|
||||||
|
Spacer(Modifier.size(16.dp))
|
||||||
|
|
||||||
|
if (failureInfo.title.isAbiFailure()) {
|
||||||
|
DownloadRecommendation(
|
||||||
|
needsUniversal = failureInfo.title == LaunchUtils.LauncherError.LINKER_NEEDS_64BIT,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 8.dp, bottom = 16.dp)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
ErrorInfoBody(failureInfo.title)
|
||||||
|
|
||||||
|
if (failureInfo.description != null) {
|
||||||
|
ErrorInfoDescription(
|
||||||
|
failureInfo.description,
|
||||||
|
modifier = Modifier.padding(vertical = 8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorInfoActions(
|
||||||
|
extraDetails = failureInfo.extendedMessage ?: failureInfo.description,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 8.dp, bottom = 16.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun showFailureSnackbar(
|
||||||
|
context: Context,
|
||||||
|
loadFailureInfo: LoadFailureInfo,
|
||||||
|
snackbarHostState: SnackbarHostState,
|
||||||
|
onActionPerformed: () -> Unit
|
||||||
|
) {
|
||||||
|
val message = if (loadFailureInfo.title == LaunchUtils.LauncherError.CRASHED) {
|
||||||
|
context.getString(R.string.launcher_crashed)
|
||||||
|
} else {
|
||||||
|
context.getString(R.string.launcher_failed_to_load)
|
||||||
|
}
|
||||||
|
|
||||||
|
val res = snackbarHostState.showSnackbar(
|
||||||
|
message = message,
|
||||||
|
actionLabel = context.getString(R.string.launcher_error_more),
|
||||||
|
duration = SnackbarDuration.Indefinite,
|
||||||
|
)
|
||||||
|
|
||||||
|
when (res) {
|
||||||
|
SnackbarResult.ActionPerformed -> {
|
||||||
|
onActionPerformed()
|
||||||
|
}
|
||||||
|
SnackbarResult.Dismissed -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,315 @@
|
|||||||
|
package com.geode.launcher.main
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
|
import androidx.compose.foundation.interaction.PressInteraction
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.RowScope
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.PlayArrow
|
||||||
|
import androidx.compose.material.icons.filled.Settings
|
||||||
|
import androidx.compose.material.icons.filled.Warning
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
|
import androidx.compose.ui.platform.LocalViewConfiguration
|
||||||
|
import androidx.compose.ui.res.pluralStringResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.geode.launcher.GeometryDashActivity
|
||||||
|
import com.geode.launcher.R
|
||||||
|
import com.geode.launcher.preferences.SettingsActivity
|
||||||
|
import com.geode.launcher.ui.theme.Typography
|
||||||
|
import com.geode.launcher.utils.Constants
|
||||||
|
import com.geode.launcher.utils.GamePackageUtils
|
||||||
|
import com.geode.launcher.utils.GeodeUtils
|
||||||
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
|
import com.geode.launcher.utils.useCountdownTimer
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun UpdateWarning(inSafeMode: Boolean = false, onDismiss: () -> Unit) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val packageManager = context.packageManager
|
||||||
|
|
||||||
|
val gdVersionCode = remember { GamePackageUtils.getGameVersionCode(packageManager) }
|
||||||
|
val gdVersionString = remember { GamePackageUtils.getGameVersionString(packageManager) }
|
||||||
|
|
||||||
|
var lastDismissedVersion by PreferenceUtils.useLongPreference(
|
||||||
|
preferenceKey = PreferenceUtils.Key.DISMISSED_GJ_UPDATE
|
||||||
|
)
|
||||||
|
|
||||||
|
val onUnsupportedVersion = gdVersionCode < Constants.SUPPORTED_VERSION_CODE_MIN || gdVersionCode > Constants.SUPPORTED_VERSION_CODE
|
||||||
|
val canDismissRelease = gdVersionCode >= Constants.SUPPORTED_VERSION_CODE
|
||||||
|
val shouldDismiss = canDismissRelease && gdVersionCode == lastDismissedVersion
|
||||||
|
|
||||||
|
if (onUnsupportedVersion && !shouldDismiss) {
|
||||||
|
AlertDialog(
|
||||||
|
icon = {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Warning,
|
||||||
|
contentDescription = stringResource(R.string.launcher_warning_icon_alt)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Text(stringResource(R.string.launcher_unsupported_version_title))
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
stringResource(
|
||||||
|
R.string.launcher_unsupported_version_description,
|
||||||
|
gdVersionString,
|
||||||
|
Constants.SUPPORTED_VERSION_STRING
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = {
|
||||||
|
onDismiss()
|
||||||
|
lastDismissedVersion = gdVersionCode
|
||||||
|
|
||||||
|
onLaunch(context, inSafeMode)
|
||||||
|
}) {
|
||||||
|
Text(stringResource(R.string.message_box_accept))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { onDismiss() }) {
|
||||||
|
Text(stringResource(R.string.message_box_cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onDismissRequest = { onDismiss() }
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
LaunchedEffect(gdVersionCode) {
|
||||||
|
onLaunch(context, inSafeMode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SafeModeDialog(onDismiss: () -> Unit, onLaunch: () -> Unit) {
|
||||||
|
AlertDialog(
|
||||||
|
icon = {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Warning,
|
||||||
|
contentDescription = stringResource(R.string.launcher_warning_icon_alt)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
title = { Text(stringResource(R.string.safe_mode_enable_title)) },
|
||||||
|
text = { Text(stringResource(R.string.safe_mode_enable_description)) },
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text(stringResource(R.string.message_box_cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onLaunch) {
|
||||||
|
Text(stringResource(R.string.message_box_continue))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onDismissRequest = onDismiss
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onLaunch(context: Context, safeMode: Boolean = false) {
|
||||||
|
if (safeMode) {
|
||||||
|
GeodeUtils.setAdditionalLaunchArguments(GeodeUtils.ARGUMENT_SAFE_MODE)
|
||||||
|
} else {
|
||||||
|
GeodeUtils.clearLaunchArguments()
|
||||||
|
}
|
||||||
|
|
||||||
|
val launchIntent = Intent(context, GeometryDashActivity::class.java)
|
||||||
|
launchIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
|
||||||
|
context.startActivity(launchIntent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onSettings(context: Context) {
|
||||||
|
val launchIntent = Intent(context, SettingsActivity::class.java)
|
||||||
|
context.startActivity(launchIntent)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LongPressButton(onClick: () -> Unit, onLongPress: () -> Unit, enabled: Boolean = true, modifier: Modifier = Modifier, content: @Composable RowScope.() -> Unit) {
|
||||||
|
// compose apis don't provide a good way of adding long press to a button
|
||||||
|
var isLongPress by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
|
val viewConfiguration = LocalViewConfiguration.current
|
||||||
|
val haptics = LocalHapticFeedback.current
|
||||||
|
|
||||||
|
LaunchedEffect(interactionSource) {
|
||||||
|
interactionSource.interactions.collectLatest { interaction ->
|
||||||
|
when (interaction) {
|
||||||
|
is PressInteraction.Press -> {
|
||||||
|
delay(viewConfiguration.longPressTimeoutMillis)
|
||||||
|
|
||||||
|
// perform a second delay to make the action more obvious
|
||||||
|
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
|
delay(viewConfiguration.longPressTimeoutMillis)
|
||||||
|
|
||||||
|
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
|
|
||||||
|
isLongPress = true
|
||||||
|
onLongPress()
|
||||||
|
}
|
||||||
|
is PressInteraction.Release -> {
|
||||||
|
if (!isLongPress) {
|
||||||
|
onClick()
|
||||||
|
}
|
||||||
|
isLongPress = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = {},
|
||||||
|
enabled = enabled,
|
||||||
|
modifier = modifier,
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
content = content
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun PlayButton(
|
||||||
|
stopAutomaticLaunch: Boolean,
|
||||||
|
blockLaunch: Boolean,
|
||||||
|
onPlayGame: (Boolean) -> Unit
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
var showSafeModeDialog by remember { mutableStateOf(false) }
|
||||||
|
var launchInSafeMode by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val shouldAutomaticallyLaunch by PreferenceUtils.useBooleanPreference(
|
||||||
|
preferenceKey = PreferenceUtils.Key.LOAD_AUTOMATICALLY
|
||||||
|
)
|
||||||
|
|
||||||
|
if (shouldAutomaticallyLaunch && !stopAutomaticLaunch && !showSafeModeDialog) {
|
||||||
|
val countdownTimer = useCountdownTimer(
|
||||||
|
time = 3000,
|
||||||
|
onCountdownFinish = { onPlayGame(launchInSafeMode) }
|
||||||
|
)
|
||||||
|
|
||||||
|
if (countdownTimer != 0L) {
|
||||||
|
Text(
|
||||||
|
pluralStringResource(
|
||||||
|
R.plurals.automatically_load_countdown,
|
||||||
|
countdownTimer.toInt(),
|
||||||
|
countdownTimer
|
||||||
|
),
|
||||||
|
style = Typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(12.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Row {
|
||||||
|
LongPressButton(
|
||||||
|
enabled = !blockLaunch,
|
||||||
|
onLongPress = {
|
||||||
|
showSafeModeDialog = true
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
onPlayGame(launchInSafeMode)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.PlayArrow,
|
||||||
|
contentDescription = context.getString(R.string.launcher_launch_icon_alt)
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(context.getString(R.string.launcher_launch))
|
||||||
|
}
|
||||||
|
Spacer(Modifier.size(2.dp))
|
||||||
|
IconButton(onClick = { onSettings(context) }) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Settings,
|
||||||
|
contentDescription = context.getString(R.string.launcher_settings_icon_alt)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showSafeModeDialog) {
|
||||||
|
SafeModeDialog(
|
||||||
|
onDismiss = {
|
||||||
|
launchInSafeMode = false
|
||||||
|
showSafeModeDialog = false
|
||||||
|
},
|
||||||
|
onLaunch = {
|
||||||
|
launchInSafeMode = true
|
||||||
|
|
||||||
|
onPlayGame(true)
|
||||||
|
|
||||||
|
showSafeModeDialog = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LaunchBlockedLabel(text: String) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val showDownload = remember { GamePackageUtils.showDownloadBadge(context.packageManager) }
|
||||||
|
|
||||||
|
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||||
|
Text(text, textAlign = TextAlign.Center, modifier = Modifier.padding(12.dp))
|
||||||
|
|
||||||
|
if (showDownload) {
|
||||||
|
GooglePlayBadge()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun UnsupportedVersionWarning(modifier: Modifier = Modifier) {
|
||||||
|
InlineDialog(
|
||||||
|
headline = {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Warning,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(28.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.launcher_unsupported_version_title),
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
body = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.launcher_game_update_required),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = modifier.padding(8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,260 @@
|
|||||||
|
package com.geode.launcher.main
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.core.MutableTransitionState
|
||||||
|
import androidx.compose.animation.expandHorizontally
|
||||||
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
|
import androidx.compose.animation.shrinkHorizontally
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.IntrinsicSize
|
||||||
|
import androidx.compose.foundation.layout.displayCutoutPadding
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Info
|
||||||
|
import androidx.compose.material.icons.filled.Warning
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.ListItem
|
||||||
|
import androidx.compose.material3.LocalContentColor
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedCard
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.geode.launcher.R
|
||||||
|
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
||||||
|
import com.geode.launcher.ui.theme.LocalTheme
|
||||||
|
import com.geode.launcher.ui.theme.Theme
|
||||||
|
import com.geode.launcher.updater.ReleaseManager
|
||||||
|
import com.geode.launcher.utils.Constants
|
||||||
|
import com.geode.launcher.utils.GamePackageUtils
|
||||||
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
|
enum class LaunchNotificationType {
|
||||||
|
GEODE_UPDATED, LAUNCHER_UPDATE_AVAILABLE, UPDATE_FAILED, UNSUPPORTED_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun determineDisplayedCards(context: Context): List<LaunchNotificationType> {
|
||||||
|
val cards = mutableListOf<LaunchNotificationType>()
|
||||||
|
|
||||||
|
if (GamePackageUtils.getGameVersionCode(context.packageManager) < Constants.SUPPORTED_VERSION_CODE_MIN_WARNING) {
|
||||||
|
cards.add(LaunchNotificationType.UNSUPPORTED_VERSION)
|
||||||
|
}
|
||||||
|
|
||||||
|
val releaseManager = ReleaseManager.get(context)
|
||||||
|
val loadAutomatically = PreferenceUtils.get(context).getBoolean(PreferenceUtils.Key.LOAD_AUTOMATICALLY)
|
||||||
|
|
||||||
|
val availableUpdate = releaseManager.availableLauncherUpdate.value
|
||||||
|
if (loadAutomatically && availableUpdate != null) {
|
||||||
|
cards.add(LaunchNotificationType.LAUNCHER_UPDATE_AVAILABLE)
|
||||||
|
}
|
||||||
|
|
||||||
|
val releaseState = releaseManager.uiState.value
|
||||||
|
|
||||||
|
if (releaseState is ReleaseManager.ReleaseManagerState.Finished && releaseState.hasUpdated) {
|
||||||
|
cards.add(LaunchNotificationType.GEODE_UPDATED)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (releaseState is ReleaseManager.ReleaseManagerState.Failure) {
|
||||||
|
cards.add(LaunchNotificationType.UPDATE_FAILED)
|
||||||
|
}
|
||||||
|
|
||||||
|
return cards
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun NotificationCardFromType(type: LaunchNotificationType) {
|
||||||
|
when (type) {
|
||||||
|
LaunchNotificationType.LAUNCHER_UPDATE_AVAILABLE -> {
|
||||||
|
var showInfoDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (showInfoDialog) {
|
||||||
|
LauncherUpdateInformation {
|
||||||
|
showInfoDialog = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimatedNotificationCard(
|
||||||
|
displayLength = 5000L,
|
||||||
|
onClick = {
|
||||||
|
showInfoDialog = true
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
LauncherUpdateContent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LaunchNotificationType.UPDATE_FAILED -> {
|
||||||
|
AnimatedNotificationCard {
|
||||||
|
UpdateFailedContent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LaunchNotificationType.UNSUPPORTED_VERSION -> {
|
||||||
|
AnimatedNotificationCard {
|
||||||
|
OutdatedVersionContent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LaunchNotification() {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
|
||||||
|
val theme = Theme.fromInt(themeOption)
|
||||||
|
|
||||||
|
val backgroundOption by PreferenceUtils.useBooleanPreference(PreferenceUtils.Key.BLACK_BACKGROUND)
|
||||||
|
|
||||||
|
val cards = determineDisplayedCards(context)
|
||||||
|
|
||||||
|
CompositionLocalProvider(LocalTheme provides theme) {
|
||||||
|
GeodeLauncherTheme(theme = theme, blackBackground = backgroundOption) {
|
||||||
|
// surface is not in use, so this is unfortunately not provided
|
||||||
|
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurface) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.displayCutoutPadding()
|
||||||
|
) {
|
||||||
|
cards.forEach {
|
||||||
|
NotificationCardFromType(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun AnimatedNotificationCard(modifier: Modifier = Modifier, visibilityDelay: Long = 0L, displayLength: Long = 3000L, onClick: (() -> Unit)? = null, contents: @Composable () -> Unit) {
|
||||||
|
val state = remember {
|
||||||
|
MutableTransitionState(false).apply {
|
||||||
|
targetState = visibilityDelay <= 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(true) {
|
||||||
|
if (visibilityDelay > 0) {
|
||||||
|
delay(visibilityDelay)
|
||||||
|
state.targetState = true
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(displayLength)
|
||||||
|
state.targetState = false
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimatedVisibility(
|
||||||
|
visibleState = state,
|
||||||
|
enter = expandHorizontally() + fadeIn(),
|
||||||
|
exit = shrinkHorizontally() + fadeOut(),
|
||||||
|
modifier = modifier
|
||||||
|
) {
|
||||||
|
CardView(onClick, modifier = Modifier.padding(8.dp)) {
|
||||||
|
contents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun CardView(onClick: (() -> Unit)?, modifier: Modifier = Modifier, contents: @Composable () -> Unit) {
|
||||||
|
// val surfaceColor = MaterialTheme.colorScheme.background.copy(alpha = 0.75f)
|
||||||
|
|
||||||
|
if (onClick != null) {
|
||||||
|
OutlinedCard(
|
||||||
|
onClick = onClick,
|
||||||
|
modifier = modifier
|
||||||
|
) {
|
||||||
|
contents()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
OutlinedCard(
|
||||||
|
modifier = modifier
|
||||||
|
) {
|
||||||
|
contents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LauncherUpdateContent(modifier: Modifier = Modifier) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(text = stringResource(id = R.string.launcher_update_available))
|
||||||
|
},
|
||||||
|
supportingContent = {
|
||||||
|
Text(text = stringResource(id = R.string.launcher_notification_update_cta))
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Info,
|
||||||
|
contentDescription = null,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = modifier.width(IntrinsicSize.Max)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun UpdateNotificationContent(modifier: Modifier = Modifier) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(text = stringResource(id = R.string.launcher_notification_update_success))
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.geode_monochrome),
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(24.dp)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = modifier.width(IntrinsicSize.Max)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun OutdatedVersionContent(modifier: Modifier = Modifier) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(text = stringResource(id = R.string.launcher_notification_compatibility))
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Warning,
|
||||||
|
contentDescription = null,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
supportingContent = {
|
||||||
|
Text(text = stringResource(id = R.string.launcher_notification_compatibility_description))
|
||||||
|
},
|
||||||
|
modifier = modifier.width(IntrinsicSize.Max)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun UpdateFailedContent(modifier: Modifier = Modifier) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(text = stringResource(id = R.string.launcher_notification_update_failed))
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Warning,
|
||||||
|
contentDescription = null,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = modifier.width(IntrinsicSize.Max)
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,228 @@
|
|||||||
|
package com.geode.launcher.main
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import android.os.CountDownTimer
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import androidx.lifecycle.viewmodel.initializer
|
||||||
|
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||||
|
import com.geode.launcher.updater.ReleaseManager
|
||||||
|
import com.geode.launcher.utils.Constants
|
||||||
|
import com.geode.launcher.utils.GamePackageUtils
|
||||||
|
import com.geode.launcher.utils.LaunchUtils
|
||||||
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.takeWhile
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
private const val COOLDOWN_LENGTH_MS = 3000L
|
||||||
|
|
||||||
|
class LaunchViewModel(private val application: Application): ViewModel() {
|
||||||
|
companion object {
|
||||||
|
val Factory: ViewModelProvider.Factory = viewModelFactory {
|
||||||
|
initializer {
|
||||||
|
val application = this[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY] as Application
|
||||||
|
|
||||||
|
LaunchViewModel(
|
||||||
|
application = application
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var readyTimerPassed = false
|
||||||
|
private var readyTimer: CountDownTimer? = null
|
||||||
|
|
||||||
|
private fun initReadyTimer() {
|
||||||
|
readyTimer = object : CountDownTimer(COOLDOWN_LENGTH_MS, 1000) {
|
||||||
|
override fun onTick(millisUntilFinished: Long) {
|
||||||
|
// no tick necessary
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFinish() {
|
||||||
|
readyTimerPassed = true
|
||||||
|
|
||||||
|
if (_uiState.value is LaunchUIState.Working) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
preReadyCheck()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class LaunchCancelReason {
|
||||||
|
MANUAL, AUTOMATIC, LAST_LAUNCH_CRASHED, GEODE_NOT_FOUND, GAME_MISSING, GAME_OUTDATED;
|
||||||
|
|
||||||
|
fun allowsRetry() = when (this) {
|
||||||
|
MANUAL,
|
||||||
|
AUTOMATIC,
|
||||||
|
LAST_LAUNCH_CRASHED,
|
||||||
|
GEODE_NOT_FOUND -> true
|
||||||
|
GAME_MISSING,
|
||||||
|
GAME_OUTDATED -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isGameInstallIssue() = when (this) {
|
||||||
|
GAME_OUTDATED,
|
||||||
|
GAME_MISSING -> true
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class LaunchUIState {
|
||||||
|
data object Initial : LaunchUIState()
|
||||||
|
data object UpdateCheck : LaunchUIState()
|
||||||
|
data class Updating(val downloaded: Long, val outOf: Long?) : LaunchUIState()
|
||||||
|
data class Cancelled(val reason: LaunchCancelReason, val inProgress: Boolean = false) : LaunchUIState()
|
||||||
|
data object Working : LaunchUIState()
|
||||||
|
data object Ready : LaunchUIState()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val _uiState = MutableStateFlow<LaunchUIState>(LaunchUIState.Initial)
|
||||||
|
val uiState = _uiState.asStateFlow()
|
||||||
|
|
||||||
|
val nextLauncherUpdate = ReleaseManager.get(application).availableLauncherUpdate
|
||||||
|
|
||||||
|
var loadFailure: LoadFailureInfo? = null
|
||||||
|
private var hasCheckedForUpdates = false
|
||||||
|
private var isCancelling = false
|
||||||
|
private var hasManuallyStarted = false
|
||||||
|
|
||||||
|
private suspend fun determineUpdateStatus() {
|
||||||
|
ReleaseManager.get(application).uiState.takeWhile {
|
||||||
|
it is ReleaseManager.ReleaseManagerState.InUpdateCheck || it is ReleaseManager.ReleaseManagerState.InDownload
|
||||||
|
}.map { when (it) {
|
||||||
|
is ReleaseManager.ReleaseManagerState.InUpdateCheck -> LaunchUIState.UpdateCheck
|
||||||
|
is ReleaseManager.ReleaseManagerState.InDownload -> LaunchUIState.Updating(it.downloaded, it.outOf)
|
||||||
|
else -> LaunchUIState.UpdateCheck
|
||||||
|
}
|
||||||
|
}.collect {
|
||||||
|
_uiState.emit(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
// flow terminates once update check is finished
|
||||||
|
hasCheckedForUpdates = true
|
||||||
|
preReadyCheck()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun currentCrashInfo(): LoadFailureInfo? {
|
||||||
|
val currentState = _uiState.value
|
||||||
|
if (currentState is LaunchUIState.Cancelled && currentState.reason == LaunchCancelReason.LAST_LAUNCH_CRASHED) {
|
||||||
|
return loadFailure
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearCrashInfo() {
|
||||||
|
val currentState = _uiState.value
|
||||||
|
if (currentState is LaunchUIState.Cancelled && currentState.reason == LaunchCancelReason.LAST_LAUNCH_CRASHED) {
|
||||||
|
loadFailure = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun preReadyCheck() {
|
||||||
|
if (isCancelling) {
|
||||||
|
// don't let the game start if cancelled
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val packageManager = application.packageManager
|
||||||
|
|
||||||
|
if (!GamePackageUtils.isGameInstalled(packageManager)) {
|
||||||
|
return _uiState.emit(LaunchUIState.Cancelled(LaunchCancelReason.GAME_MISSING))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ReleaseManager.get(application).isInUpdate) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
determineUpdateStatus()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loadFailure != null) {
|
||||||
|
// last launch crashed, so cancel
|
||||||
|
return _uiState.emit(LaunchUIState.Cancelled(LaunchCancelReason.LAST_LAUNCH_CRASHED))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GamePackageUtils.getGameVersionCode(packageManager) < Constants.SUPPORTED_VERSION_CODE_MIN) {
|
||||||
|
return _uiState.emit(LaunchUIState.Cancelled(LaunchCancelReason.GAME_OUTDATED))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!LaunchUtils.isGeodeInstalled(application)) {
|
||||||
|
return _uiState.emit(LaunchUIState.Cancelled(LaunchCancelReason.GEODE_NOT_FOUND))
|
||||||
|
}
|
||||||
|
|
||||||
|
val loadAutomatically = PreferenceUtils.get(application).getBoolean(PreferenceUtils.Key.LOAD_AUTOMATICALLY)
|
||||||
|
if (!loadAutomatically && !hasManuallyStarted) {
|
||||||
|
return cancelLaunch(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!readyTimerPassed && !hasManuallyStarted) {
|
||||||
|
return _uiState.emit(LaunchUIState.Working)
|
||||||
|
}
|
||||||
|
|
||||||
|
_uiState.emit(LaunchUIState.Ready)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun beginLaunchFlow(isRestart: Boolean = false) {
|
||||||
|
if (isRestart) {
|
||||||
|
hasManuallyStarted = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_uiState.value !is LaunchUIState.Initial && _uiState.value !is LaunchUIState.Cancelled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_uiState.value is LaunchUIState.Cancelled && !isRestart) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isCancelling = false
|
||||||
|
|
||||||
|
if (!GamePackageUtils.isGameInstalled(application.packageManager)) {
|
||||||
|
return _uiState.emit(LaunchUIState.Cancelled(LaunchCancelReason.GAME_MISSING))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (readyTimer == null) {
|
||||||
|
initReadyTimer()
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasGeode = LaunchUtils.isGeodeInstalled(application)
|
||||||
|
val shouldUpdate = PreferenceUtils.get(application).getBoolean(PreferenceUtils.Key.UPDATE_AUTOMATICALLY)
|
||||||
|
if ((shouldUpdate && !hasCheckedForUpdates) || !hasGeode) {
|
||||||
|
ReleaseManager.get(application).checkForUpdates(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
preReadyCheck()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun cancelLaunch(isAutomatic: Boolean = false) {
|
||||||
|
// no need to double cancel
|
||||||
|
if (_uiState.value is LaunchUIState.Cancelled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val reason = if (isAutomatic) LaunchCancelReason.AUTOMATIC else LaunchCancelReason.MANUAL
|
||||||
|
|
||||||
|
isCancelling = true
|
||||||
|
_uiState.emit(LaunchUIState.Cancelled(reason, true))
|
||||||
|
|
||||||
|
val releaseManager = ReleaseManager.get(application)
|
||||||
|
if (releaseManager.isInUpdate) {
|
||||||
|
releaseManager.cancelUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
_uiState.emit(LaunchUIState.Cancelled(reason, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
super.onCleared()
|
||||||
|
|
||||||
|
readyTimer?.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,430 @@
|
|||||||
|
package com.geode.launcher.main
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.provider.DocumentsContract
|
||||||
|
import android.text.format.Formatter
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.offset
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Refresh
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.ElevatedCard
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
|
import androidx.compose.material3.OutlinedButton
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalUriHandler
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.geode.launcher.R
|
||||||
|
import com.geode.launcher.UserDirectoryProvider
|
||||||
|
import com.geode.launcher.ui.theme.Typography
|
||||||
|
import com.geode.launcher.updater.ReleaseManager
|
||||||
|
import com.geode.launcher.updater.ReleaseViewModel
|
||||||
|
import com.geode.launcher.utils.LaunchUtils
|
||||||
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
|
import com.mikepenz.markdown.compose.LocalBulletListHandler
|
||||||
|
import com.mikepenz.markdown.m3.Markdown
|
||||||
|
import com.mikepenz.markdown.m3.markdownTypography
|
||||||
|
import kotlinx.datetime.toJavaInstant
|
||||||
|
import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor
|
||||||
|
import java.io.File
|
||||||
|
import java.net.ConnectException
|
||||||
|
import java.net.UnknownHostException
|
||||||
|
import java.text.DateFormat
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
fun clearDownloadedApks(context: Context) {
|
||||||
|
// technically we should be using the activity results but it was too inconsistent for my liking
|
||||||
|
val preferenceUtils = PreferenceUtils.get(context)
|
||||||
|
val performCleanup = preferenceUtils.getBoolean(PreferenceUtils.Key.CLEANUP_APKS)
|
||||||
|
if (!performCleanup) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val baseDirectory = LaunchUtils.getBaseDirectory(context)
|
||||||
|
|
||||||
|
baseDirectory.listFiles {
|
||||||
|
// only select apk files
|
||||||
|
_, name -> name.lowercase().endsWith(".apk")
|
||||||
|
}?.forEach {
|
||||||
|
it.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
preferenceUtils.setBoolean(PreferenceUtils.Key.CLEANUP_APKS, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun generateInstallIntent(uri: Uri): Intent {
|
||||||
|
// maybe one day i'll rewrite this to use packageinstaller. not today
|
||||||
|
return Intent(Intent.ACTION_INSTALL_PACKAGE).apply {
|
||||||
|
setDataAndType(uri, "application/vnd.android.package-archive")
|
||||||
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun installLauncherUpdate(context: Context) {
|
||||||
|
val nextUpdate = ReleaseManager.get(context).availableLauncherUpdate.value
|
||||||
|
val launcherDownload = nextUpdate?.getDownload()
|
||||||
|
|
||||||
|
if (launcherDownload != null) {
|
||||||
|
val outputFile = launcherDownload.filename
|
||||||
|
val baseDirectory = LaunchUtils.getBaseDirectory(context)
|
||||||
|
|
||||||
|
val outputPathFile = File(baseDirectory, outputFile)
|
||||||
|
if (!outputPathFile.exists()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val outputPath = "${UserDirectoryProvider.ROOT}${outputFile}"
|
||||||
|
|
||||||
|
val uri = DocumentsContract.buildDocumentUri("${context.packageName}.user", outputPath)
|
||||||
|
|
||||||
|
PreferenceUtils.get(context).setBoolean(PreferenceUtils.Key.CLEANUP_APKS, true)
|
||||||
|
|
||||||
|
try {
|
||||||
|
val intent = generateInstallIntent(uri)
|
||||||
|
context.startActivity(intent)
|
||||||
|
} catch (_: ActivityNotFoundException) {
|
||||||
|
// if it fails to install, just open it in the browser
|
||||||
|
try {
|
||||||
|
val downloadUrl = launcherDownload.url
|
||||||
|
val downloadIntent = Intent(Intent.ACTION_VIEW).apply {
|
||||||
|
data = Uri.parse(downloadUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.startActivity(downloadIntent)
|
||||||
|
} catch (_: ActivityNotFoundException) {
|
||||||
|
Toast.makeText(context, context.getString(R.string.no_activity_found), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, context.getString(R.string.release_fetch_no_releases), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun LauncherUpdateInformation(onDismiss: () -> Unit) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val nextRelease = remember { ReleaseManager.get(context).availableLauncherUpdate.value }
|
||||||
|
val sheetState = rememberModalBottomSheetState()
|
||||||
|
|
||||||
|
if (nextRelease != null) {
|
||||||
|
ModalBottomSheet(onDismissRequest = { onDismiss() }, sheetState = sheetState) {
|
||||||
|
Box(Modifier.verticalScroll(rememberScrollState())) {
|
||||||
|
Column(modifier = Modifier.padding(horizontal = 24.dp)) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.launcher_update_name, nextRelease.release.tagName),
|
||||||
|
style = Typography.headlineSmall,
|
||||||
|
)
|
||||||
|
|
||||||
|
val releasedTime = remember {
|
||||||
|
DateFormat.getDateInstance().format(
|
||||||
|
Date.from(nextRelease.release.publishedAt.toJavaInstant())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.launcher_update_released, "$releasedTime"),
|
||||||
|
style = Typography.labelLarge
|
||||||
|
)
|
||||||
|
|
||||||
|
Row(modifier = Modifier.padding(vertical = 12.dp)) {
|
||||||
|
Button(
|
||||||
|
onClick = { installLauncherUpdate(context) },
|
||||||
|
) {
|
||||||
|
Icon(painterResource(R.drawable.icon_download), contentDescription = null)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(stringResource(R.string.launcher_install))
|
||||||
|
}
|
||||||
|
|
||||||
|
val uriHandler = LocalUriHandler.current
|
||||||
|
|
||||||
|
IconButton(onClick = { uriHandler.openUri(nextRelease.release.htmlUrl) }) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.icon_link),
|
||||||
|
stringResource(R.string.launcher_update_external_link)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextRelease.release.body != null) {
|
||||||
|
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.launcher_update_changelog),
|
||||||
|
style = Typography.titleLarge
|
||||||
|
)
|
||||||
|
|
||||||
|
// every new release of the markdown library adds another arg to it
|
||||||
|
CompositionLocalProvider(LocalBulletListHandler provides { _, _, _, _, _ -> "• " }) {
|
||||||
|
Markdown(
|
||||||
|
content = nextRelease.release.body.replace("\r", ""),
|
||||||
|
typography = markdownTypography(
|
||||||
|
link = MaterialTheme.typography.bodyLarge.copy(
|
||||||
|
textDecoration = TextDecoration.Underline,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
flavour = GFMFlavourDescriptor(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.size(4.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LauncherUpdateIndicator(modifier: Modifier = Modifier) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
var showInfoDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (showInfoDialog) {
|
||||||
|
LauncherUpdateInformation {
|
||||||
|
showInfoDialog = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ElevatedCard(modifier) {
|
||||||
|
Column(
|
||||||
|
// buttons add enough padding already, lower to compensate
|
||||||
|
modifier = Modifier.padding(
|
||||||
|
top = 20.dp,
|
||||||
|
start = 12.dp,
|
||||||
|
end = 12.dp,
|
||||||
|
bottom = 8.dp
|
||||||
|
),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.launcher_update_available),
|
||||||
|
modifier = Modifier.padding(horizontal = 10.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
Row(modifier = Modifier.align(Alignment.End)) {
|
||||||
|
TextButton(
|
||||||
|
onClick = { showInfoDialog = true },
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.launcher_update_view))
|
||||||
|
}
|
||||||
|
|
||||||
|
TextButton(
|
||||||
|
onClick = { installLauncherUpdate(context) },
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.launcher_install))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun UpdateProgressIndicator(
|
||||||
|
message: String,
|
||||||
|
releaseViewModel: ReleaseViewModel,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
progress: (() -> Float)? = null
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
horizontalAlignment = Alignment.Start,
|
||||||
|
modifier = modifier
|
||||||
|
) {
|
||||||
|
Text(message, style = MaterialTheme.typography.labelMedium)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.padding(4.dp))
|
||||||
|
|
||||||
|
if (progress == null) {
|
||||||
|
LinearProgressIndicator()
|
||||||
|
} else {
|
||||||
|
LinearProgressIndicator(progress = progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
releaseViewModel.cancelUpdate()
|
||||||
|
},
|
||||||
|
modifier = Modifier.offset((-12).dp)
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.release_fetch_button_cancel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun UpdateMessageIndicator(
|
||||||
|
message: String,
|
||||||
|
releaseViewModel: ReleaseViewModel,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
allowRetry: Boolean = false
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
modifier = modifier
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
message,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.padding(4.dp))
|
||||||
|
|
||||||
|
if (allowRetry) {
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = {
|
||||||
|
releaseViewModel.runReleaseCheck(true)
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Refresh,
|
||||||
|
contentDescription = stringResource(R.string.launcher_retry_icon_alt)
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text(stringResource(R.string.release_fetch_button_retry))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun UpdateCard(releaseViewModel: ReleaseViewModel, modifier: Modifier = Modifier) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val releaseState by releaseViewModel.uiState.collectAsState()
|
||||||
|
|
||||||
|
when (val state = releaseState) {
|
||||||
|
is ReleaseViewModel.ReleaseUIState.Failure -> {
|
||||||
|
val message = when (state.exception) {
|
||||||
|
is UnknownHostException, is ConnectException ->
|
||||||
|
stringResource(R.string.release_fetch_no_internet)
|
||||||
|
is ReleaseManager.UpdateException -> {
|
||||||
|
when (state.exception.reason) {
|
||||||
|
ReleaseManager.UpdateException.Reason.EXTERNAL_FILE_IN_USE -> stringResource(
|
||||||
|
R.string.release_fetch_manual_check_required
|
||||||
|
)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateMessageIndicator(
|
||||||
|
stringResource(
|
||||||
|
R.string.release_fetch_failed,
|
||||||
|
message ?: stringResource(R.string.release_fetch_try_later)
|
||||||
|
),
|
||||||
|
modifier = modifier,
|
||||||
|
allowRetry = true,
|
||||||
|
releaseViewModel = releaseViewModel
|
||||||
|
)
|
||||||
|
}
|
||||||
|
is ReleaseViewModel.ReleaseUIState.InDownload -> {
|
||||||
|
val downloaded = remember(state.downloaded) {
|
||||||
|
Formatter.formatShortFileSize(context, state.downloaded)
|
||||||
|
}
|
||||||
|
|
||||||
|
val outOf = remember(state.outOf) {
|
||||||
|
state.outOf?.run {
|
||||||
|
Formatter.formatShortFileSize(context, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateProgressIndicator(
|
||||||
|
if (outOf != null) stringResource(
|
||||||
|
R.string.release_fetch_downloading,
|
||||||
|
downloaded,
|
||||||
|
outOf
|
||||||
|
) else stringResource(
|
||||||
|
R.string.release_fetch_downloading_indeterminate,
|
||||||
|
downloaded,
|
||||||
|
),
|
||||||
|
modifier = modifier,
|
||||||
|
releaseViewModel = releaseViewModel,
|
||||||
|
progress = {
|
||||||
|
val progress = state.downloaded / state.outOf!!.toDouble()
|
||||||
|
progress.toFloat()
|
||||||
|
}.takeIf { state.outOf != null }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
is ReleaseViewModel.ReleaseUIState.InUpdateCheck -> {
|
||||||
|
UpdateProgressIndicator(
|
||||||
|
stringResource(R.string.release_fetch_in_progress),
|
||||||
|
modifier = modifier,
|
||||||
|
releaseViewModel = releaseViewModel
|
||||||
|
)
|
||||||
|
}
|
||||||
|
is ReleaseViewModel.ReleaseUIState.Finished -> {
|
||||||
|
if (state.hasUpdated) {
|
||||||
|
UpdateMessageIndicator(
|
||||||
|
stringResource(R.string.release_fetch_success),
|
||||||
|
modifier = modifier,
|
||||||
|
releaseViewModel = releaseViewModel
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is ReleaseViewModel.ReleaseUIState.Cancelled -> {
|
||||||
|
if (state.isCancelling) {
|
||||||
|
UpdateProgressIndicator(
|
||||||
|
stringResource(R.string.release_fetch_cancelling),
|
||||||
|
modifier = modifier,
|
||||||
|
releaseViewModel = releaseViewModel
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
UpdateMessageIndicator(
|
||||||
|
stringResource(R.string.release_fetch_cancelled),
|
||||||
|
modifier = modifier,
|
||||||
|
allowRetry = true,
|
||||||
|
releaseViewModel = releaseViewModel
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val nextUpdate by releaseViewModel.nextLauncherUpdate.collectAsState()
|
||||||
|
|
||||||
|
if (!releaseViewModel.isInUpdate && nextUpdate != null) {
|
||||||
|
LauncherUpdateIndicator(
|
||||||
|
modifier = modifier
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
-11
@@ -1,10 +1,6 @@
|
|||||||
package com.geode.launcher
|
package com.geode.launcher.preferences
|
||||||
|
|
||||||
import android.content.ClipData
|
|
||||||
import android.content.ClipboardManager
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
@@ -66,6 +62,7 @@ import androidx.compose.ui.text.style.TextOverflow
|
|||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import com.geode.launcher.R
|
||||||
import com.geode.launcher.log.LogLine
|
import com.geode.launcher.log.LogLine
|
||||||
import com.geode.launcher.log.LogPriority
|
import com.geode.launcher.log.LogPriority
|
||||||
import com.geode.launcher.log.LogViewModel
|
import com.geode.launcher.log.LogViewModel
|
||||||
@@ -138,12 +135,14 @@ fun SelectLogLevelDialog(
|
|||||||
onDismissRequest = onDismissRequest,
|
onDismissRequest = onDismissRequest,
|
||||||
onSelect = { onSelect(it) },
|
onSelect = { onSelect(it) },
|
||||||
initialValue = initialValue,
|
initialValue = initialValue,
|
||||||
toLabel = {
|
) {
|
||||||
// i'm lazy
|
(LogPriority.VERBOSE..LogPriority.FATAL).reversed().forEach {
|
||||||
it.name.lowercase().replaceFirstChar { c -> c.uppercaseChar() }
|
SelectOption(
|
||||||
},
|
name = it.name.lowercase().replaceFirstChar { c -> c.uppercaseChar() },
|
||||||
optionsCount = LogPriority.FATAL downTo LogPriority.VERBOSE
|
value = it
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
package com.geode.launcher.preferences
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.activity.OnBackPressedDispatcher
|
||||||
|
import androidx.activity.compose.setContent
|
||||||
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.Info
|
||||||
|
import androidx.compose.material3.ElevatedCard
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.geode.launcher.R
|
||||||
|
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
||||||
|
import com.geode.launcher.ui.theme.LocalTheme
|
||||||
|
import com.geode.launcher.ui.theme.Theme
|
||||||
|
import com.geode.launcher.utils.LabelledText
|
||||||
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
|
|
||||||
|
class DeveloperSettingsActivity : ComponentActivity() {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
enableEdgeToEdge()
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContent {
|
||||||
|
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
|
||||||
|
val theme = Theme.fromInt(themeOption)
|
||||||
|
|
||||||
|
val backgroundOption by PreferenceUtils.useBooleanPreference(PreferenceUtils.Key.BLACK_BACKGROUND)
|
||||||
|
|
||||||
|
CompositionLocalProvider(LocalTheme provides theme) {
|
||||||
|
GeodeLauncherTheme(theme = theme, blackBackground = backgroundOption) {
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
color = MaterialTheme.colorScheme.background
|
||||||
|
) {
|
||||||
|
DeveloperSettingsScreen(onBackPressedDispatcher)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun DeveloperSettingsScreen(onBackPressedDispatcher: OnBackPressedDispatcher?) {
|
||||||
|
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||||
|
|
||||||
|
Scaffold(
|
||||||
|
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||||
|
topBar = {
|
||||||
|
Column {
|
||||||
|
TopAppBar(
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { onBackPressedDispatcher?.onBackPressed() }) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
|
contentDescription = stringResource(R.string.back_icon_alt)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.title_activity_developer_settings),
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
|
)
|
||||||
|
},
|
||||||
|
scrollBehavior = scrollBehavior,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) { innerPadding ->
|
||||||
|
Column(
|
||||||
|
Modifier
|
||||||
|
.padding(innerPadding)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.verticalScroll(rememberScrollState()),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
|
||||||
|
val developerMode by PreferenceUtils.useBooleanPreference(PreferenceUtils.Key.DEVELOPER_MODE)
|
||||||
|
|
||||||
|
SettingsCard(
|
||||||
|
title = stringResource(R.string.preference_developer_mode),
|
||||||
|
preferenceKey = PreferenceUtils.Key.DEVELOPER_MODE,
|
||||||
|
)
|
||||||
|
|
||||||
|
InlineText(
|
||||||
|
stringResource(R.string.preference_developer_mode_about)
|
||||||
|
)
|
||||||
|
|
||||||
|
HorizontalDivider()
|
||||||
|
|
||||||
|
if (developerMode) {
|
||||||
|
OptionsGroup(title = stringResource(R.string.preference_category_gameplay)) {
|
||||||
|
SettingsStringCard(
|
||||||
|
title = stringResource(R.string.preference_launch_arguments_name),
|
||||||
|
dialogTitle = stringResource(R.string.preference_launch_arguments_set_title),
|
||||||
|
preferenceKey = PreferenceUtils.Key.LAUNCH_ARGUMENTS,
|
||||||
|
filterInput = { it.filter { c ->
|
||||||
|
// if only there was a better way to define this!
|
||||||
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*(){}<>[]?:;'\"~`-_+=\\| ".contains(c)
|
||||||
|
}}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
SettingsCard(
|
||||||
|
title = stringResource(R.string.preference_force_hrr),
|
||||||
|
preferenceKey = PreferenceUtils.Key.FORCE_HRR,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
SettingsCard(
|
||||||
|
title = stringResource(R.string.preference_override_exceptions_name),
|
||||||
|
description = stringResource(R.string.preference_override_exceptions_description),
|
||||||
|
preferenceKey = PreferenceUtils.Key.CUSTOM_SYMBOL_LIST
|
||||||
|
)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsGroup(title = stringResource(R.string.preference_category_updater)) {
|
||||||
|
SettingsCard(
|
||||||
|
title = stringResource(R.string.preference_use_index_update_api),
|
||||||
|
preferenceKey = PreferenceUtils.Key.USE_INDEX_API
|
||||||
|
)
|
||||||
|
|
||||||
|
SettingsSelectCard(
|
||||||
|
title = stringResource(R.string.preference_release_channel_tag_name),
|
||||||
|
dialogTitle = stringResource(R.string.preference_release_channel_select),
|
||||||
|
preferenceKey = PreferenceUtils.Key.RELEASE_CHANNEL_TAG,
|
||||||
|
options = linkedMapOf(
|
||||||
|
0 to stringResource(R.string.preference_release_channel_stable),
|
||||||
|
1 to stringResource(R.string.preference_release_channel_beta),
|
||||||
|
2 to stringResource(R.string.preference_release_channel_nightly),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
ElevatedCard(modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp)) {
|
||||||
|
LabelledText(
|
||||||
|
label = stringResource(R.string.preference_developer_update_notice),
|
||||||
|
icon = {
|
||||||
|
Icon(Icons.Filled.Info, null)
|
||||||
|
},
|
||||||
|
modifier = Modifier.padding(8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsGroup(title = stringResource(R.string.preference_category_testing)) {
|
||||||
|
SettingsCard(
|
||||||
|
title = stringResource(R.string.preference_enable_redesign),
|
||||||
|
preferenceKey = PreferenceUtils.Key.ENABLE_REDESIGN,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsGroup(title = stringResource(R.string.preference_profiles)) {
|
||||||
|
ProfileCreateCard()
|
||||||
|
ProfileSelectCard()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+185
-57
@@ -1,4 +1,4 @@
|
|||||||
package com.geode.launcher
|
package com.geode.launcher.preferences
|
||||||
|
|
||||||
import android.app.UiModeManager
|
import android.app.UiModeManager
|
||||||
import android.content.ActivityNotFoundException
|
import android.content.ActivityNotFoundException
|
||||||
@@ -9,6 +9,7 @@ import android.content.Intent
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
|
import android.view.WindowManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.OnBackPressedDispatcher
|
import androidx.activity.OnBackPressedDispatcher
|
||||||
@@ -35,22 +36,30 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.semantics.Role
|
import androidx.compose.ui.semantics.Role
|
||||||
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import com.geode.launcher.BuildConfig
|
||||||
|
import com.geode.launcher.R
|
||||||
|
import com.geode.launcher.UserDirectoryProvider
|
||||||
import com.geode.launcher.updater.ReleaseViewModel
|
import com.geode.launcher.updater.ReleaseViewModel
|
||||||
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
||||||
import com.geode.launcher.ui.theme.LocalTheme
|
import com.geode.launcher.ui.theme.LocalTheme
|
||||||
import com.geode.launcher.ui.theme.Theme
|
import com.geode.launcher.ui.theme.Theme
|
||||||
import com.geode.launcher.ui.theme.Typography
|
import com.geode.launcher.utils.Constants
|
||||||
|
import com.geode.launcher.utils.GamePackageUtils
|
||||||
import com.geode.launcher.utils.LaunchUtils
|
import com.geode.launcher.utils.LaunchUtils
|
||||||
import com.geode.launcher.utils.PreferenceUtils
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
import java.net.ConnectException
|
import java.net.ConnectException
|
||||||
import java.net.UnknownHostException
|
import java.net.UnknownHostException
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
class SettingsActivity : ComponentActivity() {
|
class SettingsActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@@ -143,11 +152,16 @@ fun UpdateIndicator(
|
|||||||
is ReleaseViewModel.ReleaseUIState.InDownload -> {
|
is ReleaseViewModel.ReleaseUIState.InDownload -> {
|
||||||
// is this the ideal design? idk
|
// is this the ideal design? idk
|
||||||
enablePopup = true
|
enablePopup = true
|
||||||
val progress = updateStatus.downloaded / updateStatus.outOf.toDouble()
|
if (updateStatus.outOf != null) {
|
||||||
|
CircularProgressIndicator(
|
||||||
CircularProgressIndicator(
|
progress = {
|
||||||
progress = { progress.toFloat() },
|
val progress = updateStatus.downloaded / updateStatus.outOf.toDouble()
|
||||||
)
|
progress.toFloat()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
@@ -174,9 +188,16 @@ fun UpdateIndicator(
|
|||||||
context.getString(R.string.preference_check_for_updates_success)
|
context.getString(R.string.preference_check_for_updates_success)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
snackbarHostState.showSnackbar(
|
val gameVersion = GamePackageUtils.getGameVersionCodeOrNull(context.packageManager)
|
||||||
context.getString(R.string.preference_check_for_updates_none_found)
|
if (gameVersion != null && gameVersion < Constants.SUPPORTED_VERSION_CODE) {
|
||||||
)
|
snackbarHostState.showSnackbar(
|
||||||
|
context.getString(R.string.launcher_game_update_required_short)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
snackbarHostState.showSnackbar(
|
||||||
|
context.getString(R.string.preference_check_for_updates_none_found)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {}
|
else -> {}
|
||||||
@@ -184,24 +205,6 @@ fun UpdateIndicator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun themeToKey(theme: Int): String {
|
|
||||||
return when (theme) {
|
|
||||||
1 -> stringResource(R.string.preference_theme_light)
|
|
||||||
2 -> stringResource(R.string.preference_theme_dark)
|
|
||||||
else -> stringResource(R.string.preference_theme_default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun displayOptionToKey(option: Int): String {
|
|
||||||
return when (option) {
|
|
||||||
1 -> stringResource(R.string.preference_display_mode_legacy)
|
|
||||||
2 -> stringResource(R.string.preference_display_mode_fullscreen)
|
|
||||||
else -> stringResource(R.string.preference_display_mode_default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateTheme(context: Context, theme: Int) {
|
fun updateTheme(context: Context, theme: Int) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
|
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
|
||||||
@@ -228,6 +231,11 @@ fun onOpenLogs(context: Context) {
|
|||||||
context.startActivity(launchIntent)
|
context.startActivity(launchIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onOpenDeveloperOptions(context: Context) {
|
||||||
|
val launchIntent = Intent(context, DeveloperSettingsActivity::class.java)
|
||||||
|
context.startActivity(launchIntent)
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsScreen(
|
fun SettingsScreen(
|
||||||
@@ -297,15 +305,25 @@ fun SettingsScreen(
|
|||||||
SettingsSelectCard(
|
SettingsSelectCard(
|
||||||
title = stringResource(R.string.preference_theme_name),
|
title = stringResource(R.string.preference_theme_name),
|
||||||
dialogTitle = stringResource(R.string.preference_theme_select),
|
dialogTitle = stringResource(R.string.preference_theme_select),
|
||||||
maxVal = 2,
|
|
||||||
preferenceKey = PreferenceUtils.Key.THEME,
|
preferenceKey = PreferenceUtils.Key.THEME,
|
||||||
toLabel = { themeToKey(it) },
|
options = linkedMapOf(
|
||||||
|
0 to stringResource(R.string.preference_theme_default),
|
||||||
|
1 to stringResource(R.string.preference_theme_light),
|
||||||
|
2 to stringResource(R.string.preference_theme_dark),
|
||||||
|
),
|
||||||
extraSelectBehavior = { updateTheme(context, it) }
|
extraSelectBehavior = { updateTheme(context, it) }
|
||||||
)
|
)
|
||||||
SettingsCard(
|
SettingsCard(
|
||||||
title = stringResource(R.string.preference_black_background_name),
|
title = stringResource(R.string.preference_black_background_name),
|
||||||
preferenceKey = PreferenceUtils.Key.BLACK_BACKGROUND
|
preferenceKey = PreferenceUtils.Key.BLACK_BACKGROUND
|
||||||
)
|
)
|
||||||
|
OptionsButton(
|
||||||
|
title = stringResource(R.string.preferences_open_file_manager),
|
||||||
|
onClick = { onOpenFileManager(context) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsGroup(stringResource(R.string.preference_category_gameplay)) {
|
||||||
SettingsCard(
|
SettingsCard(
|
||||||
title = context.getString(R.string.preference_load_automatically_name),
|
title = context.getString(R.string.preference_load_automatically_name),
|
||||||
description = context.getString(R.string.preference_load_automatically_description),
|
description = context.getString(R.string.preference_load_automatically_description),
|
||||||
@@ -314,14 +332,65 @@ fun SettingsScreen(
|
|||||||
SettingsSelectCard(
|
SettingsSelectCard(
|
||||||
title = stringResource(R.string.preference_display_mode_name),
|
title = stringResource(R.string.preference_display_mode_name),
|
||||||
dialogTitle = stringResource(R.string.preference_display_mode_select),
|
dialogTitle = stringResource(R.string.preference_display_mode_select),
|
||||||
// necessary api doesn't exist on older versions of android
|
|
||||||
maxVal = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) 2 else 1,
|
|
||||||
preferenceKey = PreferenceUtils.Key.DISPLAY_MODE,
|
preferenceKey = PreferenceUtils.Key.DISPLAY_MODE,
|
||||||
toLabel = { displayOptionToKey(it) }
|
options = buildMap {
|
||||||
|
put(0, stringResource(R.string.preference_display_mode_default))
|
||||||
|
put(1, stringResource(R.string.preference_display_mode_legacy))
|
||||||
|
|
||||||
|
// necessary api doesn't exist on older versions of android
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
put(2, stringResource(R.string.preference_display_mode_fullscreen))
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
OptionsButton(
|
val currentDisplayMode by PreferenceUtils.useIntPreference(PreferenceUtils.Key.DISPLAY_MODE)
|
||||||
title = stringResource(R.string.preferences_open_file_manager),
|
|
||||||
onClick = { onOpenFileManager(context) }
|
if (currentDisplayMode == 1) {
|
||||||
|
SettingsStringSelectCard(
|
||||||
|
title = stringResource(R.string.preference_custom_aspect_ratio_name),
|
||||||
|
description = stringResource(R.string.preference_custom_aspect_ratio_description),
|
||||||
|
dialogTitle = stringResource(R.string.preference_custom_aspect_ratio_select),
|
||||||
|
preferenceKey = PreferenceUtils.Key.CUSTOM_ASPECT_RATIO,
|
||||||
|
options = linkedMapOf(
|
||||||
|
"16_9" to stringResource(R.string.preference_custom_aspect_ratio_16x9),
|
||||||
|
"16_10" to stringResource(R.string.preference_custom_aspect_ratio_16x10),
|
||||||
|
"4_3" to stringResource(R.string.preference_custom_aspect_ratio_4x3),
|
||||||
|
"1_1" to stringResource(R.string.preference_custom_aspect_ratio_1x1),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsRangeCard(
|
||||||
|
title = stringResource(R.string.preference_screen_zoom_name),
|
||||||
|
description = stringResource(R.string.preference_screen_zoom_description),
|
||||||
|
dialogTitle = stringResource(R.string.preference_screen_zoom_select),
|
||||||
|
preferenceKey = PreferenceUtils.Key.SCREEN_ZOOM,
|
||||||
|
labelSuffix = "x",
|
||||||
|
range = 25..100,
|
||||||
|
scale = 100,
|
||||||
|
step = 5,
|
||||||
|
) {
|
||||||
|
SettingsCard(
|
||||||
|
title = context.getString(R.string.preference_screen_zoom_fit_name),
|
||||||
|
preferenceKey = PreferenceUtils.Key.SCREEN_ZOOM_FIT,
|
||||||
|
asCard = false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val maxFrameRate = remember {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
context.display.supportedModes.maxOf { it.refreshRate }
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.refreshRate
|
||||||
|
}.roundToInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsFPSCard(
|
||||||
|
title = stringResource(R.string.preference_limit_framerate_name),
|
||||||
|
dialogTitle = stringResource(R.string.preference_limit_framerate_select),
|
||||||
|
preferenceKey = PreferenceUtils.Key.LIMIT_FRAME_RATE,
|
||||||
|
maxFrameRate = maxFrameRate
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,10 +399,6 @@ fun SettingsScreen(
|
|||||||
title = context.getString(R.string.preference_update_automatically_name),
|
title = context.getString(R.string.preference_update_automatically_name),
|
||||||
preferenceKey = PreferenceUtils.Key.UPDATE_AUTOMATICALLY,
|
preferenceKey = PreferenceUtils.Key.UPDATE_AUTOMATICALLY,
|
||||||
)
|
)
|
||||||
SettingsCard(
|
|
||||||
title = context.getString(R.string.preference_release_channel_name),
|
|
||||||
preferenceKey = PreferenceUtils.Key.RELEASE_CHANNEL,
|
|
||||||
)
|
|
||||||
OptionsCard(
|
OptionsCard(
|
||||||
title = {
|
title = {
|
||||||
OptionsTitle(
|
OptionsTitle(
|
||||||
@@ -361,31 +426,94 @@ fun SettingsScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
OptionsGroup(stringResource(R.string.preference_category_developer)) {
|
OptionsGroup(stringResource(R.string.preference_category_developer)) {
|
||||||
SettingsStringCard(
|
OptionsButton(
|
||||||
title = stringResource(R.string.preference_launch_arguments_name),
|
title = stringResource(R.string.preferences_view_logs),
|
||||||
dialogTitle = stringResource(R.string.preference_launch_arguments_set_title),
|
icon = {
|
||||||
preferenceKey = PreferenceUtils.Key.LAUNCH_ARGUMENTS,
|
Icon(painterResource(R.drawable.icon_description), contentDescription = null)
|
||||||
filterInput = { it.filter { c ->
|
},
|
||||||
// if only there was a better way to define this!
|
onClick = { onOpenLogs(context) }
|
||||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*(){}<>[]?:;'\"~`-_+=\\| ".contains(c)
|
)
|
||||||
}}
|
OptionsButton(
|
||||||
|
title = stringResource(R.string.preference_open_developer_options),
|
||||||
|
icon = {
|
||||||
|
Icon(painterResource(R.drawable.icon_data_object), contentDescription = null)
|
||||||
|
},
|
||||||
|
onClick = { onOpenDeveloperOptions(context) }
|
||||||
)
|
)
|
||||||
OptionsButton(
|
OptionsButton(
|
||||||
title = context.getString(R.string.preferences_copy_external_button),
|
title = context.getString(R.string.preferences_copy_external_button),
|
||||||
description = LaunchUtils.getBaseDirectory(context).path,
|
description = LaunchUtils.getBaseDirectory(context).path,
|
||||||
onClick = { onOpenFolder(context) }
|
onClick = { onOpenFolder(context) }
|
||||||
)
|
)
|
||||||
OptionsButton(
|
|
||||||
title = stringResource(R.string.preferences_view_logs),
|
|
||||||
onClick = { onOpenLogs(context) }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(
|
OptionsGroup(stringResource(R.string.preference_category_about)) {
|
||||||
stringResource(R.string.preference_launcher_version, BuildConfig.VERSION_NAME),
|
val clipboard = LocalClipboardManager.current
|
||||||
style = Typography.labelSmall,
|
|
||||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp)
|
OptionsButton(
|
||||||
)
|
stringResource(R.string.preference_launcher_version_name),
|
||||||
|
stringResource(R.string.preference_launcher_version_description, BuildConfig.VERSION_NAME),
|
||||||
|
displayInline = true
|
||||||
|
) {
|
||||||
|
clipboard.setText(AnnotatedString(context.getString(
|
||||||
|
R.string.preference_launcher_version,
|
||||||
|
BuildConfig.VERSION_NAME
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsButton(
|
||||||
|
stringResource(R.string.preference_loader_version_name),
|
||||||
|
stringResource(R.string.preference_loader_version_description, currentRelease ?: "unknown"),
|
||||||
|
displayInline = true
|
||||||
|
) {
|
||||||
|
clipboard.setText(AnnotatedString(context.getString(
|
||||||
|
R.string.preference_loader_version,
|
||||||
|
currentRelease ?: "unknown"
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
val gameInstalled = remember {
|
||||||
|
GamePackageUtils.isGameInstalled(context.packageManager)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gameInstalled) {
|
||||||
|
val gameVersion = remember {
|
||||||
|
GamePackageUtils.getUnifiedVersionName(context.packageManager)
|
||||||
|
}
|
||||||
|
|
||||||
|
val gameSource = remember {
|
||||||
|
context.getString(when (GamePackageUtils.identifyGameSource(context.packageManager)) {
|
||||||
|
GamePackageUtils.GameSource.GOOGLE -> R.string.preference_game_source_google
|
||||||
|
GamePackageUtils.GameSource.AMAZON -> R.string.preference_game_source_amazon
|
||||||
|
else -> R.string.preference_game_source_unknown
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsButton(
|
||||||
|
stringResource(R.string.preference_game_version_name),
|
||||||
|
stringResource(R.string.preference_game_version_description, gameVersion, gameSource),
|
||||||
|
displayInline = true
|
||||||
|
) {
|
||||||
|
clipboard.setText(AnnotatedString(context.getString(
|
||||||
|
R.string.preference_game_version,
|
||||||
|
gameVersion,
|
||||||
|
gameSource
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsButton(
|
||||||
|
stringResource(R.string.preference_architecture_name),
|
||||||
|
stringResource(R.string.preference_architecture_description, Build.MODEL, LaunchUtils.applicationArchitecture),
|
||||||
|
displayInline = true
|
||||||
|
) {
|
||||||
|
clipboard.setText(AnnotatedString(context.getString(
|
||||||
|
R.string.preference_architecture,
|
||||||
|
Build.MODEL,
|
||||||
|
LaunchUtils.applicationArchitecture
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,974 @@
|
|||||||
|
package com.geode.launcher.preferences
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.activity.compose.LocalActivity
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.defaultMinSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.selection.toggleable
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Add
|
||||||
|
import androidx.compose.material.icons.filled.Clear
|
||||||
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.RadioButton
|
||||||
|
import androidx.compose.material3.Slider
|
||||||
|
import androidx.compose.material3.Switch
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.compositionLocalOf
|
||||||
|
import androidx.compose.runtime.mutableFloatStateOf
|
||||||
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.runtime.staticCompositionLocalOf
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.semantics.Role
|
||||||
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.window.Dialog
|
||||||
|
import com.geode.launcher.R
|
||||||
|
import com.geode.launcher.ui.theme.GeodeLauncherTheme
|
||||||
|
import com.geode.launcher.ui.theme.Typography
|
||||||
|
import com.geode.launcher.utils.LabelledText
|
||||||
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
|
import com.geode.launcher.utils.Profile
|
||||||
|
import com.geode.launcher.utils.ProfileManager
|
||||||
|
import kotlin.math.log10
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
|
|
||||||
|
fun toggleSetting(context: Context, preferenceKey: PreferenceUtils.Key): Boolean {
|
||||||
|
val preferences = PreferenceUtils.get(context)
|
||||||
|
|
||||||
|
return preferences.toggleBoolean(preferenceKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSetting(context: Context, preferenceKey: PreferenceUtils.Key): Boolean {
|
||||||
|
val preferences = PreferenceUtils.get(context)
|
||||||
|
|
||||||
|
return preferences.getBoolean(preferenceKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun OptionsGroup(title: String, content: @Composable () -> Unit) {
|
||||||
|
Column {
|
||||||
|
Text(
|
||||||
|
title,
|
||||||
|
style = Typography.titleMedium,
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SettingsSelectCard(
|
||||||
|
title: String,
|
||||||
|
dialogTitle: String,
|
||||||
|
preferenceKey: PreferenceUtils.Key,
|
||||||
|
options: Map<Int, String>,
|
||||||
|
extraSelectBehavior: ((Int) -> Unit)? = null
|
||||||
|
) {
|
||||||
|
val preferenceValue by PreferenceUtils.useIntPreference(preferenceKey)
|
||||||
|
|
||||||
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
OptionsCard(
|
||||||
|
title = { OptionsTitle(title = title) },
|
||||||
|
modifier = Modifier
|
||||||
|
.clickable(
|
||||||
|
onClick = {
|
||||||
|
showDialog = true
|
||||||
|
},
|
||||||
|
role = Role.Button
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Text(options[preferenceValue] ?: preferenceValue.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showDialog) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
SelectDialog(
|
||||||
|
title = dialogTitle,
|
||||||
|
onDismissRequest = {
|
||||||
|
showDialog = false
|
||||||
|
},
|
||||||
|
onSelect = { selected ->
|
||||||
|
showDialog = false
|
||||||
|
PreferenceUtils.get(context)
|
||||||
|
.setInt(preferenceKey, selected)
|
||||||
|
extraSelectBehavior?.invoke(selected)
|
||||||
|
},
|
||||||
|
initialValue = preferenceValue,
|
||||||
|
) {
|
||||||
|
options.forEach { (k, v) ->
|
||||||
|
SelectOption(name = v, value = k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SettingsStringSelectCard(
|
||||||
|
title: String,
|
||||||
|
dialogTitle: String,
|
||||||
|
preferenceKey: PreferenceUtils.Key,
|
||||||
|
options: Map<String, String>,
|
||||||
|
extraSelectBehavior: ((String?) -> Unit)? = null,
|
||||||
|
description: String? = null,
|
||||||
|
) {
|
||||||
|
val preferenceValue by PreferenceUtils.useStringPreference(preferenceKey)
|
||||||
|
|
||||||
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
OptionsCard(
|
||||||
|
title = { OptionsTitle(title = title, description = description) },
|
||||||
|
modifier = Modifier
|
||||||
|
.clickable(
|
||||||
|
onClick = {
|
||||||
|
showDialog = true
|
||||||
|
},
|
||||||
|
role = Role.Button
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Text(options[preferenceValue] ?: preferenceValue ?: "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showDialog) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
SelectDialog(
|
||||||
|
title = dialogTitle,
|
||||||
|
onDismissRequest = {
|
||||||
|
showDialog = false
|
||||||
|
},
|
||||||
|
onSelect = { selected ->
|
||||||
|
showDialog = false
|
||||||
|
PreferenceUtils.get(context)
|
||||||
|
.setString(preferenceKey, selected)
|
||||||
|
extraSelectBehavior?.invoke(selected)
|
||||||
|
},
|
||||||
|
initialValue = preferenceValue,
|
||||||
|
) {
|
||||||
|
options.forEach { (k, v) ->
|
||||||
|
SelectOption(name = v, value = k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SettingsStringCard(
|
||||||
|
title: String,
|
||||||
|
dialogTitle: String,
|
||||||
|
preferenceKey: PreferenceUtils.Key,
|
||||||
|
filterInput: ((String) -> String)? = null
|
||||||
|
) {
|
||||||
|
var preferenceValue by PreferenceUtils.useStringPreference(preferenceKey)
|
||||||
|
|
||||||
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
OptionsCard(
|
||||||
|
title = {
|
||||||
|
OptionsTitle(title = title, description = preferenceValue)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clickable(
|
||||||
|
onClick = {
|
||||||
|
showDialog = true
|
||||||
|
},
|
||||||
|
role = Role.Button
|
||||||
|
)
|
||||||
|
) { }
|
||||||
|
|
||||||
|
if (showDialog) {
|
||||||
|
StringDialog(
|
||||||
|
title = dialogTitle,
|
||||||
|
onDismissRequest = { showDialog = false },
|
||||||
|
onSelect = {
|
||||||
|
preferenceValue = it
|
||||||
|
showDialog = false
|
||||||
|
},
|
||||||
|
initialValue = preferenceValue ?: "",
|
||||||
|
filterInput = filterInput
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun StringDialog(
|
||||||
|
title: String,
|
||||||
|
onDismissRequest: () -> Unit,
|
||||||
|
onSelect: (String) -> Unit,
|
||||||
|
initialValue: String,
|
||||||
|
filterInput: ((String) -> String)? = null
|
||||||
|
) {
|
||||||
|
var enteredValue by remember { mutableStateOf(initialValue) }
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { onDismissRequest() },
|
||||||
|
title = {
|
||||||
|
Text(title)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = enteredValue,
|
||||||
|
onValueChange = {
|
||||||
|
enteredValue = filterInput?.invoke(it) ?: it
|
||||||
|
},
|
||||||
|
singleLine = true,
|
||||||
|
keyboardOptions = KeyboardOptions(
|
||||||
|
keyboardType = KeyboardType.Ascii,
|
||||||
|
autoCorrectEnabled = false
|
||||||
|
),
|
||||||
|
trailingIcon = {
|
||||||
|
if (enteredValue.isNotEmpty()) {
|
||||||
|
IconButton(onClick = { enteredValue = "" }) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Clear,
|
||||||
|
contentDescription = stringResource(R.string.preference_text_clear)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = { onSelect(enteredValue) }) {
|
||||||
|
Text(stringResource(R.string.message_box_accept))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismissRequest) {
|
||||||
|
Text(stringResource(R.string.message_box_cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun RangeDialog(
|
||||||
|
title: String,
|
||||||
|
onDismissRequest: () -> Unit,
|
||||||
|
onSelect: (Int) -> Unit,
|
||||||
|
labelSuffix: String,
|
||||||
|
initialValue: Int,
|
||||||
|
range: IntRange,
|
||||||
|
scale: Int,
|
||||||
|
step: Int,
|
||||||
|
children: @Composable () -> Unit
|
||||||
|
) {
|
||||||
|
var enteredValue by remember {
|
||||||
|
mutableFloatStateOf(initialValue / scale.toFloat())
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { onDismissRequest() },
|
||||||
|
title = {
|
||||||
|
Text(title)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.weight(1.0f, false)
|
||||||
|
) {
|
||||||
|
val precision = log10(scale.toFloat()).roundToInt()
|
||||||
|
|
||||||
|
Slider(
|
||||||
|
value = enteredValue,
|
||||||
|
onValueChange = { enteredValue = it },
|
||||||
|
valueRange = (range.first.toFloat()/scale)..(range.last.toFloat()/scale),
|
||||||
|
steps = ((range.last - range.first) - 1) / step,
|
||||||
|
modifier = Modifier.weight(1.0f)
|
||||||
|
)
|
||||||
|
|
||||||
|
Text("%.${precision}f$labelSuffix".format(enteredValue))
|
||||||
|
}
|
||||||
|
|
||||||
|
children()
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = { onSelect((enteredValue * scale).roundToInt()) }) {
|
||||||
|
Text(stringResource(R.string.message_box_accept))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismissRequest) {
|
||||||
|
Text(stringResource(R.string.message_box_cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun FrameRateDialog(
|
||||||
|
title: String,
|
||||||
|
onDismissRequest: () -> Unit,
|
||||||
|
onSelect: (Int) -> Unit,
|
||||||
|
initialValue: Int,
|
||||||
|
maxFrameRate: Int,
|
||||||
|
) {
|
||||||
|
var enteredValue by remember {
|
||||||
|
mutableStateOf(
|
||||||
|
if (initialValue == 0) maxFrameRate.toString()
|
||||||
|
else initialValue.toString()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val minFrameRate = 5
|
||||||
|
val currentValue = enteredValue.toIntOrNull()
|
||||||
|
val maximumReached = currentValue != null && currentValue > maxFrameRate
|
||||||
|
val minimumReached = currentValue != null && currentValue < minFrameRate
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { onDismissRequest() },
|
||||||
|
title = {
|
||||||
|
Text(title)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.weight(1.0f, false)
|
||||||
|
) {
|
||||||
|
IconButton(onClick = {
|
||||||
|
val prevValue = max((currentValue ?: 0) - 5, minFrameRate)
|
||||||
|
enteredValue = prevValue.toString()
|
||||||
|
}, enabled = currentValue == null || currentValue > minFrameRate) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.icon_remove),
|
||||||
|
contentDescription = stringResource(R.string.preference_limit_framerate_subtract)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(Modifier.size(8.dp))
|
||||||
|
|
||||||
|
OutlinedTextField(
|
||||||
|
value = enteredValue,
|
||||||
|
onValueChange = {
|
||||||
|
enteredValue = it
|
||||||
|
},
|
||||||
|
singleLine = true,
|
||||||
|
keyboardOptions = KeyboardOptions(
|
||||||
|
keyboardType = KeyboardType.Number,
|
||||||
|
),
|
||||||
|
suffix = {
|
||||||
|
Text(stringResource(R.string.preference_limit_framerate_suffix))
|
||||||
|
},
|
||||||
|
label = {
|
||||||
|
Text(stringResource(R.string.preference_limit_framerate_label))
|
||||||
|
},
|
||||||
|
isError = minimumReached || maximumReached,
|
||||||
|
modifier = Modifier.weight(1.0f),
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(Modifier.size(8.dp))
|
||||||
|
|
||||||
|
IconButton(onClick = {
|
||||||
|
val nextValue = min((currentValue ?: 0) + 5, maxFrameRate)
|
||||||
|
enteredValue = nextValue.toString()
|
||||||
|
}, enabled = currentValue == null || currentValue < maxFrameRate) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Add,
|
||||||
|
contentDescription = stringResource(R.string.preference_limit_framerate_add)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
IconButton(onClick = { onSelect(0) }) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.icon_delete),
|
||||||
|
contentDescription = stringResource(R.string.preference_limit_framerate_reset)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (minimumReached) {
|
||||||
|
Spacer(Modifier.size(8.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.preference_limit_framerate_error_min, minFrameRate),
|
||||||
|
color = MaterialTheme.colorScheme.error,
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
)
|
||||||
|
} else if (maximumReached) {
|
||||||
|
Spacer(Modifier.size(8.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
stringResource(
|
||||||
|
R.string.preference_limit_framerate_error_max,
|
||||||
|
maxFrameRate
|
||||||
|
),
|
||||||
|
color = MaterialTheme.colorScheme.error,
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
// automatically disable if already max
|
||||||
|
if (currentValue == maxFrameRate) {
|
||||||
|
onSelect(0)
|
||||||
|
} else {
|
||||||
|
onSelect(currentValue ?: 0)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enabled = !minimumReached && !maximumReached && currentValue != null
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.message_box_accept))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismissRequest) {
|
||||||
|
Text(stringResource(R.string.message_box_cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SettingsFPSCard(
|
||||||
|
title: String,
|
||||||
|
dialogTitle: String,
|
||||||
|
preferenceKey: PreferenceUtils.Key,
|
||||||
|
maxFrameRate: Int,
|
||||||
|
description: String? = null,
|
||||||
|
) {
|
||||||
|
var preferenceValue by PreferenceUtils.useIntPreference(preferenceKey)
|
||||||
|
|
||||||
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
OptionsCard(
|
||||||
|
title = { OptionsTitle(title = title, description = description) },
|
||||||
|
modifier = Modifier
|
||||||
|
.clickable(
|
||||||
|
onClick = {
|
||||||
|
showDialog = true
|
||||||
|
},
|
||||||
|
role = Role.Button
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
if (preferenceValue == 0) {
|
||||||
|
Text(stringResource(R.string.preference_limit_framerate_default))
|
||||||
|
} else {
|
||||||
|
Text(stringResource(R.string.preference_limit_framerate_value, preferenceValue))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showDialog) {
|
||||||
|
FrameRateDialog(
|
||||||
|
title = dialogTitle,
|
||||||
|
onDismissRequest = { showDialog = false },
|
||||||
|
onSelect = {
|
||||||
|
preferenceValue = it
|
||||||
|
showDialog = false
|
||||||
|
},
|
||||||
|
initialValue = preferenceValue,
|
||||||
|
maxFrameRate = maxFrameRate
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SettingsRangeCard(
|
||||||
|
title: String,
|
||||||
|
dialogTitle: String,
|
||||||
|
preferenceKey: PreferenceUtils.Key,
|
||||||
|
labelSuffix: String,
|
||||||
|
range: IntRange,
|
||||||
|
scale: Int,
|
||||||
|
step: Int,
|
||||||
|
description: String? = null,
|
||||||
|
children: @Composable () -> Unit = {}
|
||||||
|
) {
|
||||||
|
var preferenceValue by PreferenceUtils.useIntPreference(preferenceKey)
|
||||||
|
|
||||||
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
OptionsCard(
|
||||||
|
title = {
|
||||||
|
OptionsTitle(title = title, description = description)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clickable(
|
||||||
|
onClick = {
|
||||||
|
showDialog = true
|
||||||
|
},
|
||||||
|
role = Role.Button
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
val precision = log10(scale.toFloat()).roundToInt()
|
||||||
|
val scaledValue = preferenceValue / scale.toFloat()
|
||||||
|
|
||||||
|
Text("%.${precision}f$labelSuffix".format(scaledValue))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showDialog) {
|
||||||
|
RangeDialog(
|
||||||
|
title = dialogTitle,
|
||||||
|
onDismissRequest = { showDialog = false },
|
||||||
|
onSelect = {
|
||||||
|
preferenceValue = it
|
||||||
|
showDialog = false
|
||||||
|
},
|
||||||
|
initialValue = preferenceValue,
|
||||||
|
range = range,
|
||||||
|
scale = scale,
|
||||||
|
labelSuffix = labelSuffix,
|
||||||
|
step = step,
|
||||||
|
children = children,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal val LocalSelectValue = compositionLocalOf<Any> { 0 }
|
||||||
|
internal val LocalSelectSetValue = staticCompositionLocalOf<(Any) -> Unit> { {} }
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun <T> SelectOption(name: String, value: T, enabled: Boolean = true, leadingContent: @Composable (Boolean) -> Unit = {}) {
|
||||||
|
val currentValue = LocalSelectValue.current
|
||||||
|
val setValue = LocalSelectSetValue.current
|
||||||
|
|
||||||
|
val isSelected = currentValue.equals(value)
|
||||||
|
|
||||||
|
// do not give the row or column padding!! it messes up the selection effect
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable(
|
||||||
|
onClick = { setValue(value as Any) },
|
||||||
|
role = Role.RadioButton,
|
||||||
|
enabled = enabled
|
||||||
|
)
|
||||||
|
.padding(horizontal = 12.dp)
|
||||||
|
) {
|
||||||
|
Row(modifier = Modifier.weight(1.0f, true), verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
RadioButton(
|
||||||
|
selected = isSelected,
|
||||||
|
onClick = { setValue(value as Any) },
|
||||||
|
enabled = enabled
|
||||||
|
)
|
||||||
|
Text(name, style = Typography.bodyMedium)
|
||||||
|
}
|
||||||
|
|
||||||
|
leadingContent(isSelected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ProfileCreateDialog(onDismissRequest: () -> Unit) {
|
||||||
|
var enteredValue by remember { mutableStateOf("") }
|
||||||
|
|
||||||
|
val filename = enteredValue.take(16)
|
||||||
|
.lowercase()
|
||||||
|
.map {
|
||||||
|
if ("qwertyuiopasdfghjklzxcvbnm1234567890-_.".contains(it))
|
||||||
|
it else '_'
|
||||||
|
}
|
||||||
|
.joinToString("")
|
||||||
|
|
||||||
|
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val minimumReached = enteredValue.isEmpty() || filename.isEmpty()
|
||||||
|
|
||||||
|
val profileManager = ProfileManager.get(context)
|
||||||
|
val currentProfiles = remember {
|
||||||
|
profileManager.getProfiles().map { it.path }.toSet()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isDuplicate = currentProfiles.contains(filename)
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { onDismissRequest() },
|
||||||
|
title = {
|
||||||
|
Text(stringResource(R.string.preference_profiles_create))
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.weight(1.0f, false)
|
||||||
|
) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = enteredValue,
|
||||||
|
onValueChange = {
|
||||||
|
enteredValue = it
|
||||||
|
},
|
||||||
|
singleLine = true,
|
||||||
|
keyboardOptions = KeyboardOptions(
|
||||||
|
keyboardType = KeyboardType.Text,
|
||||||
|
),
|
||||||
|
label = {
|
||||||
|
Text(stringResource(R.string.preference_profiles_create_name))
|
||||||
|
},
|
||||||
|
isError = isDuplicate
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDuplicate) {
|
||||||
|
Spacer(Modifier.size(8.dp))
|
||||||
|
|
||||||
|
Text(stringResource(R.string.preference_profiles_create_duplicate))
|
||||||
|
} else if (!minimumReached) {
|
||||||
|
Spacer(Modifier.size(8.dp))
|
||||||
|
|
||||||
|
Text(stringResource(R.string.preference_profiles_create_info, filename))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
ProfileManager.get(context).storeProfile(Profile(filename, enteredValue))
|
||||||
|
onDismissRequest()
|
||||||
|
},
|
||||||
|
enabled = !minimumReached && !isDuplicate
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.preference_profiles_create_action))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismissRequest) {
|
||||||
|
Text(stringResource(R.string.message_box_cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ProfileCreateCard() {
|
||||||
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
OptionsButton(
|
||||||
|
title = stringResource(R.string.preference_profiles_create),
|
||||||
|
icon = {
|
||||||
|
Icon(painterResource(R.drawable.icon_person_add), contentDescription = null)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
showDialog = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showDialog) {
|
||||||
|
ProfileCreateDialog(onDismissRequest = {
|
||||||
|
showDialog = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ProfileSelectCard() {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val profileManager = ProfileManager.get(context)
|
||||||
|
|
||||||
|
val currentProfileId = remember {
|
||||||
|
profileManager.getCurrentProfile()
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentProfileName = remember {
|
||||||
|
val savedProfile = currentProfileId
|
||||||
|
if (savedProfile == null) {
|
||||||
|
"Default"
|
||||||
|
} else {
|
||||||
|
profileManager.getProfile(savedProfile)
|
||||||
|
?.name ?: savedProfile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val clearedProfiles = remember { mutableStateListOf<String>() }
|
||||||
|
|
||||||
|
val profileList by profileManager.storedProfiles.collectAsState()
|
||||||
|
|
||||||
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
OptionsButton(
|
||||||
|
title = stringResource(R.string.preference_profiles_select),
|
||||||
|
description = stringResource(R.string.preference_profiles_current, currentProfileName)
|
||||||
|
) {
|
||||||
|
showDialog = true
|
||||||
|
}
|
||||||
|
|
||||||
|
val activity = LocalActivity.current
|
||||||
|
if (showDialog) {
|
||||||
|
SelectDialog(
|
||||||
|
title = stringResource(R.string.preference_profiles_select),
|
||||||
|
onDismissRequest = {
|
||||||
|
showDialog = false
|
||||||
|
},
|
||||||
|
onSelect = {
|
||||||
|
showDialog = false
|
||||||
|
|
||||||
|
val selectedProfileId = it.takeIf { it.isNotEmpty() }
|
||||||
|
|
||||||
|
if (clearedProfiles.isNotEmpty()) {
|
||||||
|
profileManager.deleteProfiles(clearedProfiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentProfileId != selectedProfileId) {
|
||||||
|
profileManager
|
||||||
|
.setCurrentProfile(selectedProfileId)
|
||||||
|
|
||||||
|
activity?.run {
|
||||||
|
packageManager.getLaunchIntentForPackage(packageName)?.also {
|
||||||
|
val mainIntent = Intent.makeRestartActivityTask(it.component)
|
||||||
|
startActivity(mainIntent)
|
||||||
|
exitProcess(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
initialValue = currentProfileId ?: "",
|
||||||
|
) {
|
||||||
|
SelectOption("Default", "")
|
||||||
|
|
||||||
|
profileList.forEach { profile ->
|
||||||
|
val path = profile.path
|
||||||
|
|
||||||
|
SelectOption(
|
||||||
|
stringResource(R.string.preference_profiles_select_value, profile.name, path),
|
||||||
|
path,
|
||||||
|
enabled = !clearedProfiles.contains(path),
|
||||||
|
leadingContent = { selected ->
|
||||||
|
IconButton(onClick = {
|
||||||
|
if (clearedProfiles.contains(path)) {
|
||||||
|
clearedProfiles.remove(path)
|
||||||
|
} else {
|
||||||
|
clearedProfiles.add(path)
|
||||||
|
}
|
||||||
|
}, enabled = !selected) {
|
||||||
|
if (clearedProfiles.contains(path)) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.icon_undo),
|
||||||
|
contentDescription = stringResource(R.string.preference_profiles_delete_undo_alt)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Delete,
|
||||||
|
contentDescription = stringResource(R.string.preference_profiles_delete_alt)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun <T> SelectDialog(
|
||||||
|
title: String,
|
||||||
|
onDismissRequest: () -> Unit,
|
||||||
|
onSelect: (T) -> Unit,
|
||||||
|
initialValue: T,
|
||||||
|
options: @Composable () -> Unit,
|
||||||
|
) {
|
||||||
|
val (selectedValue, setSelectedValue) = remember { mutableStateOf(initialValue) }
|
||||||
|
|
||||||
|
Dialog(onDismissRequest = onDismissRequest) {
|
||||||
|
Card(
|
||||||
|
shape = RoundedCornerShape(16.dp)
|
||||||
|
) {
|
||||||
|
// styling a dialog is actually a little hard if you're doing what i'm doing
|
||||||
|
// maybe there's a better way to make these padding values...
|
||||||
|
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
|
||||||
|
Text(
|
||||||
|
title,
|
||||||
|
style = Typography.titleLarge,
|
||||||
|
modifier = Modifier.padding(
|
||||||
|
start = 28.dp,
|
||||||
|
top = 24.dp,
|
||||||
|
bottom = 12.dp
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
CompositionLocalProvider(
|
||||||
|
LocalSelectValue provides (selectedValue as Any),
|
||||||
|
LocalSelectSetValue provides ({
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
setSelectedValue(it as T)
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
options()
|
||||||
|
}
|
||||||
|
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.End,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(
|
||||||
|
bottom = 16.dp,
|
||||||
|
end = 16.dp,
|
||||||
|
top = 4.dp
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
TextButton(onClick = onDismissRequest) {
|
||||||
|
Text(stringResource(R.string.message_box_cancel))
|
||||||
|
}
|
||||||
|
|
||||||
|
TextButton(onClick = { onSelect(selectedValue) }) {
|
||||||
|
Text(stringResource(R.string.message_box_accept))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun OptionsButton(title: String, description: String? = null, icon: (@Composable () -> Unit)? = null, displayInline: Boolean = false, onClick: () -> Unit) {
|
||||||
|
OptionsCard(
|
||||||
|
title = {
|
||||||
|
OptionsTitle(
|
||||||
|
title = title,
|
||||||
|
description = description.takeIf { !displayInline },
|
||||||
|
icon = icon
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clickable(onClick = onClick, role = Role.Button),
|
||||||
|
wrapContent = true
|
||||||
|
) {
|
||||||
|
if (displayInline && description != null) {
|
||||||
|
Text(description, textAlign = TextAlign.End)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SettingsCard(title: String, description: String? = null, icon: (@Composable () -> Unit)? = null, asCard: Boolean = true, preferenceKey: PreferenceUtils.Key) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val settingEnabled = remember {
|
||||||
|
mutableStateOf(getSetting(context, preferenceKey))
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsCard(
|
||||||
|
title = {
|
||||||
|
OptionsTitle(
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
icon = icon
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = if (asCard) Modifier.toggleable(
|
||||||
|
value = settingEnabled.value,
|
||||||
|
onValueChange = { settingEnabled.value = toggleSetting(context, preferenceKey) },
|
||||||
|
role = Role.Switch,
|
||||||
|
) else Modifier
|
||||||
|
) {
|
||||||
|
Switch(
|
||||||
|
checked = settingEnabled.value,
|
||||||
|
onCheckedChange = if (!asCard)
|
||||||
|
{ _ -> settingEnabled.value = toggleSetting(context, preferenceKey) }
|
||||||
|
else null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun OptionsTitle(modifier: Modifier = Modifier, title: String, description: String? = null, icon: (@Composable () -> Unit)? = null) {
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
if (icon != null) {
|
||||||
|
icon()
|
||||||
|
}
|
||||||
|
Column(
|
||||||
|
modifier,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
) {
|
||||||
|
Text(title)
|
||||||
|
if (!description.isNullOrEmpty()) {
|
||||||
|
Text(
|
||||||
|
description,
|
||||||
|
style = Typography.labelMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSecondaryContainer
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun OptionsCard(modifier: Modifier = Modifier, wrapContent: Boolean = false, title: @Composable () -> Unit, content: @Composable () -> Unit) {
|
||||||
|
Row(
|
||||||
|
modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.defaultMinSize(minHeight = 64.dp)
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
Arrangement.SpaceBetween,
|
||||||
|
Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
if (!wrapContent) {
|
||||||
|
Box(modifier = Modifier.weight(1.0f)) {
|
||||||
|
title()
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.size(12.dp))
|
||||||
|
} else {
|
||||||
|
title()
|
||||||
|
}
|
||||||
|
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun InlineText(label: String, icon: @Composable (() -> Unit)? = null, modifier: Modifier = Modifier) {
|
||||||
|
LabelledText(label = label, icon = icon, modifier = modifier.padding(horizontal = 16.dp, vertical = 4.dp))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(showBackground = true)
|
||||||
|
@Composable
|
||||||
|
fun OptionsCardPreview() {
|
||||||
|
GeodeLauncherTheme {
|
||||||
|
OptionsGroup(title = "Preview Group") {
|
||||||
|
SettingsCard(
|
||||||
|
title = "Load files from /test",
|
||||||
|
description = "Very long testing description goes here. It is incredibly long, it should wrap onto a new line.",
|
||||||
|
preferenceKey = PreferenceUtils.Key.BLACK_BACKGROUND
|
||||||
|
)
|
||||||
|
SettingsCard(
|
||||||
|
title = "Testing option 2",
|
||||||
|
preferenceKey = PreferenceUtils.Key.LOAD_AUTOMATICALLY
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ data class Asset(
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class Release(
|
data class Release(
|
||||||
val url: String,
|
val url: String,
|
||||||
val id: Int,
|
val id: Int,
|
||||||
val targetCommitish: String,
|
val targetCommitish: String,
|
||||||
@@ -24,40 +24,86 @@ class Release(
|
|||||||
val createdAt: Instant,
|
val createdAt: Instant,
|
||||||
val publishedAt: Instant,
|
val publishedAt: Instant,
|
||||||
val assets: List<Asset>,
|
val assets: List<Asset>,
|
||||||
val htmlUrl: String
|
val htmlUrl: String,
|
||||||
) {
|
val body: String?,
|
||||||
fun getDescription(): String {
|
val name: String?,
|
||||||
if (tagName == "nightly") {
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class LoaderVersion(
|
||||||
|
val tag: String,
|
||||||
|
val version: String,
|
||||||
|
val createdAt: Instant,
|
||||||
|
val commitHash: String,
|
||||||
|
val prerelease: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class LoaderPayload<T>(
|
||||||
|
val payload: T?,
|
||||||
|
val error: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class DownloadableAsset(val url: String, val filename: String, val size: Long? = null)
|
||||||
|
|
||||||
|
abstract class Downloadable {
|
||||||
|
abstract fun getDescription(): String
|
||||||
|
abstract fun getDescriptor(): Long
|
||||||
|
abstract fun getDownload(): DownloadableAsset?
|
||||||
|
}
|
||||||
|
|
||||||
|
class DownloadableGitHubLoaderRelease(private val release: Release) : Downloadable() {
|
||||||
|
override fun getDescription(): String {
|
||||||
|
if (release.tagName == "nightly") {
|
||||||
// get the commit from the assets
|
// get the commit from the assets
|
||||||
// otherwise, a separate request is needed to get the hash (ew)
|
// otherwise, a separate request is needed to get the hash (ew)
|
||||||
val asset = assets.first()
|
val asset = release.assets.first()
|
||||||
val commit = asset.name.substring(6..12)
|
val commit = asset.name.substring(6..12)
|
||||||
|
|
||||||
return "nightly-$commit"
|
return "nightly-$commit"
|
||||||
}
|
}
|
||||||
|
|
||||||
return tagName
|
return release.tagName
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDescriptor(): Long {
|
override fun getDescriptor(): Long {
|
||||||
return createdAt.epochSeconds
|
return release.createdAt.epochSeconds
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGeodeDownload(): Asset? {
|
private fun getGitHubDownload(): Asset? {
|
||||||
// try to find an asset that matches the architecture first
|
// try to find an asset that matches the architecture first
|
||||||
val platform = LaunchUtils.platformName
|
val platform = LaunchUtils.platformName
|
||||||
|
|
||||||
val releaseSuffix = "$platform.zip"
|
val releaseSuffix = "$platform.zip"
|
||||||
return assets.find {
|
return release.assets.find {
|
||||||
it.name.endsWith(releaseSuffix)
|
it.name.endsWith(releaseSuffix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLauncherDownload(): Asset? {
|
override fun getDownload(): DownloadableAsset? {
|
||||||
|
val download = getGitHubDownload() ?: return null
|
||||||
|
return DownloadableAsset(
|
||||||
|
url = download.browserDownloadUrl,
|
||||||
|
filename = download.name,
|
||||||
|
size = download.size.toLong()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DownloadableLauncherRelease(val release: Release) : Downloadable() {
|
||||||
|
override fun getDescription(): String {
|
||||||
|
return release.tagName
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDescriptor(): Long {
|
||||||
|
return release.createdAt.epochSeconds
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getGitHubDownload(): Asset? {
|
||||||
val platform = LaunchUtils.platformName
|
val platform = LaunchUtils.platformName
|
||||||
val use32BitPlatform = platform == "android32"
|
val use32BitPlatform = platform == "android32"
|
||||||
|
|
||||||
return assets.find { asset ->
|
return release.assets.find { asset ->
|
||||||
/* you know it's good when you pull out the truth table
|
/* you know it's good when you pull out the truth table
|
||||||
* u32bp | contains | found
|
* u32bp | contains | found
|
||||||
* 1 | 1 | 1
|
* 1 | 1 | 1
|
||||||
@@ -70,4 +116,31 @@ class Release(
|
|||||||
(asset.name.contains("android32")) == use32BitPlatform
|
(asset.name.contains("android32")) == use32BitPlatform
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getDownload(): DownloadableAsset? {
|
||||||
|
val download = getGitHubDownload() ?: return null
|
||||||
|
return DownloadableAsset(
|
||||||
|
url = download.browserDownloadUrl,
|
||||||
|
filename = download.name,
|
||||||
|
size = download.size.toLong()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DownloadableLoaderRelease(private val version: LoaderVersion) : Downloadable() {
|
||||||
|
override fun getDescription(): String {
|
||||||
|
return version.tag
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDescriptor(): Long {
|
||||||
|
return version.createdAt.epochSeconds
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDownload(): DownloadableAsset? {
|
||||||
|
val filename = "geode-${version.tag}-${LaunchUtils.platformName}.zip"
|
||||||
|
return DownloadableAsset(
|
||||||
|
url = "https://github.com/geode-sdk/geode/releases/download/${version.tag}/$filename",
|
||||||
|
filename = filename
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.geode.launcher.BuildConfig
|
import com.geode.launcher.BuildConfig
|
||||||
import com.geode.launcher.utils.DownloadUtils
|
import com.geode.launcher.utils.DownloadUtils
|
||||||
|
import com.geode.launcher.utils.GamePackageUtils
|
||||||
import com.geode.launcher.utils.LaunchUtils
|
import com.geode.launcher.utils.LaunchUtils
|
||||||
import com.geode.launcher.utils.PreferenceUtils
|
import com.geode.launcher.utils.PreferenceUtils
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
@@ -22,6 +23,9 @@ import okio.source
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InterruptedIOException
|
import java.io.InterruptedIOException
|
||||||
|
|
||||||
|
private const val TAG_LATEST = "latest"
|
||||||
|
private const val TAG_BETA = "prerelease"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton to manage Geode updates, from update checking to downloading.
|
* Singleton to manage Geode updates, from update checking to downloading.
|
||||||
*/
|
*/
|
||||||
@@ -57,7 +61,7 @@ class ReleaseManager private constructor(
|
|||||||
sealed class ReleaseManagerState {
|
sealed class ReleaseManagerState {
|
||||||
data object InUpdateCheck : ReleaseManagerState()
|
data object InUpdateCheck : ReleaseManagerState()
|
||||||
data class Failure(val exception: Exception) : ReleaseManagerState()
|
data class Failure(val exception: Exception) : ReleaseManagerState()
|
||||||
data class InDownload(val downloaded: Long, val outOf: Long) : ReleaseManagerState()
|
data class InDownload(val downloaded: Long, val outOf: Long?) : ReleaseManagerState()
|
||||||
data class Finished(val hasUpdated: Boolean = false) : ReleaseManagerState()
|
data class Finished(val hasUpdated: Boolean = false) : ReleaseManagerState()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +82,7 @@ class ReleaseManager private constructor(
|
|||||||
val isInUpdate: Boolean
|
val isInUpdate: Boolean
|
||||||
get() = _uiState.value !is ReleaseManagerState.Failure && _uiState.value !is ReleaseManagerState.Finished
|
get() = _uiState.value !is ReleaseManagerState.Failure && _uiState.value !is ReleaseManagerState.Finished
|
||||||
|
|
||||||
private val _availableLauncherUpdate = MutableStateFlow<Release?>(null)
|
private val _availableLauncherUpdate = MutableStateFlow<DownloadableLauncherRelease?>(null)
|
||||||
val availableLauncherUpdate = _availableLauncherUpdate.asStateFlow()
|
val availableLauncherUpdate = _availableLauncherUpdate.asStateFlow()
|
||||||
|
|
||||||
private fun sendError(e: Exception) {
|
private fun sendError(e: Exception) {
|
||||||
@@ -91,24 +95,82 @@ class ReleaseManager private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dismissLauncherUpdate() {
|
private fun mapSelectedReleaseToTag(): String {
|
||||||
val update = availableLauncherUpdate.value ?: return
|
|
||||||
|
|
||||||
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
||||||
sharedPreferences.setString(PreferenceUtils.Key.LAST_DISMISSED_UPDATE, update.tagName)
|
val releaseChannel = sharedPreferences.getInt(PreferenceUtils.Key.RELEASE_CHANNEL_TAG)
|
||||||
|
|
||||||
_availableLauncherUpdate.value = null
|
return when (releaseChannel) {
|
||||||
|
2 -> "nightly"
|
||||||
|
1 -> TAG_BETA
|
||||||
|
else -> TAG_LATEST
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getLatestRelease(): Release? {
|
private fun getBestReleaseForGameVersion(gameVersion: Long): String? = when {
|
||||||
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
gameVersion >= 40L -> mapSelectedReleaseToTag()
|
||||||
val useNightly = sharedPreferences.getBoolean(PreferenceUtils.Key.RELEASE_CHANNEL)
|
gameVersion == 39L -> "v3.9.3"
|
||||||
|
gameVersion == 38L -> "v2.0.0-beta.27"
|
||||||
return releaseRepository.getLatestGeodeRelease(useNightly)
|
gameVersion == 37L -> "v2.0.0-beta.4"
|
||||||
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun performUpdate(release: Release) {
|
private suspend fun getLatestRelease(): Downloadable? {
|
||||||
val releaseAsset = release.getGeodeDownload()
|
if (!GamePackageUtils.isGameInstalled(applicationContext.packageManager)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val gameVersion = GamePackageUtils.getGameVersionCode(applicationContext.packageManager)
|
||||||
|
val preferences = PreferenceUtils.get(applicationContext)
|
||||||
|
|
||||||
|
if (preferences.getBoolean(PreferenceUtils.Key.USE_INDEX_API)) {
|
||||||
|
val targetTag = preferences.getInt(PreferenceUtils.Key.RELEASE_CHANNEL_TAG)
|
||||||
|
|
||||||
|
return when (targetTag) {
|
||||||
|
2 -> releaseRepository.getReleaseByTag("nightly")
|
||||||
|
1 -> releaseRepository.getLatestIndexRelease(gameVersion, true)
|
||||||
|
else -> releaseRepository.getLatestIndexRelease(gameVersion, false)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val targetTag = getBestReleaseForGameVersion(gameVersion) ?: return null
|
||||||
|
|
||||||
|
return when (targetTag) {
|
||||||
|
TAG_LATEST -> releaseRepository.getLatestGeodeRelease()
|
||||||
|
TAG_BETA -> releaseRepository.getLatestGeodePreRelease()
|
||||||
|
else -> releaseRepository.getReleaseByTag(targetTag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun downloadLauncherUpdate(release: Downloadable) {
|
||||||
|
val download = release.getDownload() ?: return
|
||||||
|
|
||||||
|
val outputDirectory = LaunchUtils.getBaseDirectory(applicationContext)
|
||||||
|
val outputFile = File(outputDirectory, download.filename)
|
||||||
|
|
||||||
|
if (outputFile.exists()) {
|
||||||
|
// only download the apk once
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_uiState.value = ReleaseManagerState.InDownload(0, download.size)
|
||||||
|
|
||||||
|
try {
|
||||||
|
val fileStream = DownloadUtils.downloadStream(
|
||||||
|
httpClient,
|
||||||
|
download.url
|
||||||
|
) { progress, outOf ->
|
||||||
|
_uiState.value = ReleaseManagerState.InDownload(progress, outOf)
|
||||||
|
}
|
||||||
|
|
||||||
|
fileStream.copyTo(outputFile.outputStream())
|
||||||
|
} catch (e: Exception) {
|
||||||
|
sendError(e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun performUpdate(release: Downloadable) {
|
||||||
|
val releaseAsset = release.getDownload()
|
||||||
if (releaseAsset == null) {
|
if (releaseAsset == null) {
|
||||||
val noAssetException = Exception("missing Android download")
|
val noAssetException = Exception("missing Android download")
|
||||||
_uiState.value = ReleaseManagerState.Failure(noAssetException)
|
_uiState.value = ReleaseManagerState.Failure(noAssetException)
|
||||||
@@ -117,47 +179,62 @@ class ReleaseManager private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set an initial download size
|
// set an initial download size
|
||||||
_uiState.value = ReleaseManagerState.InDownload(0, releaseAsset.size.toLong())
|
_uiState.value = ReleaseManagerState.InDownload(0, releaseAsset.size)
|
||||||
|
|
||||||
|
val outputFile = getTempFile()
|
||||||
|
// clone the file instance as renameTo may move the original file
|
||||||
|
val tempFilePath = outputFile.path
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val fileStream = DownloadUtils.downloadStream(
|
val fileStream = DownloadUtils.downloadStream(
|
||||||
httpClient,
|
httpClient,
|
||||||
releaseAsset.browserDownloadUrl
|
releaseAsset.url
|
||||||
) { progress, outOf ->
|
) { progress, outOf ->
|
||||||
_uiState.value = ReleaseManagerState.InDownload(progress, outOf)
|
_uiState.value = ReleaseManagerState.InDownload(progress, outOf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outputFile.parentFile?.mkdirs()
|
||||||
|
|
||||||
val geodeFile = getGeodeOutputPath()
|
val geodeFile = getGeodeOutputPath()
|
||||||
|
|
||||||
|
DownloadUtils.extractFileFromZipStream(
|
||||||
|
fileStream,
|
||||||
|
outputFile.outputStream(),
|
||||||
|
geodeFile.name
|
||||||
|
)
|
||||||
|
|
||||||
// work around a permission issue from adb push
|
// work around a permission issue from adb push
|
||||||
if (geodeFile.exists()) {
|
if (geodeFile.exists()) {
|
||||||
geodeFile.delete()
|
geodeFile.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
geodeFile.parentFile?.mkdirs()
|
outputFile.renameTo(geodeFile)
|
||||||
|
|
||||||
DownloadUtils.extractFileFromZipStream(
|
|
||||||
fileStream,
|
|
||||||
geodeFile.outputStream(),
|
|
||||||
geodeFile.name
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
sendError(e)
|
sendError(e)
|
||||||
return
|
return
|
||||||
|
} finally {
|
||||||
|
val tempFileClone = File(tempFilePath)
|
||||||
|
try {
|
||||||
|
if (tempFileClone.exists()) tempFileClone.delete()
|
||||||
|
} catch (_: Exception) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
downloadLauncherUpdateIfNecessary()
|
||||||
|
|
||||||
// extraction performed
|
// extraction performed
|
||||||
updatePreferences(release)
|
updatePreferences(release)
|
||||||
_uiState.value = ReleaseManagerState.Finished(true)
|
_uiState.value = ReleaseManagerState.Finished(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fileWasExternallyModified(): Boolean {
|
private fun fileWasExternallyModified(modifiedOnly: Boolean = false): Boolean {
|
||||||
|
// make sure geode is still here. just in case
|
||||||
val geodeFile = getGeodeOutputPath()
|
val geodeFile = getGeodeOutputPath()
|
||||||
if (!geodeFile.exists()) {
|
if (!geodeFile.exists()) {
|
||||||
return false
|
return !modifiedOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
||||||
|
|
||||||
val originalFileHash = sharedPreferences.getString(PreferenceUtils.Key.CURRENT_RELEASE_MODIFIED)
|
val originalFileHash = sharedPreferences.getString(PreferenceUtils.Key.CURRENT_RELEASE_MODIFIED)
|
||||||
?: return false
|
?: return false
|
||||||
|
|
||||||
@@ -166,20 +243,18 @@ class ReleaseManager private constructor(
|
|||||||
return originalFileHash != currentFileHash
|
return originalFileHash != currentFileHash
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkLauncherUpdate(launcherUpdate: Release) {
|
private fun checkLauncherUpdate(launcherUpdate: DownloadableLauncherRelease) {
|
||||||
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
if (launcherUpdate.release.tagName != BuildConfig.VERSION_NAME) {
|
||||||
val lastDismissedVersion = sharedPreferences.getString(PreferenceUtils.Key.LAST_DISMISSED_UPDATE)
|
|
||||||
|
|
||||||
if (!lastDismissedVersion.isNullOrEmpty() && launcherUpdate.tagName == lastDismissedVersion) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (launcherUpdate.tagName != BuildConfig.VERSION_NAME) {
|
|
||||||
_availableLauncherUpdate.value = launcherUpdate
|
_availableLauncherUpdate.value = launcherUpdate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun checkForNewRelease(allowOverwriting: Boolean = false) {
|
private suspend fun downloadLauncherUpdateIfNecessary() {
|
||||||
|
val update = _availableLauncherUpdate.value ?: return
|
||||||
|
downloadLauncherUpdate(update)
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun checkForNewRelease(isManual: Boolean = false) {
|
||||||
val release = try {
|
val release = try {
|
||||||
getLatestRelease()
|
getLatestRelease()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -199,6 +274,8 @@ class ReleaseManager private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (release == null) {
|
if (release == null) {
|
||||||
|
downloadLauncherUpdateIfNecessary()
|
||||||
|
|
||||||
_uiState.value = ReleaseManagerState.Finished()
|
_uiState.value = ReleaseManagerState.Finished()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -208,17 +285,20 @@ class ReleaseManager private constructor(
|
|||||||
val currentVersion = sharedPreferences.getLong(PreferenceUtils.Key.CURRENT_VERSION_TIMESTAMP)
|
val currentVersion = sharedPreferences.getLong(PreferenceUtils.Key.CURRENT_VERSION_TIMESTAMP)
|
||||||
val latestVersion = release.getDescriptor()
|
val latestVersion = release.getDescriptor()
|
||||||
|
|
||||||
// make sure geode is still here. just in case
|
|
||||||
val geodeFile = getGeodeOutputPath()
|
|
||||||
|
|
||||||
// check if an update is needed
|
// check if an update is needed
|
||||||
if (latestVersion == currentVersion && geodeFile.exists()) {
|
if (latestVersion == currentVersion && !fileWasExternallyModified()) {
|
||||||
|
downloadLauncherUpdateIfNecessary()
|
||||||
|
|
||||||
_uiState.value = ReleaseManagerState.Finished()
|
_uiState.value = ReleaseManagerState.Finished()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val allowOverwriting = !sharedPreferences.getBoolean(PreferenceUtils.Key.DEVELOPER_MODE) || isManual
|
||||||
|
|
||||||
// check if the file was externally modified
|
// check if the file was externally modified
|
||||||
if (!allowOverwriting && fileWasExternallyModified()) {
|
if (!allowOverwriting && fileWasExternallyModified(true)) {
|
||||||
|
downloadLauncherUpdateIfNecessary()
|
||||||
|
|
||||||
sendError(UpdateException(UpdateException.Reason.EXTERNAL_FILE_IN_USE))
|
sendError(UpdateException(UpdateException.Reason.EXTERNAL_FILE_IN_USE))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -226,7 +306,7 @@ class ReleaseManager private constructor(
|
|||||||
performUpdate(release)
|
performUpdate(release)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePreferences(release: Release) {
|
private fun updatePreferences(release: Downloadable) {
|
||||||
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
||||||
|
|
||||||
sharedPreferences.setString(
|
sharedPreferences.setString(
|
||||||
@@ -256,6 +336,15 @@ class ReleaseManager private constructor(
|
|||||||
return File(geodeDirectory, geodeName)
|
return File(geodeDirectory, geodeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getTempFile(): File {
|
||||||
|
val geodeName = LaunchUtils.geodeFilename
|
||||||
|
val geodeDirectory = LaunchUtils.getBaseDirectory(applicationContext)
|
||||||
|
|
||||||
|
val tempFile = File.createTempFile(geodeName, null, geodeDirectory)
|
||||||
|
|
||||||
|
return tempFile
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels the current update job.
|
* Cancels the current update job.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import kotlinx.serialization.ExperimentalSerializationApi
|
|||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.JsonNamingStrategy
|
import kotlinx.serialization.json.JsonNamingStrategy
|
||||||
import kotlinx.serialization.json.okio.decodeFromBufferedSource
|
import kotlinx.serialization.json.okio.decodeFromBufferedSource
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@@ -22,24 +23,85 @@ class ReleaseRepository(private val httpClient: OkHttpClient) {
|
|||||||
|
|
||||||
private const val GITHUB_RATELIMIT_REMAINING = "x-ratelimit-remaining"
|
private const val GITHUB_RATELIMIT_REMAINING = "x-ratelimit-remaining"
|
||||||
private const val GITHUB_RATELIMIT_RESET = "x-ratelimit-reset"
|
private const val GITHUB_RATELIMIT_RESET = "x-ratelimit-reset"
|
||||||
|
|
||||||
|
private const val GEODE_API_BASE = "https://api.geode-sdk.org/v1"
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getLatestLauncherRelease(): Release? {
|
suspend fun getLatestLauncherRelease(): DownloadableLauncherRelease? {
|
||||||
val releasePath = "$GITHUB_API_BASE/repos/geode-sdk/android-launcher/releases/latest"
|
val releasePath = "$GITHUB_API_BASE/repos/geode-sdk/android-launcher/releases/latest"
|
||||||
|
|
||||||
val url = URL(releasePath)
|
val url = URL(releasePath)
|
||||||
|
|
||||||
return getReleaseByUrl(url)
|
return getReleaseByUrl(url)?.let(::DownloadableLauncherRelease)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getLatestGeodeRelease(isNightly: Boolean = false): Release? {
|
suspend fun getLatestGeodeRelease(): DownloadableGitHubLoaderRelease? {
|
||||||
val geodeBaseUrl = "$GITHUB_API_BASE/repos/geode-sdk/geode/releases"
|
val releasePath = "$GITHUB_API_BASE/repos/geode-sdk/geode/releases/latest"
|
||||||
val releasePath = if (isNightly) "$geodeBaseUrl/tags/nightly"
|
|
||||||
else "$geodeBaseUrl/latest"
|
|
||||||
|
|
||||||
val url = URL(releasePath)
|
val url = URL(releasePath)
|
||||||
|
|
||||||
return getReleaseByUrl(url)
|
return getReleaseByUrl(url)?.let(::DownloadableGitHubLoaderRelease)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getReleaseByTag(tag: String): DownloadableGitHubLoaderRelease? {
|
||||||
|
val releasePath = "$GITHUB_API_BASE/repos/geode-sdk/geode/releases/tags/$tag"
|
||||||
|
val url = URL(releasePath)
|
||||||
|
|
||||||
|
return getReleaseByUrl(url)?.let(::DownloadableGitHubLoaderRelease)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
|
suspend fun getLatestGeodePreRelease(): DownloadableGitHubLoaderRelease? {
|
||||||
|
val releasesUrl = "$GITHUB_API_BASE/repos/geode-sdk/geode/releases?per_page=2"
|
||||||
|
val url = URL(releasesUrl)
|
||||||
|
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.addHeader(GITHUB_API_HEADER, GITHUB_API_VERSION)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val call = httpClient.newCall(request)
|
||||||
|
val response = call.executeCoroutine()
|
||||||
|
|
||||||
|
return when (response.code) {
|
||||||
|
200 -> {
|
||||||
|
val format = Json {
|
||||||
|
namingStrategy = JsonNamingStrategy.SnakeCase
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
}
|
||||||
|
|
||||||
|
val release = format.decodeFromBufferedSource<List<Release>>(
|
||||||
|
response.body!!.source()
|
||||||
|
)
|
||||||
|
|
||||||
|
(release.find { it.tagName != "nightly" })
|
||||||
|
?.let(::DownloadableGitHubLoaderRelease)
|
||||||
|
}
|
||||||
|
403 -> {
|
||||||
|
// determine if the error code is a ratelimit
|
||||||
|
// (github docs say it sends 429 too, but haven't seen that)
|
||||||
|
|
||||||
|
val limitRemaining = response.headers.get(GITHUB_RATELIMIT_REMAINING)?.toInt()
|
||||||
|
val limitReset = response.headers.get(GITHUB_RATELIMIT_RESET)?.toLong()
|
||||||
|
|
||||||
|
if (limitRemaining == 0 && limitReset != null) {
|
||||||
|
// handle ratelimit with a custom error
|
||||||
|
// there's also a retry-after header but again, haven't seen
|
||||||
|
val resetTime = Instant.fromEpochSeconds(limitReset, 0L)
|
||||||
|
val msg = generateRateLimitMessage(resetTime)
|
||||||
|
|
||||||
|
throw IOException(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
throw IOException("response 403: ${response.body!!.string()}")
|
||||||
|
}
|
||||||
|
404 -> {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
throw IOException("unknown response ${response.code}")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateRateLimitMessage(resetTime: Instant): String {
|
private fun generateRateLimitMessage(resetTime: Instant): String {
|
||||||
@@ -79,8 +141,8 @@ class ReleaseRepository(private val httpClient: OkHttpClient) {
|
|||||||
// determine if the error code is a ratelimit
|
// determine if the error code is a ratelimit
|
||||||
// (github docs say it sends 429 too, but haven't seen that)
|
// (github docs say it sends 429 too, but haven't seen that)
|
||||||
|
|
||||||
val limitRemaining = response.headers.get(GITHUB_RATELIMIT_REMAINING)?.toInt()
|
val limitRemaining = response.headers[GITHUB_RATELIMIT_REMAINING]?.toInt()
|
||||||
val limitReset = response.headers.get(GITHUB_RATELIMIT_RESET)?.toLong()
|
val limitReset = response.headers[GITHUB_RATELIMIT_RESET]?.toLong()
|
||||||
|
|
||||||
if (limitRemaining == 0 && limitReset != null) {
|
if (limitRemaining == 0 && limitReset != null) {
|
||||||
// handle ratelimit with a custom error
|
// handle ratelimit with a custom error
|
||||||
@@ -101,4 +163,45 @@ class ReleaseRepository(private val httpClient: OkHttpClient) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
|
suspend fun getLatestIndexRelease(gd: Long, prerelease: Boolean = false): DownloadableLoaderRelease? {
|
||||||
|
val url = "$GEODE_API_BASE/loader/versions/latest".toHttpUrlOrNull()!!
|
||||||
|
.newBuilder()
|
||||||
|
.addQueryParameter("gd", gd.toString())
|
||||||
|
.addQueryParameter("platform", "android")
|
||||||
|
.addQueryParameter("prerelease", prerelease.toString())
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val call = httpClient.newCall(request)
|
||||||
|
val response = call.executeCoroutine()
|
||||||
|
|
||||||
|
return when (response.code) {
|
||||||
|
200 -> {
|
||||||
|
val format = Json {
|
||||||
|
namingStrategy = JsonNamingStrategy.SnakeCase
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
}
|
||||||
|
|
||||||
|
val body = format.decodeFromBufferedSource<LoaderPayload<LoaderVersion>>(
|
||||||
|
response.body!!.source()
|
||||||
|
)
|
||||||
|
|
||||||
|
val release = body.payload ?: throw IOException("index error: ${body.error}")
|
||||||
|
|
||||||
|
DownloadableLoaderRelease(release)
|
||||||
|
}
|
||||||
|
404 -> {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
throw IOException("unknown response ${response.code}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ class ReleaseViewModel(private val application: Application): ViewModel() {
|
|||||||
sealed class ReleaseUIState {
|
sealed class ReleaseUIState {
|
||||||
data object InUpdateCheck : ReleaseUIState()
|
data object InUpdateCheck : ReleaseUIState()
|
||||||
data class Failure(val exception: Exception) : ReleaseUIState()
|
data class Failure(val exception: Exception) : ReleaseUIState()
|
||||||
data class InDownload(val downloaded: Long, val outOf: Long) : ReleaseUIState()
|
data class InDownload(val downloaded: Long, val outOf: Long?) : ReleaseUIState()
|
||||||
data class Finished(val hasUpdated: Boolean = false) : ReleaseUIState()
|
data class Finished(val hasUpdated: Boolean = false) : ReleaseUIState()
|
||||||
data class Cancelled(val isCancelling: Boolean = false) : ReleaseUIState()
|
data class Cancelled(val isCancelling: Boolean = false) : ReleaseUIState()
|
||||||
|
|
||||||
@@ -98,10 +98,4 @@ class ReleaseViewModel(private val application: Application): ViewModel() {
|
|||||||
syncUiState(releaseFlow)
|
syncUiState(releaseFlow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dismissLauncherUpdate() {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
ReleaseManager.get(application).dismissLauncherUpdate()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.geode.launcher.utils
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.text.InlineTextContent
|
||||||
|
import androidx.compose.foundation.text.appendInlineContent
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.Placeholder
|
||||||
|
import androidx.compose.ui.text.PlaceholderVerticalAlign
|
||||||
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LabelledText(label: String, icon: @Composable (() -> Unit)? = null, modifier: Modifier = Modifier) {
|
||||||
|
if (icon != null) {
|
||||||
|
val iconId = "inlineIcon"
|
||||||
|
val paddingId = "paddingIcon"
|
||||||
|
|
||||||
|
val labelText = buildAnnotatedString {
|
||||||
|
appendInlineContent(iconId, "[x]")
|
||||||
|
appendInlineContent(paddingId, " ")
|
||||||
|
append(label)
|
||||||
|
}
|
||||||
|
|
||||||
|
val inlineContent = mapOf(
|
||||||
|
Pair(iconId, InlineTextContent(
|
||||||
|
Placeholder(
|
||||||
|
width = 24.sp,
|
||||||
|
height = 24.sp,
|
||||||
|
placeholderVerticalAlign = PlaceholderVerticalAlign.TextCenter
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
icon()
|
||||||
|
}),
|
||||||
|
Pair(paddingId, InlineTextContent(Placeholder(width = 6.sp, height = 24.sp, placeholderVerticalAlign = PlaceholderVerticalAlign.Center)) {
|
||||||
|
Spacer(modifier = Modifier.fillMaxWidth())
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
Text(text = labelText, inlineContent = inlineContent, modifier = modifier)
|
||||||
|
} else {
|
||||||
|
Text(label, modifier = modifier)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,14 @@ object Constants {
|
|||||||
@SuppressLint("SdCardPath")
|
@SuppressLint("SdCardPath")
|
||||||
const val GJ_DATA_DIR = "/data/data/${PACKAGE_NAME}"
|
const val GJ_DATA_DIR = "/data/data/${PACKAGE_NAME}"
|
||||||
|
|
||||||
const val SUPPORTED_VERSION_CODE = 38L
|
// anything below this version code is blocked from opening the game
|
||||||
const val SUPPORTED_VERSION_STRING = "2.205"
|
const val SUPPORTED_VERSION_CODE_MIN = 37L
|
||||||
|
|
||||||
|
// anything below this version code shows a warning on the main menu
|
||||||
|
const val SUPPORTED_VERSION_CODE_MIN_WARNING = 40L
|
||||||
|
|
||||||
|
// anything above this version code will show a warning when starting the game
|
||||||
|
const val SUPPORTED_VERSION_CODE = 40L
|
||||||
|
|
||||||
|
const val SUPPORTED_VERSION_STRING = "2.2.143"
|
||||||
}
|
}
|
||||||
@@ -2,26 +2,71 @@ package com.geode.launcher.utils
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import kotlin.math.ceil
|
||||||
|
import kotlin.math.floor
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class ConstrainedFrameLayout(context: Context) : FrameLayout(context) {
|
class ConstrainedFrameLayout(context: Context) : FrameLayout(context) {
|
||||||
// avoid running the aspect ratio fix when we don't need it
|
// avoid running the aspect ratio fix when we don't need it
|
||||||
var aspectRatio: Float? = null;
|
var aspectRatio: Float? = null
|
||||||
|
var zoom: Float? = null
|
||||||
|
var fitZoom: Boolean = false
|
||||||
|
|
||||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
if (aspectRatio != null) {
|
var paddingX = 0.0f
|
||||||
|
var paddingY = 0.0f
|
||||||
|
|
||||||
|
val currentZoom = zoom
|
||||||
|
if (currentZoom != null) {
|
||||||
val width = MeasureSpec.getSize(widthMeasureSpec)
|
val width = MeasureSpec.getSize(widthMeasureSpec)
|
||||||
val height = MeasureSpec.getSize(heightMeasureSpec)
|
val height = MeasureSpec.getSize(heightMeasureSpec)
|
||||||
if (width == 0 || height == 0) {
|
if (width == 0 || height == 0) {
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val calculatedWidth = height * (aspectRatio ?: 1.0f);
|
val calculatedWidth = width * currentZoom
|
||||||
val padding = ((width - calculatedWidth) / 2).toInt()
|
val calculatedHeight = height * currentZoom
|
||||||
|
|
||||||
// ignore paddings where the screen ends up looking odd
|
paddingX = (width - calculatedWidth)/2
|
||||||
if (padding > 0) {
|
paddingY = (height - calculatedHeight)/2
|
||||||
setPadding(padding, 0, padding, 0)
|
}
|
||||||
|
|
||||||
|
val currentAspectRatio = aspectRatio
|
||||||
|
if (currentAspectRatio != null) {
|
||||||
|
val width = MeasureSpec.getSize(widthMeasureSpec)
|
||||||
|
val height = MeasureSpec.getSize(heightMeasureSpec)
|
||||||
|
if (width == 0 || height == 0) {
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val calculatedWidth = (height - paddingY * 2) * currentAspectRatio
|
||||||
|
val padding = (width - calculatedWidth) / 2
|
||||||
|
|
||||||
|
paddingX = padding
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paddingX > 0.0 || paddingY > 0.0) {
|
||||||
|
if (fitZoom) {
|
||||||
|
val width = MeasureSpec.getSize(widthMeasureSpec)
|
||||||
|
val height = MeasureSpec.getSize(heightMeasureSpec)
|
||||||
|
|
||||||
|
val calculatedHeight = (height - paddingY * 2)
|
||||||
|
val calculatedWidth = (width - paddingX * 2)
|
||||||
|
|
||||||
|
val zoomFactor = min(height / calculatedHeight, width / calculatedWidth)
|
||||||
|
|
||||||
|
scaleX = zoomFactor
|
||||||
|
scaleY = zoomFactor
|
||||||
|
}
|
||||||
|
|
||||||
|
setPadding(
|
||||||
|
ceil(paddingX).toInt(),
|
||||||
|
ceil(paddingY).toInt(),
|
||||||
|
floor(paddingX).toInt(),
|
||||||
|
floor(paddingY).toInt()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onMeasure(
|
super.onMeasure(
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ object GamePackageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showDownloadBadge(packageManager: PackageManager) =
|
||||||
|
!isGameInstalled(packageManager) || !identifyGameLegitimacy(packageManager)
|
||||||
|
|
||||||
fun getGameVersionCode(packageManager: PackageManager): Long {
|
fun getGameVersionCode(packageManager: PackageManager): Long {
|
||||||
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)
|
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)
|
||||||
|
|
||||||
@@ -31,14 +34,24 @@ object GamePackageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getGameVersionCodeOrNull(packageManager: PackageManager): Long? {
|
||||||
|
return try {
|
||||||
|
getGameVersionCode(packageManager)
|
||||||
|
} catch (e: PackageManager.NameNotFoundException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getGameVersionString(packageManager: PackageManager): String {
|
fun getGameVersionString(packageManager: PackageManager): String {
|
||||||
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)
|
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)
|
||||||
return game.versionName
|
return game.versionName ?: "0.000"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val gameVersionMap = mapOf(
|
private val gameVersionMap = mapOf(
|
||||||
37L to "2.200",
|
37L to "2.200",
|
||||||
38L to "2.205"
|
38L to "2.205",
|
||||||
|
39L to "2.206",
|
||||||
|
40L to "2.2074" // ok
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,8 +65,8 @@ object GamePackageUtils {
|
|||||||
fun detectAbiMismatch(context: Context, packageInfo: PackageInfo, loadException: Error): Boolean {
|
fun detectAbiMismatch(context: Context, packageInfo: PackageInfo, loadException: Error): Boolean {
|
||||||
val abi = LaunchUtils.applicationArchitecture
|
val abi = LaunchUtils.applicationArchitecture
|
||||||
val isExtracted =
|
val isExtracted =
|
||||||
packageInfo.applicationInfo.flags and ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS == ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS
|
packageInfo.applicationInfo!!.flags and ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS == ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS
|
||||||
val isSplit = (packageInfo.applicationInfo.splitSourceDirs?.size ?: 0) > 1
|
val isSplit = (packageInfo.applicationInfo?.splitSourceDirs?.size ?: 0) > 1
|
||||||
|
|
||||||
val metadata =
|
val metadata =
|
||||||
"Geometry Dash metadata:\nSplit sources: $isSplit\nExtracted libraries: $isExtracted\nLauncher architecture: $abi"
|
"Geometry Dash metadata:\nSplit sources: $isSplit\nExtracted libraries: $isExtracted\nLauncher architecture: $abi"
|
||||||
@@ -73,7 +86,7 @@ object GamePackageUtils {
|
|||||||
val oppositeArchitecture = if (abi == "arm64-v8a") "armeabi-v7a" else "arm64-v8a"
|
val oppositeArchitecture = if (abi == "arm64-v8a") "armeabi-v7a" else "arm64-v8a"
|
||||||
|
|
||||||
// detect issues using native library directory (only works on extracted libraries)
|
// detect issues using native library directory (only works on extracted libraries)
|
||||||
val nativeLibraryDir = packageInfo.applicationInfo.nativeLibraryDir
|
val nativeLibraryDir = packageInfo.applicationInfo!!.nativeLibraryDir
|
||||||
|
|
||||||
if (nativeLibraryDir.contains(oppositeArchitecture)) {
|
if (nativeLibraryDir.contains(oppositeArchitecture)) {
|
||||||
return true
|
return true
|
||||||
@@ -104,31 +117,47 @@ object GamePackageUtils {
|
|||||||
val clazz = assetManager.javaClass
|
val clazz = assetManager.javaClass
|
||||||
val aspMethod = clazz.getDeclaredMethod("addAssetPath", String::class.java)
|
val aspMethod = clazz.getDeclaredMethod("addAssetPath", String::class.java)
|
||||||
|
|
||||||
aspMethod.invoke(assetManager, packageInfo.applicationInfo.sourceDir)
|
aspMethod.invoke(assetManager, packageInfo.applicationInfo?.sourceDir)
|
||||||
packageInfo.applicationInfo.splitSourceDirs?.forEach {
|
packageInfo.applicationInfo?.splitSourceDirs?.forEach {
|
||||||
aspMethod.invoke(assetManager, it)
|
aspMethod.invoke(assetManager, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val GAME_CERTIFICATE_HASH = "f5e7d8284d72c461a5f022d0cf755df101c3bb1e69cbe241bc1aef2cc5610a43"
|
private const val GAME_CERTIFICATE_HASH = "f5e7d8284d72c461a5f022d0cf755df101c3bb1e69cbe241bc1aef2cc5610a43"
|
||||||
|
private const val AMAZON_CERTIFICATE_HASH = "1f228081e4d66e006887d4ba0f3d40e96a80c758b84231f11cd5c1c9aef6048f"
|
||||||
|
|
||||||
private fun validateCertificate(certificate: ByteArray): Boolean =
|
private fun validateCertificate(certificate: ByteArray): GameSource = when (val hash = certificate.toByteString().sha256().hex()) {
|
||||||
certificate.toByteString().sha256().hex() == GAME_CERTIFICATE_HASH
|
GAME_CERTIFICATE_HASH -> GameSource.GOOGLE
|
||||||
|
AMAZON_CERTIFICATE_HASH -> GameSource.AMAZON
|
||||||
|
else -> {
|
||||||
|
println("Encountered certificate hash: $hash")
|
||||||
|
GameSource.UNKNOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun identifyGameLegitimacy(packageManager: PackageManager): Boolean {
|
enum class GameSource {
|
||||||
|
UNKNOWN, GOOGLE, AMAZON
|
||||||
|
}
|
||||||
|
|
||||||
|
fun identifyGameSource(packageManager: PackageManager): GameSource {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
val certificates = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
val certificates = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, PackageManager.GET_SIGNING_CERTIFICATES)
|
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, PackageManager.GET_SIGNING_CERTIFICATES)
|
||||||
val signingInfo = game.signingInfo
|
val signingInfo = game.signingInfo
|
||||||
|
|
||||||
signingInfo.signingCertificateHistory
|
signingInfo?.signingCertificateHistory ?: return GameSource.UNKNOWN
|
||||||
} else {
|
} else {
|
||||||
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, PackageManager.GET_SIGNATURES)
|
val game = packageManager.getPackageInfo(Constants.PACKAGE_NAME, PackageManager.GET_SIGNATURES)
|
||||||
game.signatures
|
game.signatures
|
||||||
}
|
}
|
||||||
|
|
||||||
return certificates.any {
|
return certificates?.map {
|
||||||
validateCertificate(it.toByteArray())
|
validateCertificate(it.toByteArray())
|
||||||
}
|
}?.firstOrNull {
|
||||||
|
it != GameSource.UNKNOWN
|
||||||
|
} ?: GameSource.UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun identifyGameLegitimacy(packageManager: PackageManager) =
|
||||||
|
identifyGameSource(packageManager) != GameSource.UNKNOWN
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,9 @@ import android.content.pm.PackageManager
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
|
import android.os.VibrationEffect
|
||||||
|
import android.os.Vibrator
|
||||||
|
import android.os.VibratorManager
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
import android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
|
import android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@@ -18,7 +21,9 @@ import androidx.activity.result.ActivityResultLauncher
|
|||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.browser.customtabs.CustomTabsIntent
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.net.toUri
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import com.geode.launcher.BuildConfig
|
import com.geode.launcher.BuildConfig
|
||||||
import com.geode.launcher.R
|
import com.geode.launcher.R
|
||||||
@@ -26,6 +31,7 @@ import com.geode.launcher.UserDirectoryProvider
|
|||||||
import com.geode.launcher.activityresult.GeodeOpenFileActivityResult
|
import com.geode.launcher.activityresult.GeodeOpenFileActivityResult
|
||||||
import com.geode.launcher.activityresult.GeodeOpenFilesActivityResult
|
import com.geode.launcher.activityresult.GeodeOpenFilesActivityResult
|
||||||
import com.geode.launcher.activityresult.GeodeSaveFileActivityResult
|
import com.geode.launcher.activityresult.GeodeSaveFileActivityResult
|
||||||
|
import org.cocos2dx.lib.Cocos2dxGLSurfaceView
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
@@ -34,6 +40,8 @@ import kotlin.system.exitProcess
|
|||||||
@Suppress("unused", "KotlinJniMissingFunction")
|
@Suppress("unused", "KotlinJniMissingFunction")
|
||||||
object GeodeUtils {
|
object GeodeUtils {
|
||||||
private lateinit var activity: WeakReference<AppCompatActivity>
|
private lateinit var activity: WeakReference<AppCompatActivity>
|
||||||
|
var handleSafeArea: Boolean = false
|
||||||
|
|
||||||
private lateinit var openFileResultLauncher: ActivityResultLauncher<GeodeOpenFileActivityResult.OpenFileParams>
|
private lateinit var openFileResultLauncher: ActivityResultLauncher<GeodeOpenFileActivityResult.OpenFileParams>
|
||||||
private lateinit var openDirectoryResultLauncher: ActivityResultLauncher<Uri?>
|
private lateinit var openDirectoryResultLauncher: ActivityResultLauncher<Uri?>
|
||||||
private lateinit var openFilesResultLauncher: ActivityResultLauncher<GeodeOpenFilesActivityResult.OpenFileParams>
|
private lateinit var openFilesResultLauncher: ActivityResultLauncher<GeodeOpenFilesActivityResult.OpenFileParams>
|
||||||
@@ -54,20 +62,37 @@ object GeodeUtils {
|
|||||||
selectFileCallback(path)
|
selectFileCallback(path)
|
||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Toast.makeText(activity, R.string.file_select_error, Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(activity, R.string.no_file_selected, Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
failedCallback()
|
failedCallback()
|
||||||
}
|
}
|
||||||
openDirectoryResultLauncher = activity.registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) {
|
openDirectoryResultLauncher = activity.registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) {
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
val path = FileUtils.getRealPathFromURI(activity, it)
|
val path = FileUtils.getRealPathFromURI(activity, it)
|
||||||
if (path != null)
|
if (path != null) {
|
||||||
selectFileCallback(path)
|
selectFileCallback(path)
|
||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
|
}
|
||||||
|
|
||||||
|
Toast.makeText(activity, R.string.file_select_error, Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(activity, R.string.no_file_selected, Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
failedCallback()
|
failedCallback()
|
||||||
}
|
}
|
||||||
openFilesResultLauncher = activity.registerForActivityResult(GeodeOpenFilesActivityResult()) { result ->
|
openFilesResultLauncher = activity.registerForActivityResult(GeodeOpenFilesActivityResult()) { result ->
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
|
Toast.makeText(activity, R.string.no_file_selected, Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
|
|
||||||
failedCallback()
|
failedCallback()
|
||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
}
|
}
|
||||||
@@ -88,6 +113,12 @@ object GeodeUtils {
|
|||||||
selectFileCallback(path)
|
selectFileCallback(path)
|
||||||
return@registerForActivityResult
|
return@registerForActivityResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Toast.makeText(activity, R.string.file_select_error, Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(activity, R.string.no_file_selected, Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
failedCallback()
|
failedCallback()
|
||||||
}
|
}
|
||||||
@@ -149,7 +180,7 @@ object GeodeUtils {
|
|||||||
val manager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
val manager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
val clip = manager.primaryClip
|
val clip = manager.primaryClip
|
||||||
if (clip != null && clip.itemCount > 0) {
|
if (clip != null && clip.itemCount > 0) {
|
||||||
return clip.getItemAt(0).text.toString()
|
return clip.getItemAt(0).coerceToText(this).toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
@@ -350,11 +381,6 @@ object GeodeUtils {
|
|||||||
return activity.filesDir.canonicalPath
|
return activity.filesDir.canonicalPath
|
||||||
}
|
}
|
||||||
|
|
||||||
private val gameVersionMap = mapOf(
|
|
||||||
37L to "2.200",
|
|
||||||
38L to "2.205"
|
|
||||||
)
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getGameVersion(): String {
|
fun getGameVersion(): String {
|
||||||
// these versions should be aligned to windows releases, not what android says
|
// these versions should be aligned to windows releases, not what android says
|
||||||
@@ -365,6 +391,14 @@ object GeodeUtils {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current version code of the launcher.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun getLauncherVersion(): Int {
|
||||||
|
return BuildConfig.VERSION_CODE
|
||||||
|
}
|
||||||
|
|
||||||
fun isGeodeUri(uri: Uri): Boolean {
|
fun isGeodeUri(uri: Uri): Boolean {
|
||||||
return "com.geode.launcher.user" == uri.authority
|
return "com.geode.launcher.user" == uri.authority
|
||||||
}
|
}
|
||||||
@@ -420,6 +454,64 @@ object GeodeUtils {
|
|||||||
|
|
||||||
private external fun permissionCallback(granted: Boolean)
|
private external fun permissionCallback(granted: Boolean)
|
||||||
|
|
||||||
|
internal fun getVibrator(): Vibrator? = activity.get()?.run {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
val manager = getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
||||||
|
manager.defaultVibrator
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// vibration
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If vibration is supported on the device.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun vibrateSupported(): Boolean = getVibrator()?.hasVibrator() == true
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vibrates for the given amount of time.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun vibrate(ms: Long) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
getVibrator()?.vibrate(VibrationEffect.createOneShot(ms, VibrationEffect.DEFAULT_AMPLITUDE))
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
getVibrator()?.vibrate(ms)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vibrates with the given pattern.
|
||||||
|
* @see android.os.VibrationEffect.createWaveform
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun vibratePattern(pattern: LongArray, repeat: Int) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
getVibrator()?.vibrate(VibrationEffect.createWaveform(pattern, repeat))
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
getVibrator()?.vibrate(pattern, repeat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getScreenInsets(): IntArray? {
|
||||||
|
if (!handleSafeArea || Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return activity.get()?.run {
|
||||||
|
val displayCutout = window.decorView.rootWindowInsets?.displayCutout ?: return null
|
||||||
|
|
||||||
|
intArrayOf(displayCutout.safeInsetLeft, displayCutout.safeInsetBottom, displayCutout.safeInsetRight, displayCutout.safeInsetTop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const val ARGUMENT_SAFE_MODE = "--geode:safe-mode"
|
const val ARGUMENT_SAFE_MODE = "--geode:safe-mode"
|
||||||
|
|
||||||
private var additionalLaunchArguments = arrayListOf<String>()
|
private var additionalLaunchArguments = arrayListOf<String>()
|
||||||
@@ -451,6 +543,7 @@ object GeodeUtils {
|
|||||||
|
|
||||||
const val CAPABILITY_EXTENDED_INPUT = "extended_input"
|
const val CAPABILITY_EXTENDED_INPUT = "extended_input"
|
||||||
const val CAPABILITY_TIMESTAMP_INPUT = "timestamp_inputs"
|
const val CAPABILITY_TIMESTAMP_INPUT = "timestamp_inputs"
|
||||||
|
const val CAPABILITY_INTERNAL_CALLBACKS = "internal_callbacks_v1"
|
||||||
|
|
||||||
private var capabilityListener: WeakReference<CapabilityListener?> = WeakReference(null)
|
private var capabilityListener: WeakReference<CapabilityListener?> = WeakReference(null)
|
||||||
|
|
||||||
@@ -458,13 +551,31 @@ object GeodeUtils {
|
|||||||
capabilityListener = WeakReference(listener)
|
capabilityListener = WeakReference(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports that the game client supports a feature.
|
||||||
|
* These features typically require callbacks into the game, so ensure that the required methods are registered first.
|
||||||
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun reportPlatformCapability(capability: String?): Boolean {
|
fun reportPlatformCapability(capability: String?): Boolean {
|
||||||
if (capability.isNullOrEmpty()) {
|
if (capability.isNullOrEmpty()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return capabilityListener.get()?.onCapabilityAdded(capability) ?: false
|
return capabilityListener.get()?.onCapabilityAdded(capability) == true
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun openWebview(url: String) {
|
||||||
|
val activity = activity.get() ?: return
|
||||||
|
CustomTabsIntent.Builder()
|
||||||
|
.setShowTitle(true)
|
||||||
|
.build()
|
||||||
|
.launchUrl(activity, url.toUri())
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun openMultilineIMEKeyboard() {
|
||||||
|
Cocos2dxGLSurfaceView.openMultilineIMEKeyboard()
|
||||||
}
|
}
|
||||||
|
|
||||||
external fun nativeKeyUp(keyCode: Int, modifiers: Int)
|
external fun nativeKeyUp(keyCode: Int, modifiers: Int)
|
||||||
@@ -472,6 +583,11 @@ object GeodeUtils {
|
|||||||
external fun nativeActionScroll(scrollX: Float, scrollY: Float)
|
external fun nativeActionScroll(scrollX: Float, scrollY: Float)
|
||||||
external fun resizeSurface(width: Int, height: Int)
|
external fun resizeSurface(width: Int, height: Int)
|
||||||
|
|
||||||
// represents the timestamp of the next input callback, in nanoseconds (most events don't send it, but it's there)
|
/**
|
||||||
|
* Gives the timestamp of the next input callback, in nanoseconds.
|
||||||
|
* Enable this by sending the "timestamp_inputs" platform capability.
|
||||||
|
* @see reportPlatformCapability
|
||||||
|
*/
|
||||||
external fun setNextInputTimestamp(timestamp: Long)
|
external fun setNextInputTimestamp(timestamp: Long)
|
||||||
|
external fun setNextInputTimestampInternal(timestamp: Long)
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.geode.launcher.utils
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
object LaunchUtils {
|
object LaunchUtils {
|
||||||
// supposedly CPU_ABI returns the current arch for the running application
|
// supposedly CPU_ABI returns the current arch for the running application
|
||||||
@@ -46,7 +47,7 @@ object LaunchUtils {
|
|||||||
/**
|
/**
|
||||||
* Returns the directory that Geode/the game should base itself off of.
|
* Returns the directory that Geode/the game should base itself off of.
|
||||||
*/
|
*/
|
||||||
fun getBaseDirectory(context: Context): File {
|
fun getBaseDirectory(context: Context, ignoreProfile: Boolean = false): File {
|
||||||
// deprecated, but seems to be the best choice of directory (i forced mat to test it)
|
// deprecated, but seems to be the best choice of directory (i forced mat to test it)
|
||||||
// also, is getting the first item the correct choice here?? what do they mean
|
// also, is getting the first item the correct choice here?? what do they mean
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@@ -57,6 +58,14 @@ object LaunchUtils {
|
|||||||
val noMediaPath = File(dir, ".nomedia")
|
val noMediaPath = File(dir, ".nomedia")
|
||||||
noMediaPath.createNewFile()
|
noMediaPath.createNewFile()
|
||||||
|
|
||||||
|
val currentProfile = ProfileManager.get(context).getCurrentProfile()
|
||||||
|
if (currentProfile != null && !ignoreProfile) {
|
||||||
|
val profile = File(dir, "profiles/$currentProfile/")
|
||||||
|
profile.mkdirs()
|
||||||
|
|
||||||
|
return profile
|
||||||
|
}
|
||||||
|
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,9 +101,10 @@ object LaunchUtils {
|
|||||||
return crashIndicatorFile.exists()
|
return crashIndicatorFile.exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class LauncherError {
|
enum class LauncherError : Serializable {
|
||||||
LINKER_NEEDS_64BIT,
|
LINKER_NEEDS_64BIT,
|
||||||
LINKER_NEEDS_32BIT,
|
LINKER_NEEDS_32BIT,
|
||||||
|
LINKER_FAILED_STL,
|
||||||
LINKER_FAILED,
|
LINKER_FAILED,
|
||||||
GENERIC,
|
GENERIC,
|
||||||
CRASHED;
|
CRASHED;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import androidx.compose.runtime.MutableState
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleEventObserver
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
@@ -20,8 +20,6 @@ import com.geode.launcher.BuildConfig
|
|||||||
*/
|
*/
|
||||||
class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val FILE_KEY = "GeodeLauncherPreferencesFileKey"
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun useBooleanPreference(preferenceKey: Key, lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current): MutableState<Boolean> {
|
fun useBooleanPreference(preferenceKey: Key, lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current): MutableState<Boolean> {
|
||||||
return usePreference(
|
return usePreference(
|
||||||
@@ -70,11 +68,14 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
|||||||
preferenceSet: (PreferenceUtils, Key, T) -> Unit
|
preferenceSet: (PreferenceUtils, Key, T) -> Unit
|
||||||
): MutableState<T> {
|
): MutableState<T> {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val sharedPreferences = context.getSharedPreferences(FILE_KEY, Context.MODE_PRIVATE)
|
|
||||||
|
val currentProfile = remember { ProfileManager.get(context).getCurrentFileKey() }
|
||||||
|
val sharedPreferences = context.getSharedPreferences(currentProfile, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
val preferences = get(sharedPreferences)
|
val preferences = get(sharedPreferences)
|
||||||
|
|
||||||
val preferenceValue = remember {
|
// inferring the type causes an internal compiler error. lol
|
||||||
|
val preferenceValue: MutableState<T> = remember {
|
||||||
val state = mutableStateOf(preferenceGet(preferences, preferenceKey))
|
val state = mutableStateOf(preferenceGet(preferences, preferenceKey))
|
||||||
object : MutableState<T> by state {
|
object : MutableState<T> by state {
|
||||||
override var value: T
|
override var value: T
|
||||||
@@ -113,7 +114,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun get(context: Context): PreferenceUtils {
|
fun get(context: Context): PreferenceUtils {
|
||||||
val sharedPreferences = context.getSharedPreferences(FILE_KEY, Context.MODE_PRIVATE)
|
val currentFileKey = ProfileManager.get(context).getCurrentFileKey()
|
||||||
|
val sharedPreferences = context.getSharedPreferences(currentFileKey, Context.MODE_PRIVATE)
|
||||||
return get(sharedPreferences)
|
return get(sharedPreferences)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,22 +137,41 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
|||||||
DISMISSED_GJ_UPDATE,
|
DISMISSED_GJ_UPDATE,
|
||||||
LAUNCH_ARGUMENTS,
|
LAUNCH_ARGUMENTS,
|
||||||
LIMIT_ASPECT_RATIO,
|
LIMIT_ASPECT_RATIO,
|
||||||
DISPLAY_MODE
|
DISPLAY_MODE,
|
||||||
|
FORCE_HRR,
|
||||||
|
ENABLE_REDESIGN,
|
||||||
|
RELEASE_CHANNEL_TAG,
|
||||||
|
DEVELOPER_MODE,
|
||||||
|
CLEANUP_APKS,
|
||||||
|
CUSTOM_SYMBOL_LIST,
|
||||||
|
CUSTOM_ASPECT_RATIO,
|
||||||
|
SCREEN_ZOOM,
|
||||||
|
SCREEN_ZOOM_FIT,
|
||||||
|
LIMIT_FRAME_RATE,
|
||||||
|
USE_INDEX_API,
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun defaultValueForBooleanKey(key: Key): Boolean {
|
private fun defaultValueForBooleanKey(key: Key): Boolean {
|
||||||
return when (key) {
|
return when (key) {
|
||||||
Key.UPDATE_AUTOMATICALLY -> true
|
Key.UPDATE_AUTOMATICALLY, Key.FORCE_HRR -> true
|
||||||
Key.RELEASE_CHANNEL -> BuildConfig.DEBUG
|
Key.DEVELOPER_MODE -> BuildConfig.DEBUG
|
||||||
|
Key.USE_INDEX_API -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun defaultValueForIntKey(key: Key) = when (key) {
|
private fun defaultValueForIntKey(key: Key) = when (key) {
|
||||||
Key.DISPLAY_MODE -> if (this.getBoolean(Key.LIMIT_ASPECT_RATIO)) 1 else 0
|
Key.DISPLAY_MODE -> if (this.getBoolean(Key.LIMIT_ASPECT_RATIO)) 1 else 0
|
||||||
|
Key.SCREEN_ZOOM -> 100
|
||||||
|
// people wanted a reset on nightly anyways, so this is a good excuse to do so
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun defaultValueForStringKey(key: Key) = when (key) {
|
||||||
|
Key.CUSTOM_ASPECT_RATIO -> "16_9"
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
private fun keyToName(key: Key): String {
|
private fun keyToName(key: Key): String {
|
||||||
return when (key) {
|
return when (key) {
|
||||||
Key.LOAD_AUTOMATICALLY -> "PreferenceLoadAutomatically"
|
Key.LOAD_AUTOMATICALLY -> "PreferenceLoadAutomatically"
|
||||||
@@ -166,6 +187,17 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
|||||||
Key.LAUNCH_ARGUMENTS -> "PreferenceLaunchArguments"
|
Key.LAUNCH_ARGUMENTS -> "PreferenceLaunchArguments"
|
||||||
Key.LIMIT_ASPECT_RATIO -> "PreferenceLimitAspectRatio"
|
Key.LIMIT_ASPECT_RATIO -> "PreferenceLimitAspectRatio"
|
||||||
Key.DISPLAY_MODE -> "PreferenceDisplayMode"
|
Key.DISPLAY_MODE -> "PreferenceDisplayMode"
|
||||||
|
Key.FORCE_HRR -> "PreferenceForceHighRefreshRate"
|
||||||
|
Key.ENABLE_REDESIGN -> "PreferenceEnableRedesign"
|
||||||
|
Key.RELEASE_CHANNEL_TAG -> "PreferenceReleaseChannelTag"
|
||||||
|
Key.DEVELOPER_MODE -> "PreferenceDeveloperMode"
|
||||||
|
Key.CLEANUP_APKS -> "PreferenceCleanupPackages"
|
||||||
|
Key.CUSTOM_SYMBOL_LIST -> "PreferenceCustomSymbolList"
|
||||||
|
Key.CUSTOM_ASPECT_RATIO -> "PreferenceCustomAspectRatio"
|
||||||
|
Key.SCREEN_ZOOM -> "PreferenceScreenZoom"
|
||||||
|
Key.SCREEN_ZOOM_FIT -> "PreferenceScreenZoomFit"
|
||||||
|
Key.LIMIT_FRAME_RATE -> "PreferenceLimitFrameRate"
|
||||||
|
Key.USE_INDEX_API -> "PreferenceUseIndexApi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +228,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
|||||||
|
|
||||||
fun getString(key: Key): String? {
|
fun getString(key: Key): String? {
|
||||||
val keyName = keyToName(key)
|
val keyName = keyToName(key)
|
||||||
return sharedPreferences.getString(keyName, null)
|
return sharedPreferences.getString(keyName, defaultValueForStringKey(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setString(key: Key, value: String?) {
|
fun setString(key: Key, value: String?) {
|
||||||
|
|||||||
@@ -0,0 +1,133 @@
|
|||||||
|
package com.geode.launcher.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
|
private const val FILE_KEY = "GeodeLauncherPreferencesFileKey"
|
||||||
|
private const val PROFILES_FILE_KEY = "GeodeLauncherProfiles"
|
||||||
|
|
||||||
|
private const val PROFILE_LIST_SAVE_KEY = "profiles"
|
||||||
|
private const val PROFILE_CURRENT_SAVE_KEY = "currentProfile"
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Profile(val path: String, val name: String)
|
||||||
|
|
||||||
|
class ProfileManager {
|
||||||
|
private val applicationContext: Context
|
||||||
|
private val preferences: SharedPreferences
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private lateinit var managerInstance: ProfileManager
|
||||||
|
|
||||||
|
fun get(context: Context): ProfileManager {
|
||||||
|
if (!Companion::managerInstance.isInitialized) {
|
||||||
|
val applicationContext = context.applicationContext
|
||||||
|
|
||||||
|
managerInstance = ProfileManager(applicationContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
return managerInstance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(applicationContext: Context) {
|
||||||
|
this.applicationContext = applicationContext
|
||||||
|
this.preferences = applicationContext.getSharedPreferences(PROFILES_FILE_KEY, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
_storedProfiles.value = getProfiles()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val _storedProfiles = MutableStateFlow<List<Profile>>(emptyList())
|
||||||
|
val storedProfiles = _storedProfiles.asStateFlow()
|
||||||
|
|
||||||
|
fun getCurrentProfile(): String? {
|
||||||
|
return preferences.getString(PROFILE_CURRENT_SAVE_KEY, null)
|
||||||
|
.takeUnless { it.isNullOrEmpty() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getCurrentFileKey(): String {
|
||||||
|
val currentProfile = getCurrentProfile()
|
||||||
|
?: return FILE_KEY
|
||||||
|
|
||||||
|
return "${FILE_KEY}_${currentProfile}"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getProfile(path: String): Profile? {
|
||||||
|
val profilesSet = preferences.getStringSet(PROFILE_LIST_SAVE_KEY, null)
|
||||||
|
return profilesSet?.firstNotNullOfOrNull {
|
||||||
|
Json.decodeFromString<Profile>(it).takeIf { it.path == path }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a profile into the save, removing any duplicate profiles beforehand
|
||||||
|
*/
|
||||||
|
fun storeProfile(profile: Profile) {
|
||||||
|
val profilesSet = preferences.getStringSet(PROFILE_LIST_SAVE_KEY, null) ?: emptySet<String>()
|
||||||
|
|
||||||
|
val removedList = profilesSet.filterTo(LinkedHashSet()) {
|
||||||
|
val saveProfile = Json.decodeFromString<Profile>(it)
|
||||||
|
saveProfile.path != profile.path
|
||||||
|
}
|
||||||
|
removedList.add(Json.encodeToString(profile))
|
||||||
|
|
||||||
|
preferences.edit {
|
||||||
|
putStringSet(PROFILE_LIST_SAVE_KEY, removedList)
|
||||||
|
}
|
||||||
|
|
||||||
|
_storedProfiles.value = getProfiles()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteProfile(path: String) {
|
||||||
|
val profilesSet = preferences.getStringSet(PROFILE_LIST_SAVE_KEY, null) ?: emptySet<String>()
|
||||||
|
|
||||||
|
val removedList = profilesSet.filterTo(LinkedHashSet()) {
|
||||||
|
val saveProfile = Json.decodeFromString<Profile>(it)
|
||||||
|
saveProfile.path != path
|
||||||
|
}
|
||||||
|
|
||||||
|
preferences.edit {
|
||||||
|
putStringSet(PROFILE_LIST_SAVE_KEY, removedList)
|
||||||
|
}
|
||||||
|
|
||||||
|
_storedProfiles.value = getProfiles()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteProfiles(paths: List<String>) {
|
||||||
|
val profilesSet = preferences.getStringSet(PROFILE_LIST_SAVE_KEY, null) ?: emptySet<String>()
|
||||||
|
|
||||||
|
val removedList = profilesSet.filterTo(LinkedHashSet()) {
|
||||||
|
val saveProfile = Json.decodeFromString<Profile>(it)
|
||||||
|
!paths.contains(saveProfile.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
preferences.edit(commit = true) {
|
||||||
|
putStringSet(PROFILE_LIST_SAVE_KEY, removedList)
|
||||||
|
}
|
||||||
|
|
||||||
|
_storedProfiles.value = getProfiles()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setCurrentProfile(profile: String?) {
|
||||||
|
preferences.edit(commit = true) {
|
||||||
|
if (profile.isNullOrEmpty()) {
|
||||||
|
remove(PROFILE_CURRENT_SAVE_KEY)
|
||||||
|
} else {
|
||||||
|
putString(PROFILE_CURRENT_SAVE_KEY, profile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getProfiles(): List<Profile> {
|
||||||
|
val profilesSet = preferences.getStringSet(PROFILE_LIST_SAVE_KEY, null) ?: emptySet<String>()
|
||||||
|
|
||||||
|
return profilesSet.map {
|
||||||
|
Json.decodeFromString<Profile>(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.geode.launcher.utils
|
package com.geode.launcher.utils
|
||||||
|
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleEventObserver
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2010-2011 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
package org.cocos2dx.lib
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import android.hardware.Sensor
|
||||||
|
import android.hardware.SensorEvent
|
||||||
|
import android.hardware.SensorEventListener
|
||||||
|
import android.hardware.SensorManager
|
||||||
|
import android.os.Build
|
||||||
|
import android.view.Surface
|
||||||
|
import android.view.WindowManager
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
class Cocos2dxAccelerometer : SensorEventListener {
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
external fun onSensorChanged(pX: Float, pY: Float, pZ: Float, pTimestamp: Long)
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(context: Context) {
|
||||||
|
mContext = WeakReference(context)
|
||||||
|
mSensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||||
|
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
|
||||||
|
val display = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
context.display
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay
|
||||||
|
}
|
||||||
|
this.mNaturalOrientation = display.rotation
|
||||||
|
}
|
||||||
|
|
||||||
|
private val mContext: WeakReference<Context>
|
||||||
|
private val mSensorManager: SensorManager
|
||||||
|
private val mAccelerometer: Sensor?
|
||||||
|
private val mNaturalOrientation: Int
|
||||||
|
|
||||||
|
fun enable() {
|
||||||
|
this.mSensorManager.registerListener(this, this.mAccelerometer, SensorManager.SENSOR_DELAY_GAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setInterval(interval: Float) {
|
||||||
|
this.mSensorManager.registerListener(this, this.mAccelerometer, (interval * 100000).roundToInt())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun disable() {
|
||||||
|
this.mSensorManager.unregisterListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSensorChanged(pSensorEvent: SensorEvent) {
|
||||||
|
if (pSensorEvent.sensor.type != Sensor.TYPE_ACCELEROMETER) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var (x, y, z) = pSensorEvent.values
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Because the axes are not swapped when the device's screen orientation
|
||||||
|
* changes. So we should swap it here. In tablets such as Motorola Xoom,
|
||||||
|
* the default orientation is landscape, so should consider this.
|
||||||
|
*/
|
||||||
|
val orientation = this.mContext.get()!!.resources.configuration.orientation
|
||||||
|
|
||||||
|
if ((orientation == Configuration.ORIENTATION_LANDSCAPE) && (this.mNaturalOrientation != Surface.ROTATION_0)) {
|
||||||
|
val tmp = x
|
||||||
|
x = -y
|
||||||
|
y = tmp
|
||||||
|
} else if ((orientation == Configuration.ORIENTATION_PORTRAIT) && (this.mNaturalOrientation != Surface.ROTATION_0)) {
|
||||||
|
val tmp = x
|
||||||
|
x = y
|
||||||
|
y = -tmp
|
||||||
|
}
|
||||||
|
|
||||||
|
Cocos2dxGLSurfaceView.queueAccelerometer(x, y, z, pSensorEvent.timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAccuracyChanged(pSensor: Sensor, pAccuracy: Int) {}
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package org.cocos2dx.lib
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.view.KeyEvent
|
|
||||||
import androidx.appcompat.widget.AppCompatEditText
|
|
||||||
|
|
||||||
class Cocos2dxEditText(context: Context) : AppCompatEditText(context) {
|
|
||||||
var cocos2dxGLSurfaceView: Cocos2dxGLSurfaceView? = null
|
|
||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, keyEvent: KeyEvent): Boolean {
|
|
||||||
super.onKeyDown(keyCode, keyEvent)
|
|
||||||
if (keyCode != KeyEvent.KEYCODE_BACK) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
cocos2dxGLSurfaceView?.requestFocus()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,27 @@
|
|||||||
package org.cocos2dx.lib
|
package org.cocos2dx.lib
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.opengl.GLSurfaceView
|
import android.opengl.GLSurfaceView
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.Message
|
import android.os.Message
|
||||||
|
import android.text.InputType
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
import android.view.Surface
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.appcompat.widget.AppCompatEditText
|
||||||
import com.customRobTop.BaseRobTopActivity
|
import com.customRobTop.BaseRobTopActivity
|
||||||
import com.geode.launcher.utils.GeodeUtils
|
import com.geode.launcher.utils.GeodeUtils
|
||||||
|
|
||||||
private const val HANDLER_OPEN_IME_KEYBOARD = 2
|
private const val HANDLER_OPEN_IME_KEYBOARD = 2
|
||||||
private const val HANDLER_CLOSE_IME_KEYBOARD = 3
|
private const val HANDLER_CLOSE_IME_KEYBOARD = 3
|
||||||
|
private const val HANDLER_ARG_MULTILINE = 1
|
||||||
|
private const val HANDLER_ARG_SINGLELINE = 0
|
||||||
private const val MS_TO_NS = 1_000_000
|
private const val MS_TO_NS = 1_000_000
|
||||||
|
|
||||||
class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||||
@@ -23,11 +30,22 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
private lateinit var handler: Handler
|
private lateinit var handler: Handler
|
||||||
private lateinit var cocos2dxTextInputWrapper: Cocos2dxTextInputWrapper
|
private lateinit var cocos2dxTextInputWrapper: Cocos2dxTextInputWrapper
|
||||||
|
|
||||||
|
fun openMultilineIMEKeyboard() {
|
||||||
|
val msg = Message().apply {
|
||||||
|
what = HANDLER_OPEN_IME_KEYBOARD
|
||||||
|
obj = cocos2dxGLSurfaceView.getContentText()
|
||||||
|
arg1 = HANDLER_ARG_MULTILINE
|
||||||
|
}
|
||||||
|
handler.sendMessage(msg)
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun openIMEKeyboard() {
|
fun openIMEKeyboard() {
|
||||||
val msg = Message()
|
val msg = Message().apply {
|
||||||
msg.what = HANDLER_OPEN_IME_KEYBOARD
|
what = HANDLER_OPEN_IME_KEYBOARD
|
||||||
msg.obj = cocos2dxGLSurfaceView.getContentText()
|
obj = cocos2dxGLSurfaceView.getContentText()
|
||||||
|
arg1 = HANDLER_ARG_SINGLELINE
|
||||||
|
}
|
||||||
handler.sendMessage(msg)
|
handler.sendMessage(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +55,11 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
msg.what = HANDLER_CLOSE_IME_KEYBOARD
|
msg.what = HANDLER_CLOSE_IME_KEYBOARD
|
||||||
handler.sendMessage(msg)
|
handler.sendMessage(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun queueAccelerometer(x: Float, y: Float, z: Float, timestamp: Long) =
|
||||||
|
cocos2dxGLSurfaceView.queueEvent {
|
||||||
|
Cocos2dxAccelerometer.onSensorChanged(x, y, z, timestamp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var cocos2dxRenderer: Cocos2dxRenderer
|
private lateinit var cocos2dxRenderer: Cocos2dxRenderer
|
||||||
@@ -47,22 +70,33 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var sendTimestampEvents = false
|
var sendTimestampEvents = false
|
||||||
|
var sendInternalTimestampEvents = false
|
||||||
|
var manualBackEvents = false
|
||||||
|
|
||||||
var cocos2dxEditText: Cocos2dxEditText? = null
|
var cocos2dxEditText: AppCompatEditText? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
|
|
||||||
field?.setOnEditorActionListener(cocos2dxTextInputWrapper)
|
field?.setOnEditorActionListener(cocos2dxTextInputWrapper)
|
||||||
field?.cocos2dxGLSurfaceView = this
|
|
||||||
requestFocus()
|
requestFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setKeyboardMultiline() {
|
||||||
|
val editText = cocos2dxEditText ?: return
|
||||||
|
editText.inputType = editText.inputType or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
||||||
|
editText.maxLines = Int.MAX_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setKeyboardSingleLine() {
|
||||||
|
val editText = cocos2dxEditText ?: return
|
||||||
|
editText.inputType = editText.inputType and InputType.TYPE_TEXT_FLAG_MULTI_LINE.inv()
|
||||||
|
editText.maxLines = 1
|
||||||
|
}
|
||||||
|
|
||||||
fun initView() {
|
fun initView() {
|
||||||
setEGLContextClientVersion(2)
|
setEGLContextClientVersion(2)
|
||||||
isFocusableInTouchMode = true
|
isFocusableInTouchMode = true
|
||||||
// if (Build.VERSION.SDK_INT >= 11) {
|
|
||||||
preserveEGLContextOnPause = true
|
preserveEGLContextOnPause = true
|
||||||
// }
|
|
||||||
cocos2dxGLSurfaceView = this
|
cocos2dxGLSurfaceView = this
|
||||||
cocos2dxTextInputWrapper = Cocos2dxTextInputWrapper(this)
|
cocos2dxTextInputWrapper = Cocos2dxTextInputWrapper(this)
|
||||||
Cocos2dxGLSurfaceView.handler = object : Handler(Looper.getMainLooper()) {
|
Cocos2dxGLSurfaceView.handler = object : Handler(Looper.getMainLooper()) {
|
||||||
@@ -70,6 +104,12 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
when (msg.what) {
|
when (msg.what) {
|
||||||
HANDLER_OPEN_IME_KEYBOARD -> {
|
HANDLER_OPEN_IME_KEYBOARD -> {
|
||||||
if (cocos2dxEditText?.requestFocus() == true) {
|
if (cocos2dxEditText?.requestFocus() == true) {
|
||||||
|
if (msg.arg1 == HANDLER_ARG_MULTILINE) {
|
||||||
|
setKeyboardMultiline()
|
||||||
|
} else {
|
||||||
|
setKeyboardSingleLine()
|
||||||
|
}
|
||||||
|
|
||||||
cocos2dxEditText?.apply {
|
cocos2dxEditText?.apply {
|
||||||
removeTextChangedListener(
|
removeTextChangedListener(
|
||||||
cocos2dxTextInputWrapper
|
cocos2dxTextInputWrapper
|
||||||
@@ -113,16 +153,44 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
|
fun updateRefreshRate() {
|
||||||
|
val chosenDisplay = display.supportedModes?.maxByOrNull { it.refreshRate }
|
||||||
|
if (chosenDisplay == null) {
|
||||||
|
println("updateRefreshRate failed to find a display to maximize refresh rate...")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val chosenRefreshRate = chosenDisplay.refreshRate
|
||||||
|
|
||||||
|
println("updateRefreshRate: selecting refresh rate of ${chosenDisplay.refreshRate} (display ${chosenDisplay.modeId})")
|
||||||
|
|
||||||
|
holder.surface.setFrameRate(chosenRefreshRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT)
|
||||||
|
if (isAttachedToWindow) {
|
||||||
|
(context as Activity).window.attributes.preferredRefreshRate = chosenRefreshRate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
queueEvent { cocos2dxRenderer.handleOnPause() }
|
queueEvent { cocos2dxRenderer.handleOnPause() }
|
||||||
|
renderMode = RENDERMODE_WHEN_DIRTY
|
||||||
super.onPause()
|
super.onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
renderMode = RENDERMODE_CONTINUOUSLY
|
||||||
queueEvent { cocos2dxRenderer.handleOnResume() }
|
queueEvent { cocos2dxRenderer.handleOnResume() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun sendNextEventTimestamp(timestamp: Long) {
|
||||||
|
if (sendTimestampEvents)
|
||||||
|
GeodeUtils.setNextInputTimestamp(timestamp)
|
||||||
|
|
||||||
|
if (sendInternalTimestampEvents)
|
||||||
|
GeodeUtils.setNextInputTimestampInternal(timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onTouchEvent(motionEvent: MotionEvent): Boolean {
|
override fun onTouchEvent(motionEvent: MotionEvent): Boolean {
|
||||||
val pointerNumber = motionEvent.pointerCount
|
val pointerNumber = motionEvent.pointerCount
|
||||||
val ids = IntArray(pointerNumber)
|
val ids = IntArray(pointerNumber)
|
||||||
@@ -142,9 +210,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
val xDown = xs[0]
|
val xDown = xs[0]
|
||||||
val f = ys[0]
|
val f = ys[0]
|
||||||
queueEvent {
|
queueEvent {
|
||||||
if (sendTimestampEvents)
|
sendNextEventTimestamp(timestamp)
|
||||||
GeodeUtils.setNextInputTimestamp(timestamp)
|
|
||||||
|
|
||||||
cocos2dxRenderer.handleActionDown(idDown, xDown, f)
|
cocos2dxRenderer.handleActionDown(idDown, xDown, f)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@@ -154,27 +220,21 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
val f2 = xs[0]
|
val f2 = xs[0]
|
||||||
val f3 = ys[0]
|
val f3 = ys[0]
|
||||||
queueEvent {
|
queueEvent {
|
||||||
if (sendTimestampEvents)
|
sendNextEventTimestamp(timestamp)
|
||||||
GeodeUtils.setNextInputTimestamp(timestamp)
|
|
||||||
|
|
||||||
cocos2dxRenderer.handleActionUp(idUp, f2, f3)
|
cocos2dxRenderer.handleActionUp(idUp, f2, f3)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_MOVE -> {
|
MotionEvent.ACTION_MOVE -> {
|
||||||
queueEvent {
|
queueEvent {
|
||||||
if (sendTimestampEvents)
|
sendNextEventTimestamp(timestamp)
|
||||||
GeodeUtils.setNextInputTimestamp(timestamp)
|
|
||||||
|
|
||||||
cocos2dxRenderer.handleActionMove(ids, xs, ys)
|
cocos2dxRenderer.handleActionMove(ids, xs, ys)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_CANCEL -> {
|
MotionEvent.ACTION_CANCEL -> {
|
||||||
queueEvent {
|
queueEvent {
|
||||||
if (sendTimestampEvents)
|
sendNextEventTimestamp(timestamp)
|
||||||
GeodeUtils.setNextInputTimestamp(timestamp)
|
|
||||||
|
|
||||||
cocos2dxRenderer.handleActionCancel(ids, xs, ys)
|
cocos2dxRenderer.handleActionCancel(ids, xs, ys)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@@ -185,9 +245,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
val xPointerDown = motionEvent.getX(indexPointerDown)
|
val xPointerDown = motionEvent.getX(indexPointerDown)
|
||||||
val y = motionEvent.getY(indexPointerDown)
|
val y = motionEvent.getY(indexPointerDown)
|
||||||
queueEvent {
|
queueEvent {
|
||||||
if (sendTimestampEvents)
|
sendNextEventTimestamp(timestamp)
|
||||||
GeodeUtils.setNextInputTimestamp(timestamp)
|
|
||||||
|
|
||||||
cocos2dxRenderer.handleActionDown(idPointerDown, xPointerDown, y)
|
cocos2dxRenderer.handleActionDown(idPointerDown, xPointerDown, y)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@@ -198,9 +256,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
val xPointerUp = motionEvent.getX(indexPointUp)
|
val xPointerUp = motionEvent.getX(indexPointUp)
|
||||||
val y2 = motionEvent.getY(indexPointUp)
|
val y2 = motionEvent.getY(indexPointUp)
|
||||||
queueEvent {
|
queueEvent {
|
||||||
if (sendTimestampEvents)
|
sendNextEventTimestamp(timestamp)
|
||||||
GeodeUtils.setNextInputTimestamp(timestamp)
|
|
||||||
|
|
||||||
cocos2dxRenderer.handleActionUp(idPointerUp, xPointerUp, y2)
|
cocos2dxRenderer.handleActionUp(idPointerUp, xPointerUp, y2)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@@ -233,6 +289,28 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun sendKeyBack() {
|
||||||
|
if (cocos2dxEditText?.isFocused == true) {
|
||||||
|
requestFocus()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BaseRobTopActivity.blockBackButton) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useKeyboardEvents) {
|
||||||
|
queueEvent {
|
||||||
|
cocos2dxRenderer.handleKeyDown(KeyEvent.KEYCODE_BACK)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val currentTime = System.nanoTime()
|
||||||
|
queueEvent {
|
||||||
|
sendNextEventTimestamp(currentTime)
|
||||||
|
GeodeUtils.nativeKeyDown(KeyEvent.KEYCODE_BACK, 0, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
||||||
if (!useKeyboardEvents) {
|
if (!useKeyboardEvents) {
|
||||||
return legacyKeyDown(keyCode, event)
|
return legacyKeyDown(keyCode, event)
|
||||||
@@ -249,9 +327,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
queueEvent {
|
queueEvent {
|
||||||
if (sendTimestampEvents)
|
sendNextEventTimestamp(event.eventTime * MS_TO_NS)
|
||||||
GeodeUtils.setNextInputTimestamp(event.eventTime * MS_TO_NS)
|
|
||||||
|
|
||||||
GeodeUtils.nativeKeyDown(keyCode, event.modifiers, event.repeatCount != 0)
|
GeodeUtils.nativeKeyDown(keyCode, event.modifiers, event.repeatCount != 0)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@@ -274,9 +350,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
queueEvent {
|
queueEvent {
|
||||||
if (sendTimestampEvents)
|
sendNextEventTimestamp(event.eventTime * MS_TO_NS)
|
||||||
GeodeUtils.setNextInputTimestamp(event.eventTime * MS_TO_NS)
|
|
||||||
|
|
||||||
GeodeUtils.nativeKeyUp(keyCode, event.modifiers)
|
GeodeUtils.nativeKeyUp(keyCode, event.modifiers)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,9 +371,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
event.eventTimeNanos else event.eventTime * MS_TO_NS
|
event.eventTimeNanos else event.eventTime * MS_TO_NS
|
||||||
|
|
||||||
queueEvent {
|
queueEvent {
|
||||||
if (sendTimestampEvents)
|
sendNextEventTimestamp(timestamp)
|
||||||
GeodeUtils.setNextInputTimestamp(timestamp)
|
|
||||||
|
|
||||||
GeodeUtils.nativeActionScroll(scrollX, scrollY)
|
GeodeUtils.nativeActionScroll(scrollX, scrollY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.cocos2dx.lib
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.ApplicationInfo
|
import android.content.pm.ApplicationInfo
|
||||||
|
import android.content.res.AssetManager
|
||||||
import android.os.Process
|
import android.os.Process
|
||||||
import com.customRobTop.BaseRobTopActivity
|
import com.customRobTop.BaseRobTopActivity
|
||||||
import com.geode.launcher.utils.LaunchUtils
|
import com.geode.launcher.utils.LaunchUtils
|
||||||
@@ -11,9 +12,9 @@ import com.geode.launcher.utils.LaunchUtils
|
|||||||
object Cocos2dxHelper {
|
object Cocos2dxHelper {
|
||||||
// private val sCocos2dMusic: Cocos2dxMusic? = null
|
// private val sCocos2dMusic: Cocos2dxMusic? = null
|
||||||
// private val sCocos2dSound: Cocos2dxSound? = null
|
// private val sCocos2dSound: Cocos2dxSound? = null
|
||||||
// private val sAssetManager: AssetManager? = null
|
private var sAssetManager: AssetManager? = null
|
||||||
// private val sCocos2dxAccelerometer: Cocos2dxAccelerometer? = null
|
private var sCocos2dxAccelerometer: Cocos2dxAccelerometer? = null
|
||||||
// private val sAccelerometerEnabled = false
|
private var sAccelerometerEnabled = false
|
||||||
private var packageName: String? = null
|
private var packageName: String? = null
|
||||||
private var fileDirectory: String? = null
|
private var fileDirectory: String? = null
|
||||||
|
|
||||||
@@ -36,6 +37,40 @@ object Cocos2dxHelper {
|
|||||||
Process.killProcess(Process.myPid())
|
Process.killProcess(Process.myPid())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getAssetManager(): AssetManager? {
|
||||||
|
return sAssetManager
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun enableAccelerometer() {
|
||||||
|
sAccelerometerEnabled = true
|
||||||
|
sCocos2dxAccelerometer?.enable()
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun setAccelerometerInterval(interval: Float) {
|
||||||
|
sCocos2dxAccelerometer?.setInterval(interval)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun disableAccelerometer() {
|
||||||
|
sAccelerometerEnabled = false
|
||||||
|
sCocos2dxAccelerometer?.disable()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onResume() {
|
||||||
|
if (sAccelerometerEnabled) {
|
||||||
|
sCocos2dxAccelerometer?.enable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onPause() {
|
||||||
|
if (sAccelerometerEnabled) {
|
||||||
|
sCocos2dxAccelerometer?.disable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getDPI(): Int {
|
fun getDPI(): Int {
|
||||||
return BaseRobTopActivity.me.get()?.resources?.configuration?.densityDpi ?: -1
|
return BaseRobTopActivity.me.get()?.resources?.configuration?.densityDpi ?: -1
|
||||||
@@ -52,14 +87,14 @@ object Cocos2dxHelper {
|
|||||||
this.cocos2dxHelperListener = cocos2dxHelperListener
|
this.cocos2dxHelperListener = cocos2dxHelperListener
|
||||||
packageName = applicationInfo.packageName
|
packageName = applicationInfo.packageName
|
||||||
fileDirectory = LaunchUtils.getSaveDirectory(context).absolutePath
|
fileDirectory = LaunchUtils.getSaveDirectory(context).absolutePath
|
||||||
// Cocos2dxHelper.sCocos2dxAccelerometer = Cocos2dxAccelerometer(pContext)
|
sCocos2dxAccelerometer = Cocos2dxAccelerometer(context)
|
||||||
// Cocos2dxHelper.sCocos2dMusic = Cocos2dxMusic(pContext)
|
// Cocos2dxHelper.sCocos2dMusic = Cocos2dxMusic(pContext)
|
||||||
// var simultaneousStreams: Int = Cocos2dxSound.MAX_SIMULTANEOUS_STREAMS_DEFAULT
|
// var simultaneousStreams: Int = Cocos2dxSound.MAX_SIMULTANEOUS_STREAMS_DEFAULT
|
||||||
// if (Cocos2dxHelper.getDeviceModel().indexOf("GT-I9100") !== -1) {
|
// if (Cocos2dxHelper.getDeviceModel().indexOf("GT-I9100") !== -1) {
|
||||||
// simultaneousStreams = Cocos2dxSound.MAX_SIMULTANEOUS_STREAMS_I9100
|
// simultaneousStreams = Cocos2dxSound.MAX_SIMULTANEOUS_STREAMS_I9100
|
||||||
// }
|
// }
|
||||||
// Cocos2dxHelper.sCocos2dSound = Cocos2dxSound(pContext, simultaneousStreams)
|
// Cocos2dxHelper.sCocos2dSound = Cocos2dxSound(pContext, simultaneousStreams)
|
||||||
// Cocos2dxHelper.sAssetManager = pContext.getAssets()
|
sAssetManager = context.assets
|
||||||
Cocos2dxBitmap.setContext(context)
|
Cocos2dxBitmap.setContext(context)
|
||||||
// Cocos2dxETCLoader.setContext(pContext)
|
// Cocos2dxETCLoader.setContext(pContext)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
package org.cocos2dx.lib
|
package org.cocos2dx.lib
|
||||||
|
|
||||||
import android.opengl.GLSurfaceView
|
import android.opengl.GLSurfaceView
|
||||||
|
import android.os.Build
|
||||||
import javax.microedition.khronos.egl.EGLConfig
|
import javax.microedition.khronos.egl.EGLConfig
|
||||||
import javax.microedition.khronos.opengles.GL10
|
import javax.microedition.khronos.opengles.GL10
|
||||||
|
|
||||||
|
private const val NANOSECONDS_PER_SECOND = 1000000000L
|
||||||
|
private const val NANOSECONDS_PER_MICROSECOND = 1000000L
|
||||||
|
|
||||||
@Suppress("unused", "KotlinJniMissingFunction")
|
@Suppress("unused", "KotlinJniMissingFunction")
|
||||||
class Cocos2dxRenderer : GLSurfaceView.Renderer {
|
class Cocos2dxRenderer(private var handler: Cocos2dxGLSurfaceView) : GLSurfaceView.Renderer {
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun setAnimationInterval(@Suppress("UNUSED_PARAMETER") animationInterval: Double) {
|
fun setAnimationInterval(@Suppress("UNUSED_PARAMETER") animationInterval: Double) {
|
||||||
@@ -60,6 +64,12 @@ class Cocos2dxRenderer : GLSurfaceView.Renderer {
|
|||||||
private var screenWidth = 0
|
private var screenWidth = 0
|
||||||
private var screenHeight = 0
|
private var screenHeight = 0
|
||||||
var sendResizeEvents = false
|
var sendResizeEvents = false
|
||||||
|
var setFrameRate = false
|
||||||
|
private var mAnimationInterval: Long? = null
|
||||||
|
|
||||||
|
fun limitFrameRate(rate: Int) {
|
||||||
|
mAnimationInterval = NANOSECONDS_PER_SECOND/rate
|
||||||
|
}
|
||||||
|
|
||||||
fun setScreenWidthAndHeight(surfaceWidth: Int, surfaceHeight: Int) {
|
fun setScreenWidthAndHeight(surfaceWidth: Int, surfaceHeight: Int) {
|
||||||
screenWidth = surfaceWidth
|
screenWidth = surfaceWidth
|
||||||
@@ -71,10 +81,32 @@ class Cocos2dxRenderer : GLSurfaceView.Renderer {
|
|||||||
lastTickInNanoSeconds = System.nanoTime()
|
lastTickInNanoSeconds = System.nanoTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSurfaceChanged(gl10: GL10?, width: Int, height: Int) {}
|
override fun onSurfaceChanged(gl10: GL10?, width: Int, height: Int) {
|
||||||
|
if (setFrameRate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
handler.updateRefreshRate()
|
||||||
|
}
|
||||||
|
|
||||||
|
println("renderer surfaceChanged: ${width}x${height}@${handler.display.refreshRate}fps")
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDrawFrame(gl: GL10?) {
|
override fun onDrawFrame(gl: GL10?) {
|
||||||
nativeRender()
|
val animationInterval = mAnimationInterval
|
||||||
|
if (animationInterval == null) {
|
||||||
|
nativeRender()
|
||||||
|
} else {
|
||||||
|
nativeRender()
|
||||||
|
|
||||||
|
val now = System.nanoTime()
|
||||||
|
val interval = now - this.lastTickInNanoSeconds
|
||||||
|
|
||||||
|
if (interval < animationInterval) {
|
||||||
|
try {
|
||||||
|
Thread.sleep((animationInterval - interval) / NANOSECONDS_PER_MICROSECOND)
|
||||||
|
} catch (e: Exception) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastTickInNanoSeconds = System.nanoTime()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleActionDown(id: Int, x: Float, y: Float) {
|
fun handleActionDown(id: Int, x: Float, y: Float) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.text.TextWatcher
|
|||||||
import android.widget.TextView.OnEditorActionListener
|
import android.widget.TextView.OnEditorActionListener
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
|
||||||
@@ -47,22 +48,22 @@ class Cocos2dxTextInputWrapper(private val cocos2dxGLSurfaceView: Cocos2dxGLSurf
|
|||||||
|
|
||||||
override fun onTextChanged(pCharSequence: CharSequence, start: Int, before: Int, count: Int) {}
|
override fun onTextChanged(pCharSequence: CharSequence, start: Int, before: Int, count: Int) {}
|
||||||
override fun onEditorAction(textView: TextView, actionID: Int, keyEvent: KeyEvent?): Boolean {
|
override fun onEditorAction(textView: TextView, actionID: Int, keyEvent: KeyEvent?): Boolean {
|
||||||
|
if (actionID != EditorInfo.IME_ACTION_DONE) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (cocos2dxGLSurfaceView.cocos2dxEditText == textView && isFullScreenEdit) {
|
if (cocos2dxGLSurfaceView.cocos2dxEditText == textView && isFullScreenEdit) {
|
||||||
for (i in originText!!.length downTo 1) {
|
for (i in originText!!.length downTo 1) {
|
||||||
cocos2dxGLSurfaceView.deleteBackward()
|
cocos2dxGLSurfaceView.deleteBackward()
|
||||||
}
|
}
|
||||||
var text = textView.text.toString()
|
var text = textView.text.toString()
|
||||||
if (text.compareTo("") == 0) {
|
if (!text.endsWith('\n')) {
|
||||||
text = "\n"
|
text += '\n'
|
||||||
}
|
|
||||||
if (10 != text[text.length - 1].code) {
|
|
||||||
text += 10.toChar()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cocos2dxGLSurfaceView.insertText(text)
|
cocos2dxGLSurfaceView.insertText(text)
|
||||||
}
|
}
|
||||||
if (actionID != 6) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
cocos2dxGLSurfaceView.requestFocus()
|
cocos2dxGLSurfaceView.requestFocus()
|
||||||
Cocos2dxGLSurfaceView.closeIMEKeyboard()
|
Cocos2dxGLSurfaceView.closeIMEKeyboard()
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ object Cocos2dxTypefaces {
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
operator fun get(pContext: Context, pAssetName: String): Typeface? {
|
operator fun get(pContext: Context, pAssetName: String): Typeface? {
|
||||||
var typeface: Typeface?
|
val typeface: Typeface?
|
||||||
var typeface2: Typeface
|
val typeface2: Typeface
|
||||||
|
|
||||||
synchronized(Cocos2dxTypefaces::class.java) {
|
synchronized(Cocos2dxTypefaces::class.java) {
|
||||||
if (!typefaceCache.containsKey(pAssetName)) {
|
if (!typefaceCache.containsKey(pAssetName)) {
|
||||||
typeface2 = if (pAssetName.startsWith("/")) {
|
typeface2 = if (pAssetName.startsWith("/")) {
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:aapt="http://schemas.android.com/aapt"
|
||||||
|
android:width="96dp"
|
||||||
|
android:height="96dp"
|
||||||
|
android:viewportWidth="696"
|
||||||
|
android:viewportHeight="698"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:pathData="M393.08,24.42L372.88,9C358.19,-2.22 337.81,-2.22 323.12,9L16.94,242.81C3.28,253.24 -2.42,271.09 2.66,287.51L120.41,668.43C125.72,685.61 141.6,697.33 159.58,697.33H536.42C554.4,697.33 570.28,685.61 575.59,668.43L693.34,287.51C698.42,271.09 692.72,253.24 679.06,242.81L650.84,221.26L618.37,323.39L529.2,613.39C525.71,624.72 515.24,632.46 503.39,632.46H190.61C178.76,632.46 168.29,624.72 164.8,613.39L67.2,295.97C63.88,285.19 67.62,273.49 76.56,266.62L330.56,71.62C331.58,70.84 332.64,70.14 333.74,69.52L393.08,24.42Z"
|
||||||
|
android:fillType="evenOdd"
|
||||||
|
android:fillColor="@android:color/white">
|
||||||
|
</path>
|
||||||
|
<path
|
||||||
|
android:pathData="M336.61,143.26C344.51,137.21 355.49,137.21 363.39,143.26L552.8,288.49C560.1,294.09 563.14,303.63 560.44,312.42L487.62,548.92C484.78,558.15 476.25,564.45 466.59,564.45H233.41C223.75,564.45 215.22,558.15 212.38,548.92L199.93,508.5H261.68C262.39,508.65 263.13,508.72 263.89,508.72H432.11C436.96,508.72 441.24,505.55 442.64,500.9L495.14,326.98C496.45,322.64 494.96,317.93 491.39,315.14L354.78,208.3C350.8,205.19 345.2,205.19 341.22,208.3L215.93,306.29L152.15,353.31L139.56,312.42C136.86,303.63 139.9,294.09 147.2,288.49L336.61,143.26Z"
|
||||||
|
android:fillType="evenOdd"
|
||||||
|
android:fillColor="@android:color/white">
|
||||||
|
</path>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M560,800L560,720L680,720Q697,720 708.5,708.5Q720,697 720,680L720,600Q720,562 742,531Q764,500 800,487L800,473Q764,460 742,429Q720,398 720,360L720,280Q720,263 708.5,251.5Q697,240 680,240L560,240L560,160L680,160Q730,160 765,195Q800,230 800,280L800,360Q800,377 811.5,388.5Q823,400 840,400L880,400L880,560L840,560Q823,560 811.5,571.5Q800,583 800,600L800,680Q800,730 765,765Q730,800 680,800L560,800ZM280,800Q230,800 195,765Q160,730 160,680L160,600Q160,583 148.5,571.5Q137,560 120,560L80,560L80,400L120,400Q137,400 148.5,388.5Q160,377 160,360L160,280Q160,230 195,195Q230,160 280,160L400,160L400,240L280,240Q263,240 251.5,251.5Q240,263 240,280L240,360Q240,398 218,429Q196,460 160,473L160,487Q196,500 218,531Q240,562 240,600L240,680Q240,697 251.5,708.5Q263,720 280,720L400,720L400,800L280,800Z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M440,680L280,680Q197,680 138.5,621.5Q80,563 80,480Q80,397 138.5,338.5Q197,280 280,280L440,280L440,360L280,360Q230,360 195,395Q160,430 160,480Q160,530 195,565Q230,600 280,600L440,600L440,680ZM320,520L320,440L640,440L640,520L320,520ZM520,680L520,600L680,600Q730,600 765,565Q800,530 800,480Q800,430 765,395Q730,360 680,360L520,360L520,280L680,280Q763,280 821.5,338.5Q880,397 880,480Q880,563 821.5,621.5Q763,680 680,680L520,680Z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M480,480Q414,480 367,433Q320,386 320,320Q320,254 367,207Q414,160 480,160Q546,160 593,207Q640,254 640,320Q640,386 593,433Q546,480 480,480ZM160,800L160,688Q160,654 177.5,625.5Q195,597 224,582Q286,551 350,535.5Q414,520 480,520Q546,520 610,535.5Q674,551 736,582Q765,597 782.5,625.5Q800,654 800,688L800,800L160,800ZM240,720L720,720L720,688Q720,677 714.5,668Q709,659 700,654Q646,627 591,613.5Q536,600 480,600Q424,600 369,613.5Q314,627 260,654Q251,659 245.5,668Q240,677 240,688L240,720ZM480,400Q513,400 536.5,376.5Q560,353 560,320Q560,287 536.5,263.5Q513,240 480,240Q447,240 423.5,263.5Q400,287 400,320Q400,353 423.5,376.5Q447,400 480,400ZM480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320ZM480,720L480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720L480,720Z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M720,560L720,440L600,440L600,360L720,360L720,240L800,240L800,360L920,360L920,440L800,440L800,560L720,560ZM360,480Q294,480 247,433Q200,386 200,320Q200,254 247,207Q294,160 360,160Q426,160 473,207Q520,254 520,320Q520,386 473,433Q426,480 360,480ZM40,800L40,688Q40,654 57.5,625.5Q75,597 104,582Q166,551 230,535.5Q294,520 360,520Q426,520 490,535.5Q554,551 616,582Q645,597 662.5,625.5Q680,654 680,688L680,800L40,800ZM120,720L600,720L600,688Q600,677 594.5,668Q589,659 580,654Q526,627 471,613.5Q416,600 360,600Q304,600 249,613.5Q194,627 140,654Q131,659 125.5,668Q120,677 120,688L120,720ZM360,400Q393,400 416.5,376.5Q440,353 440,320Q440,287 416.5,263.5Q393,240 360,240Q327,240 303.5,263.5Q280,287 280,320Q280,353 303.5,376.5Q327,400 360,400ZM360,320Q360,320 360,320Q360,320 360,320Q360,320 360,320Q360,320 360,320Q360,320 360,320Q360,320 360,320Q360,320 360,320Q360,320 360,320ZM360,720L360,720Q360,720 360,720Q360,720 360,720Q360,720 360,720Q360,720 360,720Q360,720 360,720Q360,720 360,720Q360,720 360,720Q360,720 360,720L360,720Z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M424,640Q424,559 438.5,523.5Q453,488 500,446Q541,410 562.5,383.5Q584,357 584,323Q584,282 556.5,255Q529,228 480,228Q429,228 402.5,259Q376,290 365,322L262,278Q283,214 339,167Q395,120 480,120Q585,120 641.5,178.5Q698,237 698,319Q698,369 676.5,404.5Q655,440 609,485Q560,532 549.5,556.5Q539,581 539,640L424,640ZM480,880Q447,880 423.5,856.5Q400,833 400,800Q400,767 423.5,743.5Q447,720 480,720Q513,720 536.5,743.5Q560,767 560,800Q560,833 536.5,856.5Q513,880 480,880Z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M200,520L200,440L760,440L760,520L200,520Z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M240,720L240,240L320,240L320,720L240,720ZM400,720L800,480L400,240L400,720ZM480,579L480,381L645,480L480,579ZM480,480L480,480L480,480Z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal"
|
||||||
|
android:autoMirrored="true">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M280,760L280,680L564,680Q627,680 673.5,640Q720,600 720,540Q720,480 673.5,440Q627,400 564,400L312,400L416,504L360,560L160,360L360,160L416,216L312,320L564,320Q661,320 730.5,383Q800,446 800,540Q800,634 730.5,697Q661,760 564,760L280,760Z"/>
|
||||||
|
</vector>
|
||||||
@@ -3,10 +3,11 @@
|
|||||||
<string name="no_activity_found">No activity found for this action.</string>
|
<string name="no_activity_found">No activity found for this action.</string>
|
||||||
|
|
||||||
<!-- MainActivity strings -->
|
<!-- MainActivity strings -->
|
||||||
<string name="game_not_found">Geometry Dash was not found.</string>
|
<string name="game_not_found">Geometry Dash was not found.\nThe full version of the game is required.</string>
|
||||||
<string name="launcher_launch">Launch</string>
|
<string name="launcher_launch">Launch</string>
|
||||||
<string name="launcher_settings">Settings</string>
|
<string name="launcher_settings">Settings</string>
|
||||||
<string name="launcher_download">Download</string>
|
<string name="launcher_download">Download</string>
|
||||||
|
<string name="launcher_install">Install</string>
|
||||||
<string name="launcher_title">Geode</string>
|
<string name="launcher_title">Geode</string>
|
||||||
<string name="launcher_logo_alt">geode logo</string>
|
<string name="launcher_logo_alt">geode logo</string>
|
||||||
<string name="launcher_launch_icon_alt">play icon</string>
|
<string name="launcher_launch_icon_alt">play icon</string>
|
||||||
@@ -32,8 +33,17 @@
|
|||||||
<string name="launcher_unsupported_version_description">
|
<string name="launcher_unsupported_version_description">
|
||||||
The current version of Geometry Dash is not compatible with the version supported by the launcher. A launcher update is required to fix this.\nLaunch will continue, but crashes may occur!
|
The current version of Geometry Dash is not compatible with the version supported by the launcher. A launcher update is required to fix this.\nLaunch will continue, but crashes may occur!
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string name="launcher_game_update_required_short">A Geometry Dash update is required.</string>
|
||||||
|
<string name="launcher_game_update_required">The currently installed version of Geometry Dash is no longer supported. Please update Geometry Dash to continue receiving Geode updates.</string>
|
||||||
|
|
||||||
<string name="launcher_update_available">A new launcher update is available!</string>
|
<string name="launcher_update_available">A new launcher update is available!</string>
|
||||||
<string name="launcher_update_dismiss">Dismiss</string>
|
<string name="launcher_update_dismiss">Dismiss</string>
|
||||||
|
<string name="launcher_update_view">View</string>
|
||||||
|
<string name="launcher_update_external_link">View in browser</string>
|
||||||
|
<string name="launcher_update_name">Geode Launcher v%1$s</string>
|
||||||
|
<string name="launcher_update_changelog">Changelog</string>
|
||||||
|
<string name="launcher_update_released">Released %1$s</string>
|
||||||
<string name="safe_mode_enable_title">Enable safe mode?</string>
|
<string name="safe_mode_enable_title">Enable safe mode?</string>
|
||||||
<string name="safe_mode_enable_description">Safe mode disables loading of all mods, allowing one to remove problematic mods or diagnose crashes. If you\'re not experiencing issues with Geode, you should probably not be using safe mode.</string>
|
<string name="safe_mode_enable_description">Safe mode disables loading of all mods, allowing one to remove problematic mods or diagnose crashes. If you\'re not experiencing issues with Geode, you should probably not be using safe mode.</string>
|
||||||
<string name="launcher_failed_to_load">Geode failed to load.</string>
|
<string name="launcher_failed_to_load">Geode failed to load.</string>
|
||||||
@@ -45,7 +55,28 @@
|
|||||||
<string name="launcher_error_copy">Copy details</string>
|
<string name="launcher_error_copy">Copy details</string>
|
||||||
<string name="launcher_error_export_crash">Share crash</string>
|
<string name="launcher_error_export_crash">Share crash</string>
|
||||||
<string name="launcher_error_export_missing">No crash dump was found!</string>
|
<string name="launcher_error_export_missing">No crash dump was found!</string>
|
||||||
<string name="launcher_error_device_info">Android %2$s, %1$s</string>
|
<string name="launcher_error_device_info">Android %2$s, %1$s (%5$s)\nGD %4$s, Geode %3$s + v%6$s</string>
|
||||||
|
|
||||||
|
<string name="launcher_notification_settings">Launcher Settings</string>
|
||||||
|
<string name="launcher_notification_update_failed">Failed to update Geode.</string>
|
||||||
|
<string name="launcher_notification_update_success">Geode updated!</string>
|
||||||
|
<string name="launcher_notification_compatibility">Unsupported Geometry Dash version.</string>
|
||||||
|
<string name="launcher_notification_compatibility_description">An update is required to receive Geode updates.</string>
|
||||||
|
<string name="launcher_notification_update_cta">Tap for more information.</string>
|
||||||
|
|
||||||
|
<string name="launcher_starting_game">Starting Geometry Dash…</string>
|
||||||
|
<string name="launcher_downloading_update">Downloading update…</string>
|
||||||
|
<string name="launcher_downloading_update_details">(%1$s/%2$s)</string>
|
||||||
|
<string name="launcher_cancelled_manual">Launch paused.</string>
|
||||||
|
<string name="launcher_cancelled_navigated_away">Launch paused.</string>
|
||||||
|
<string name="launcher_cancelled_crash">Launch paused due to a crash.</string>
|
||||||
|
<string name="launcher_cancelled_error">Could not start Geode.</string>
|
||||||
|
<string name="launcher_cancelled_outdated">A Geometry Dash update is required.</string>
|
||||||
|
<string name="launcher_cancelled_restart">Restart</string>
|
||||||
|
<string name="launcher_cancelled_resume">Resume</string>
|
||||||
|
<string name="launcher_cancelled_retry">Retry</string>
|
||||||
|
<string name="launcher_cancelled_help_alt">Help</string>
|
||||||
|
<string name="launcher_in_safe_mode">Starting in safe mode…</string>
|
||||||
|
|
||||||
<!-- Updater strings -->
|
<!-- Updater strings -->
|
||||||
<string name="release_fetch_failed">Update failed.\n%1$s</string>
|
<string name="release_fetch_failed">Update failed.\n%1$s</string>
|
||||||
@@ -53,6 +84,7 @@
|
|||||||
<string name="release_fetch_in_progress">Checking for new releases…</string>
|
<string name="release_fetch_in_progress">Checking for new releases…</string>
|
||||||
<string name="release_fetch_success">Geode updated!</string>
|
<string name="release_fetch_success">Geode updated!</string>
|
||||||
<string name="release_fetch_downloading">Downloading update… (%1$s/%2$s)</string>
|
<string name="release_fetch_downloading">Downloading update… (%1$s/%2$s)</string>
|
||||||
|
<string name="release_fetch_downloading_indeterminate">Downloading update… (%1$s)</string>
|
||||||
<string name="release_fetch_cancelling">Cancelling update…</string>
|
<string name="release_fetch_cancelling">Cancelling update…</string>
|
||||||
<string name="release_fetch_no_internet">No internet found.</string>
|
<string name="release_fetch_no_internet">No internet found.</string>
|
||||||
<string name="release_fetch_cancelled">Update cancelled.</string>
|
<string name="release_fetch_cancelled">Update cancelled.</string>
|
||||||
@@ -75,11 +107,14 @@
|
|||||||
<string name="load_failed_recommendation_update">Verify that the latest versions of the launcher and Geometry Dash are installed.</string>
|
<string name="load_failed_recommendation_update">Verify that the latest versions of the launcher and Geometry Dash are installed.</string>
|
||||||
<string name="load_failed_recommendation_report">Report this issue to the developers.</string>
|
<string name="load_failed_recommendation_report">Report this issue to the developers.</string>
|
||||||
<string name="load_failed_recommendation_safe_mode">Hold the Launch button to launch in safe mode.</string>
|
<string name="load_failed_recommendation_safe_mode">Hold the Launch button to launch in safe mode.</string>
|
||||||
|
<string name="load_failed_recommendation_dev_stl">Devs: If this is a locally built Geode version, please use the c++_shared ANDROID_STL!</string>
|
||||||
|
|
||||||
<string name="message_box_cancel">Cancel</string>
|
<string name="message_box_cancel">Cancel</string>
|
||||||
<string name="message_box_accept">OK</string>
|
<string name="message_box_accept">OK</string>
|
||||||
<string name="message_box_continue">Continue</string>
|
<string name="message_box_continue">Continue</string>
|
||||||
<string name="missing_permissions">Missing required permissions for this action!</string>
|
<string name="missing_permissions">Missing required permissions for this action!</string>
|
||||||
|
<string name="no_file_selected">File selection cancelled.</string>
|
||||||
|
<string name="file_select_error">Failed to get file.</string>
|
||||||
|
|
||||||
<!-- SettingsActivity strings -->
|
<!-- SettingsActivity strings -->
|
||||||
<string name="title_activity_settings">Settings</string>
|
<string name="title_activity_settings">Settings</string>
|
||||||
@@ -101,20 +136,76 @@
|
|||||||
<string name="preference_theme_light">Light</string>
|
<string name="preference_theme_light">Light</string>
|
||||||
<string name="preference_theme_dark">Dark</string>
|
<string name="preference_theme_dark">Dark</string>
|
||||||
<string name="preference_black_background_name">Black background in dark theme</string>
|
<string name="preference_black_background_name">Black background in dark theme</string>
|
||||||
|
<string name="preference_force_hrr">Force maximum refresh rate</string>
|
||||||
|
<string name="preference_enable_redesign">✨ Enable UI refresh</string>
|
||||||
|
|
||||||
<string name="preference_display_mode_name">Screen scale</string>
|
<string name="preference_display_mode_name">Display mode</string>
|
||||||
<string name="preference_display_mode_select">Select screen scale</string>
|
<string name="preference_display_mode_select">Select display mode</string>
|
||||||
<string name="preference_display_mode_legacy">Limited (16:9)</string>
|
<string name="preference_display_mode_legacy">Limited (Custom)</string>
|
||||||
<string name="preference_display_mode_fullscreen">Edge-to-edge</string>
|
<string name="preference_display_mode_fullscreen">Edge-to-edge</string>
|
||||||
<string name="preference_display_mode_default">Default</string>
|
<string name="preference_display_mode_default">Default</string>
|
||||||
|
|
||||||
|
<string name="preference_custom_aspect_ratio_name">Aspect ratio</string>
|
||||||
|
<string name="preference_custom_aspect_ratio_description">Limits aspect ratio of the game.</string>
|
||||||
|
<string name="preference_custom_aspect_ratio_select">Select aspect ratio</string>
|
||||||
|
<string name="preference_custom_aspect_ratio_16x9">16:9</string>
|
||||||
|
<string name="preference_custom_aspect_ratio_16x10">16:10</string>
|
||||||
|
<string name="preference_custom_aspect_ratio_4x3">4:3</string>
|
||||||
|
<string name="preference_custom_aspect_ratio_1x1">1:1</string>
|
||||||
|
|
||||||
|
<string name="preference_screen_zoom_name">Screen zoom</string>
|
||||||
|
<string name="preference_screen_zoom_description">Reduces the size of the game window.</string>
|
||||||
|
<string name="preference_screen_zoom_select">Edit screen zoom</string>
|
||||||
|
<string name="preference_screen_zoom_fit_name">Fit to screen</string>
|
||||||
|
|
||||||
|
<string name="preference_limit_framerate_name">Limit max framerate</string>
|
||||||
|
<string name="preference_limit_framerate_description">Limits framerate during rendering.</string>
|
||||||
|
<string name="preference_limit_framerate_select">Edit maximum framerate</string>
|
||||||
|
<string name="preference_limit_framerate_default">Disabled</string>
|
||||||
|
<string name="preference_limit_framerate_label">Framerate</string>
|
||||||
|
<string name="preference_limit_framerate_suffix">FPS</string>
|
||||||
|
<string name="preference_limit_framerate_value">%1$d FPS</string>
|
||||||
|
<string name="preference_limit_framerate_error_max">This device supports at most %1$s FPS.</string>
|
||||||
|
<string name="preference_limit_framerate_error_min">Framerate must be at least %1$s FPS.</string>
|
||||||
|
<string name="preference_limit_framerate_subtract">Decrement</string>
|
||||||
|
<string name="preference_limit_framerate_add">Increment</string>
|
||||||
|
<string name="preference_limit_framerate_reset">Disable</string>
|
||||||
|
|
||||||
<string name="preference_category_updater">Updates</string>
|
<string name="preference_category_updater">Updates</string>
|
||||||
<string name="preference_update_automatically_name">Enable automatic updates</string>
|
<string name="preference_update_automatically_name">Enable automatic updates</string>
|
||||||
<string name="preference_release_channel_name">Use nightly release channel</string>
|
<string name="preference_release_channel_name">Use nightly release channel</string>
|
||||||
|
|
||||||
|
<string name="preference_category_gameplay">Gameplay</string>
|
||||||
|
|
||||||
|
<string name="preference_release_channel_tag_name">Release channel</string>
|
||||||
|
<string name="preference_release_channel_select">Select release channel</string>
|
||||||
|
<string name="preference_release_channel_stable">Stable</string>
|
||||||
|
<string name="preference_release_channel_beta">Pre-release</string>
|
||||||
|
<string name="preference_release_channel_nightly">Nightly</string>
|
||||||
|
|
||||||
|
<string name="preference_category_about">About</string>
|
||||||
|
|
||||||
|
<string name="preference_launcher_version_name">Android Launcher</string>
|
||||||
|
<string name="preference_launcher_version_description">v%1$s</string>
|
||||||
|
<string name="preference_launcher_version">Android Launcher v%1$s</string>
|
||||||
|
|
||||||
|
<string name="preference_loader_version_name">Geode</string>
|
||||||
|
<string name="preference_loader_version_description">%1$s</string>
|
||||||
|
<string name="preference_loader_version">Geode %1$s</string>
|
||||||
|
|
||||||
|
<string name="preference_game_version_name">Geometry Dash</string>
|
||||||
|
<string name="preference_game_version_description">%1$s (%2$s)</string>
|
||||||
|
<string name="preference_game_version">Geometry Dash %1$s (%2$s)</string>
|
||||||
|
<string name="preference_game_source_google">Google</string>
|
||||||
|
<string name="preference_game_source_amazon">Amazon</string>
|
||||||
|
<string name="preference_game_source_unknown">Unknown</string>
|
||||||
|
|
||||||
|
<string name="preference_architecture_name">Device</string>
|
||||||
|
<string name="preference_architecture_description">%1$s (%2$s)</string>
|
||||||
|
<string name="preference_architecture">%1$s (%2$s)</string>
|
||||||
|
|
||||||
<string name="preference_check_for_updates_button">Check for updates</string>
|
<string name="preference_check_for_updates_button">Check for updates</string>
|
||||||
<string name="preference_check_for_updates_description">Current loader version: %1$s</string>
|
<string name="preference_check_for_updates_description">Current loader version: %1$s</string>
|
||||||
<string name="preference_launcher_version">Geode Launcher v%1$s</string>
|
|
||||||
<string name="preference_check_for_updates_failed">Update failed. See logs for more details.</string>
|
<string name="preference_check_for_updates_failed">Update failed. See logs for more details.</string>
|
||||||
<string name="preference_check_for_updates_none_found">No updates found.</string>
|
<string name="preference_check_for_updates_none_found">No updates found.</string>
|
||||||
<string name="preference_check_for_updates_success">Geode has been updated!</string>
|
<string name="preference_check_for_updates_success">Geode has been updated!</string>
|
||||||
@@ -122,11 +213,26 @@
|
|||||||
<string name="preference_check_for_updates_no_internet">No internet found.</string>
|
<string name="preference_check_for_updates_no_internet">No internet found.</string>
|
||||||
<string name="preference_check_for_updates_already_updating">An update is already in progress!</string>
|
<string name="preference_check_for_updates_already_updating">An update is already in progress!</string>
|
||||||
|
|
||||||
<string name="preference_category_developer">Developer</string>
|
<string name="preference_category_developer">Advanced</string>
|
||||||
<string name="preference_launch_arguments_name">Launch arguments</string>
|
<string name="preference_launch_arguments_name">Launch arguments</string>
|
||||||
<string name="preference_launch_arguments_set_title">Set launch arguments</string>
|
<string name="preference_launch_arguments_set_title">Set launch arguments</string>
|
||||||
<string name="preference_text_clear">Clear</string>
|
<string name="preference_text_clear">Clear</string>
|
||||||
|
|
||||||
|
<string name="preference_open_developer_options">Open developer options</string>
|
||||||
|
|
||||||
|
<string name="preference_profiles">Profiles</string>
|
||||||
|
<string name="preference_profiles_create">Create profile</string>
|
||||||
|
<string name="preference_profiles_name">Change profile</string>
|
||||||
|
<string name="preference_profiles_select">Select profile</string>
|
||||||
|
<string name="preference_profiles_create_name">Profile name</string>
|
||||||
|
<string name="preference_profiles_create_action">Create</string>
|
||||||
|
<string name="preference_profiles_select_value">%1$s</string>
|
||||||
|
<string name="preference_profiles_current">Current profile: %1$s</string>
|
||||||
|
<string name="preference_profiles_create_info">This profile will be created at %1$s.</string>
|
||||||
|
<string name="preference_profiles_create_duplicate">A profile with this name already exists.</string>
|
||||||
|
<string name="preference_profiles_delete_alt">Delete</string>
|
||||||
|
<string name="preference_profiles_delete_undo_alt">Undo</string>
|
||||||
|
|
||||||
<!-- ApplicationLogsActivity strings -->
|
<!-- ApplicationLogsActivity strings -->
|
||||||
<string name="title_activity_application_logs">Application Logs</string>
|
<string name="title_activity_application_logs">Application Logs</string>
|
||||||
<string name="application_logs_no_logs">No logs available.</string>
|
<string name="application_logs_no_logs">No logs available.</string>
|
||||||
@@ -141,4 +247,13 @@
|
|||||||
<string name="application_logs_default_filename" translatable="false">launcher_logcat.txt</string>
|
<string name="application_logs_default_filename" translatable="false">launcher_logcat.txt</string>
|
||||||
<string name="application_logs_crash_only">Show Crash Buffer</string>
|
<string name="application_logs_crash_only">Show Crash Buffer</string>
|
||||||
<string name="application_logs_crash_only_enabled_alt">Enabled</string>
|
<string name="application_logs_crash_only_enabled_alt">Enabled</string>
|
||||||
|
|
||||||
|
<string name="title_activity_developer_settings">Developer Settings</string>
|
||||||
|
<string name="preference_developer_mode">Enable developer options</string>
|
||||||
|
<string name="preference_developer_mode_about">Developer mode enables some options that may make the game unstable. Please do not modify them unless you know what you\'re doing!\nThese options may change behavior, or be removed entirely in future updates.</string>
|
||||||
|
<string name="preference_developer_update_notice">Enabling developer mode automatically disallows the updater from overwriting custom loader builds.</string>
|
||||||
|
|
||||||
|
<string name="preference_override_exceptions_name">Custom exceptions fix symbols</string>
|
||||||
|
<string name="preference_override_exceptions_description">Uses exception_symbols.txt to patch</string>
|
||||||
|
<string name="preference_use_index_update_api">Use index release API</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<style name="Theme.NoActionBar.Fullscreen" parent="@style/Theme.AppCompat.DayNight.NoActionBar">
|
<style name="Theme.NoActionBar.Fullscreen" parent="@style/Theme.AppCompat.DayNight.NoActionBar">
|
||||||
<item name="android:windowNoTitle">true</item>
|
<item name="android:windowNoTitle">true</item>
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
<item name="android:windowFullscreen">true</item>
|
<item name="android:windowFullscreen">true</item>
|
||||||
<item name="android:windowContentOverlay">@null</item>
|
<item name="android:windowContentOverlay">@null</item>
|
||||||
<item name="android:windowBackground">@android:drawable/screen_background_dark</item>
|
<item name="android:windowBackground">@android:drawable/screen_background_dark</item>
|
||||||
|
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Theme.GeodeLauncher" parent="android:Theme.Material.Light.NoActionBar" />
|
<style name="Theme.GeodeLauncher" parent="android:Theme.Material.Light.NoActionBar" />
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<game-mode-config
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:targetApi="33"
|
||||||
|
android:supportsBatteryGameMode="false"
|
||||||
|
android:supportsPerformanceGameMode="false"
|
||||||
|
android:allowGameFpsOverride="false" />
|
||||||
+6
-6
@@ -1,14 +1,14 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
val composeBOM by extra("2024.05.00")
|
val composeBOM by extra("2025.04.01")
|
||||||
val composeCompiler by extra("1.5.14")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application") version "8.4.0" apply false
|
id("com.android.application") version "8.9.2" apply false
|
||||||
id("com.android.library") version "8.4.0" apply false
|
id("com.android.library") version "8.9.2" apply false
|
||||||
id("org.jetbrains.kotlin.android") version "1.9.24" apply false
|
id("org.jetbrains.kotlin.android") version "2.1.20" apply false
|
||||||
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.24" apply false
|
id("org.jetbrains.kotlin.plugin.serialization") version "2.1.20" apply false
|
||||||
|
id("org.jetbrains.kotlin.plugin.compose") version "2.1.20" apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Delete>("clean") {
|
tasks.register<Delete>("clean") {
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
|
#Thu Apr 24 10:54:01 MST 2025
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@@ -55,7 +57,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -84,7 +86,8 @@ done
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||||
|
' "$PWD" ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
|
|||||||
Vendored
+12
-10
@@ -13,6 +13,8 @@
|
|||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
|||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user