1+ name :' Modify Source Code'
2+ description :' Modify source code based on client type'
3+ inputs :
4+ appname :
5+ description :' App name'
6+ required :true
7+
8+ runs :
9+ using :' composite'
10+ steps :
11+ -name :Modify source code for ${{ inputs.appname }}
12+ shell :bash
13+ if :${{ inputs.appname != 'RustDesk' }}
14+ run :|
15+ APP_NAME_LOWER=$(echo "${{ inputs.appname }}" | awk '{print tolower($0)}')
16+ echo "Modifying source code for ${{ inputs.appname }}, app name in lowercase: ${APP_NAME_LOWER}"
17+
18+ # libs/hbb_common/src/config.rs
19+ if [[ "$OSTYPE" == "darwin"* ]]; then
20+ sed -i '' "s/pub static ref APP_NAME: RwLock<String> = RwLock::new(\"RustDesk\".to_owned());/pub static ref APP_NAME: RwLock<String> = RwLock::new(\"${{ inputs.appname }}\".to_owned());/g" libs/hbb_common/src/config.rs
21+ else
22+ sed -i "s/pub static ref APP_NAME: RwLock<String> = RwLock::new(\"RustDesk\".to_owned());/pub static ref APP_NAME: RwLock<String> = RwLock::new(\"${{ inputs.appname }}\".to_owned());/g" libs/hbb_common/src/config.rs
23+ fi
24+ echo "Modified APP_NAME in libs/hbb_common/src/config.rs"
25+
26+ # libs/portable/src/main.rs
27+ if [[ "$OSTYPE" == "darwin"* ]]; then
28+ sed -E -i '' 's/const APP_PREFIX: &str = "([^"]*)".*/const APP_PREFIX: \&str = "${APP_NAME_LOWER}";/g' libs/portable/src/main.rs
29+ else
30+ sed -E -i 's/const APP_PREFIX: &str = "([^"]*)".*/const APP_PREFIX: \&str = "${APP_NAME_LOWER}";/g' libs/portable/src/main.rs
31+ fi
32+ echo "Modified APP_PREFIX in libs/portable/src/main.rs"
33+
34+ # android/app/src/main/AndroidManifest.xml
35+ if [[ "$OSTYPE" == "darwin"* ]]; then
36+ sed -i '' "s/RustDesk/${{ inputs.appname }}/g" flutter/android/app/src/main/AndroidManifest.xml
37+ sed -i '' "s/rustdesk/${APP_NAME_LOWER}/g" flutter/android/app/src/main/AndroidManifest.xml
38+ else
39+ sed -i "s/RustDesk/${{ inputs.appname }}/g" flutter/android/app/src/main/AndroidManifest.xml
40+ sed -i "s/rustdesk/${APP_NAME_LOWER}/g" flutter/android/app/src/main/AndroidManifest.xml
41+ fi
42+ echo "Modified AndroidManifest.xml"
43+
44+ # android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt
45+ if [[ "$OSTYPE" == "darwin"* ]]; then
46+ sed -i '' "s/RustDesk/${{ inputs.appname }}/g" flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt
47+ sed -i '' "s/rustdesk/${APP_NAME_LOWER}/g" flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt
48+ else
49+ sed -i "s/RustDesk/${{ inputs.appname }}/g" flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt
50+ sed -i "s/rustdesk/${APP_NAME_LOWER}/g" flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt
51+ fi
52+ echo "Modified MainService.kt"
53+
54+ # flutter/android/app/build.gradle - modify applicationId
55+ # https://developer.android.com/guide/topics/manifest/manifest-element
56+ APP_NAME_UNDERSCORE=$(echo "${APP_NAME_LOWER}" | sed 's/-/_/g')
57+ if [[ "$OSTYPE" == "darwin"* ]]; then
58+ sed -i '' "s/applicationId \"com.carriez.flutter_hbb\"/applicationId \"com.carriez.flutter_hbb.${APP_NAME_UNDERSCORE}\"/g" flutter/android/app/build.gradle
59+ else
60+ sed -i "s/applicationId \"com.carriez.flutter_hbb\"/applicationId \"com.carriez.flutter_hbb.${APP_NAME_UNDERSCORE}\"/g" flutter/android/app/build.gradle
61+ fi
62+ echo "Modified applicationId in build.gradle to com.carriez.flutter_hbb.${APP_NAME_UNDERSCORE}"
63+
64+ # src/server/dbus.rs - modify DBUS_NAME
65+ # https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
66+ if [[ "$OSTYPE" == "darwin"* ]]; then
67+ sed -i '' "s/const DBUS_NAME: \&str = \"org.rustdesk.rustdesk\";/const DBUS_NAME: \&str = \"com.rustdesk.${APP_NAME_UNDERSCORE}\";/g" src/server/dbus.rs
68+ else
69+ sed -i "s/const DBUS_NAME: \&str = \"org.rustdesk.rustdesk\";/const DBUS_NAME: \&str = \"com.rustdesk.${APP_NAME_UNDERSCORE}\";/g" src/server/dbus.rs
70+ fi
71+ echo "Modified DBUS_NAME in src/server/dbus.rs to com.rustdesk.${APP_NAME_UNDERSCORE}"
72+