Skip to content

Commit 0341cb3

Browse files
committed
关于界面添加核心构建信息 (#173)
1 parent d7246f1 commit 0341cb3

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

app/src/main/java/com/github/kr328/clash/MainActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.github.kr328.clash.util.startClashService
99
import com.github.kr328.clash.util.stopClashService
1010
import com.github.kr328.clash.util.withClash
1111
import com.github.kr328.clash.util.withProfile
12+
import com.github.kr328.clash.core.bridge.*
1213
import kotlinx.coroutines.Dispatchers
1314
import kotlinx.coroutines.isActive
1415
import kotlinx.coroutines.selects.select
@@ -125,7 +126,7 @@ class MainActivity : BaseActivity<MainDesign>() {
125126

126127
private suspend fun queryAppVersionName(): String {
127128
return withContext(Dispatchers.IO) {
128-
packageManager.getPackageInfo(packageName, 0).versionName
129+
packageManager.getPackageInfo(packageName, 0).versionName + "\n" + Bridge.nativeCoreVersion().replace("_", "-")
129130
}
130131
}
131132
}

core/src/main/cpp/CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,54 @@
11
cmake_minimum_required(VERSION 3.0)
22

3+
# 获取git hash
4+
5+
message(STATUS "CMAKE_CURRENT_SOURCE_DIR= ${CMAKE_CURRENT_SOURCE_DIR}")
6+
execute_process(
7+
COMMAND git submodule foreach git log -1 --format=%H
8+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
9+
OUTPUT_VARIABLE COMMIT_HASH
10+
)
11+
string(REPLACE "\n" ";" COMMIT_HASH "${COMMIT_HASH}")
12+
list(GET COMMIT_HASH 1 COMMIT_HASH)
13+
string (REGEX REPLACE "[\n\t\r]" "" COMMIT_HASH ${COMMIT_HASH})
14+
string(SUBSTRING ${COMMIT_HASH} 0 7 COMMIT_HASH)
15+
message(STATUS "git hash= ${COMMIT_HASH}")
16+
17+
# 获取分支名称
18+
execute_process(
19+
COMMAND git submodule foreach git branch -r --contains ${COMMIT_HASH}
20+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
21+
OUTPUT_VARIABLE CURRENT_BRANCH
22+
)
23+
string(REPLACE "\n" ";" CURRENT_BRANCH "${CURRENT_BRANCH}")
24+
list(GET CURRENT_BRANCH 1 CURRENT_BRANCH)
25+
string (REGEX REPLACE "origin/" "" CURRENT_BRANCH ${CURRENT_BRANCH})
26+
string (REGEX REPLACE "[\n\t\r]" "" CURRENT_BRANCH ${CURRENT_BRANCH})
27+
#string(SUBSTRING ${CURRENT_BRANCH} 0 8 CURRENT_BRANCH)
28+
message(STATUS "git current branch = ${CURRENT_BRANCH}")
29+
30+
# 获取生成时间
31+
execute_process(
32+
COMMAND date +"%y%m%d"
33+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
34+
OUTPUT_VARIABLE COMPILE_TIME
35+
)
36+
string (REGEX REPLACE "[\n\t\r]" "" COMPILE_TIME ${COMPILE_TIME})
37+
string(REGEX REPLACE "\"" "" COMPILE_TIME ${COMPILE_TIME})
38+
39+
# 生成版本信息
40+
set(GIT_VERSION "Meta_${CURRENT_BRANCH}_${COMMIT_HASH}_${COMPILE_TIME}")
41+
message(STATUS "version info = ${GIT_VERSION}")
42+
43+
# 去除空格
44+
string(REGEX REPLACE "[ ]+" "" GIT_VERSION "${GIT_VERSION}")
45+
46+
# 保存变量到文件
47+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/version.h @ONLY)
48+
349
project(clash-bridge C)
450

51+
552
set(CMAKE_POSITION_INDEPENDENT_CODE on)
653
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
754

core/src/main/cpp/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "jni_helper.h"
99
#include "trace.h"
1010

11+
#include "version.h" // 添加当前编译core版本号变量
12+
13+
1114
JNIEXPORT void JNICALL
1215
Java_com_github_kr328_clash_core_bridge_Bridge_nativeInit(JNIEnv *env, jobject thiz,
1316
jstring home,
@@ -330,6 +333,7 @@ Java_com_github_kr328_clash_core_bridge_Bridge_nativeSubscribeLogcat(JNIEnv *env
330333
subscribeLogcat(_callback);
331334
}
332335

336+
333337
static jmethodID m_tun_interface_mark_socket;
334338
static jmethodID m_tun_interface_query_socket_uid;
335339
static jmethodID m_completable_complete;
@@ -537,4 +541,13 @@ JNI_OnLoad(JavaVM *vm, void *reserved) {
537541
release_object_func = &release_jni_object_impl;
538542

539543
return JNI_VERSION_1_6;
544+
}
545+
546+
JNIEXPORT jstring JNICALL
547+
Java_com_github_kr328_clash_core_bridge_Bridge_nativeCoreVersion(JNIEnv *env, jobject thiz) {
548+
TRACE_METHOD();
549+
550+
char* Version = make_String(GIT_VERSION);
551+
552+
return new_string(Version);
540553
}

core/src/main/cpp/version.h.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef VERSION_H_IN
2+
#define VERSION_H_IN
3+
4+
/**
5+
* 当前编译core版本号
6+
*/
7+
8+
#define GIT_VERSION @GIT_VERSION@
9+
#define make_Str(x) #x
10+
#define make_String(x) make_Str(x)
11+
12+
#endif

core/src/main/java/com/github/kr328/clash/core/bridge/Bridge.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ object Bridge {
4949
external fun nativeInstallSideloadGeoip(data: ByteArray?)
5050
external fun nativeQueryConfiguration(): String
5151
external fun nativeSubscribeLogcat(callback: LogcatInterface)
52+
external fun nativeCoreVersion(): String
5253

5354
private external fun nativeInit(home: String, versionName: String, sdkVersion: Int)
5455

0 commit comments

Comments
 (0)