Skip to content

Commit

Permalink
关于界面添加核心构建信息 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Larvan2 committed Jan 18, 2024
1 parent d7246f1 commit 0341cb3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/src/main/java/com/github/kr328/clash/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("_", "-")
}
}
}
47 changes: 47 additions & 0 deletions core/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
13 changes: 13 additions & 0 deletions core/src/main/cpp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -537,4 +541,13 @@ JNI_OnLoad(JavaVM *vm, void *reserved) {
release_object_func = &release_jni_object_impl;

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 changes: 12 additions & 0 deletions core/src/main/cpp/version.h.in
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 0341cb3

Please sign in to comment.