mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2026-05-09 18:11:26 +08:00
关于界面添加核心构建信息 (#173)
This commit is contained in:
@@ -9,6 +9,7 @@ import com.github.kr328.clash.util.startClashService
|
||||
import com.github.kr328.clash.util.stopClashService
|
||||
import com.github.kr328.clash.util.withClash
|
||||
import com.github.kr328.clash.util.withProfile
|
||||
import com.github.kr328.clash.core.bridge.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.selects.select
|
||||
@@ -125,7 +126,7 @@ class MainActivity : BaseActivity<MainDesign>() {
|
||||
|
||||
private suspend fun queryAppVersionName(): String {
|
||||
return withContext(Dispatchers.IO) {
|
||||
packageManager.getPackageInfo(packageName, 0).versionName
|
||||
packageManager.getPackageInfo(packageName, 0).versionName + "\n" + Bridge.nativeCoreVersion().replace("_", "-")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,54 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
# 获取git hash
|
||||
|
||||
message(STATUS "CMAKE_CURRENT_SOURCE_DIR= ${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
execute_process(
|
||||
COMMAND git submodule foreach git log -1 --format=%H
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE COMMIT_HASH
|
||||
)
|
||||
string(REPLACE "\n" ";" COMMIT_HASH "${COMMIT_HASH}")
|
||||
list(GET COMMIT_HASH 1 COMMIT_HASH)
|
||||
string (REGEX REPLACE "[\n\t\r]" "" COMMIT_HASH ${COMMIT_HASH})
|
||||
string(SUBSTRING ${COMMIT_HASH} 0 7 COMMIT_HASH)
|
||||
message(STATUS "git hash= ${COMMIT_HASH}")
|
||||
|
||||
# 获取分支名称
|
||||
execute_process(
|
||||
COMMAND git submodule foreach git branch -r --contains ${COMMIT_HASH}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE CURRENT_BRANCH
|
||||
)
|
||||
string(REPLACE "\n" ";" CURRENT_BRANCH "${CURRENT_BRANCH}")
|
||||
list(GET CURRENT_BRANCH 1 CURRENT_BRANCH)
|
||||
string (REGEX REPLACE "origin/" "" CURRENT_BRANCH ${CURRENT_BRANCH})
|
||||
string (REGEX REPLACE "[\n\t\r]" "" CURRENT_BRANCH ${CURRENT_BRANCH})
|
||||
#string(SUBSTRING ${CURRENT_BRANCH} 0 8 CURRENT_BRANCH)
|
||||
message(STATUS "git current branch = ${CURRENT_BRANCH}")
|
||||
|
||||
# 获取生成时间
|
||||
execute_process(
|
||||
COMMAND date +"%y%m%d"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE COMPILE_TIME
|
||||
)
|
||||
string (REGEX REPLACE "[\n\t\r]" "" COMPILE_TIME ${COMPILE_TIME})
|
||||
string(REGEX REPLACE "\"" "" COMPILE_TIME ${COMPILE_TIME})
|
||||
|
||||
# 生成版本信息
|
||||
set(GIT_VERSION "Meta_${CURRENT_BRANCH}_${COMMIT_HASH}_${COMPILE_TIME}")
|
||||
message(STATUS "version info = ${GIT_VERSION}")
|
||||
|
||||
# 去除空格
|
||||
string(REGEX REPLACE "[ ]+" "" GIT_VERSION "${GIT_VERSION}")
|
||||
|
||||
# 保存变量到文件
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/version.h @ONLY)
|
||||
|
||||
project(clash-bridge C)
|
||||
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE on)
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include "jni_helper.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include "version.h" // 添加当前编译core版本号变量
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_github_kr328_clash_core_bridge_Bridge_nativeInit(JNIEnv *env, jobject thiz,
|
||||
jstring home,
|
||||
@@ -330,6 +333,7 @@ Java_com_github_kr328_clash_core_bridge_Bridge_nativeSubscribeLogcat(JNIEnv *env
|
||||
subscribeLogcat(_callback);
|
||||
}
|
||||
|
||||
|
||||
static jmethodID m_tun_interface_mark_socket;
|
||||
static jmethodID m_tun_interface_query_socket_uid;
|
||||
static jmethodID m_completable_complete;
|
||||
@@ -538,3 +542,12 @@ JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_github_kr328_clash_core_bridge_Bridge_nativeCoreVersion(JNIEnv *env, jobject thiz) {
|
||||
TRACE_METHOD();
|
||||
|
||||
char* Version = make_String(GIT_VERSION);
|
||||
|
||||
return new_string(Version);
|
||||
}
|
||||
12
core/src/main/cpp/version.h.in
Normal file
12
core/src/main/cpp/version.h.in
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef VERSION_H_IN
|
||||
#define VERSION_H_IN
|
||||
|
||||
/**
|
||||
* 当前编译core版本号
|
||||
*/
|
||||
|
||||
#define GIT_VERSION @GIT_VERSION@
|
||||
#define make_Str(x) #x
|
||||
#define make_String(x) make_Str(x)
|
||||
|
||||
#endif
|
||||
@@ -49,6 +49,7 @@ object Bridge {
|
||||
external fun nativeInstallSideloadGeoip(data: ByteArray?)
|
||||
external fun nativeQueryConfiguration(): String
|
||||
external fun nativeSubscribeLogcat(callback: LogcatInterface)
|
||||
external fun nativeCoreVersion(): String
|
||||
|
||||
private external fun nativeInit(home: String, versionName: String, sdkVersion: Int)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user