From 52fa329cfa25a1fbb32388198a27910ce9b68d54 Mon Sep 17 00:00:00 2001 From: Anillc Date: Wed, 1 Mar 2023 01:04:51 +0800 Subject: [PATCH] support timezone, fix #8 --- .../main/java/cn/anillc/koishi/Constant.kt | 3 ++- .../cn/anillc/koishi/services/ProotService.kt | 26 +++++++++---------- app/src/main/res/drawable/timezone.xml | 1 + app/src/main/res/values/strings.xml | 4 ++- app/src/main/res/xml/settings.xml | 6 +++++ bootstrap/bootstrap.nix | 6 ++--- bootstrap/environment/default.nix | 12 ++++++--- bootstrap/environment/login.nix | 9 ++++--- bootstrap/environment/timezone.nix | 6 +++++ bootstrap/flake.nix | 5 +--- 10 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 app/src/main/res/drawable/timezone.xml create mode 100644 bootstrap/environment/timezone.nix diff --git a/app/src/main/java/cn/anillc/koishi/Constant.kt b/app/src/main/java/cn/anillc/koishi/Constant.kt index fc02c30..b7ecde5 100644 --- a/app/src/main/java/cn/anillc/koishi/Constant.kt +++ b/app/src/main/java/cn/anillc/koishi/Constant.kt @@ -1,4 +1,5 @@ package cn.anillc.koishi const val DEFAULT_DNS = "223.5.5.5" -const val ABOUT = "Koishi Android v${BuildConfig.VERSION_NAME}\n项目开源于 GitHub koishijs/koishi-android" \ No newline at end of file +const val DEFAULT_TIMEZONE = "Asia/Shanghai" +const val ABOUT = "Koishi Android v${BuildConfig.VERSION_NAME}\n项目开源于 GitHub koishijs/koishi-android" diff --git a/app/src/main/java/cn/anillc/koishi/services/ProotService.kt b/app/src/main/java/cn/anillc/koishi/services/ProotService.kt index d2432ea..78e2aea 100644 --- a/app/src/main/java/cn/anillc/koishi/services/ProotService.kt +++ b/app/src/main/java/cn/anillc/koishi/services/ProotService.kt @@ -52,22 +52,20 @@ open class ProotService : Service(), Runnable { protected fun startProot(cmd: String, env: Map = mapOf()) { if (process.get() != null) return val prootEnv = mutableMapOf( - "KOISHI_DNS" to preferences.getString("KOISHI_DNS", DEFAULT_DNS)!! + "KOISHI_DNS" to preferences.getString("KOISHI_DNS", DEFAULT_DNS)!!, + "KOISHI_TIMEZONE" to preferences.getString("KOISHI_TIMEZONE", DEFAULT_TIMEZONE)!!, ) prootEnv.putAll(env) - this.process.set( - startProotProcess( - """ -setsid sh < \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b322806..520412e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,6 +9,8 @@ koishi 尚未启动或启动未完成 DNS 设置 点击修改 DNS 设置 + DNS 设置 + 点击修改 DNS 设置 导出 Koishi 备份 从文件中导入 Koishi 警告:此操作将会覆盖您已有的 Koishi 实例,请确认已备份后再操作 @@ -24,4 +26,4 @@ 导出文件已保存至 %s 初始化失败: %s 请在导入前停止 Koishi 实例 - \ No newline at end of file + diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 8544b89..c8bab66 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -9,6 +9,12 @@ android:title="@string/dns_settings" android:icon="@drawable/dns"/> + + /etc/resolv.conf < /etc/resolv.conf + fi + if [ -n "$KOISHI_TIMEZONE" ] && [ -e /etc/zoneinfo ]; then + /bin/ln -sf /etc/zoneinfo/$KOISHI_TIMEZONE /etc/localtiome fi for var in $(/bin/env | /bin/cut -d '=' -f 1); do unset $var; done diff --git a/bootstrap/environment/timezone.nix b/bootstrap/environment/timezone.nix new file mode 100644 index 0000000..5f7fb98 --- /dev/null +++ b/bootstrap/environment/timezone.nix @@ -0,0 +1,6 @@ +{ tzdata, runCommand }: + +runCommand "timezone" {} '' + mkdir -p $out/etc + ln -s ${tzdata}/share/zoneinfo $out/etc/zoneinfo +'' diff --git a/bootstrap/flake.nix b/bootstrap/flake.nix index bd3cd7a..4ad5ed9 100644 --- a/bootstrap/flake.nix +++ b/bootstrap/flake.nix @@ -26,10 +26,7 @@ in { packages = { bootstrap = pkgs.callPackage ./bootstrap.nix {}; - bootstrap-extra = pkgs.callPackage ./bootstrap.nix { - extraPackages = with aarch64-pkgs; [ chromium ]; - withFonts = true; - }; + bootstrap-extra = pkgs.callPackage ./bootstrap.nix { full = true; }; }; apps = let app = bootstrap: mkApp {