Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ What changed in each release, one line per change. Versions follow [Semantic Ver

## [Unreleased]

### Fixes

- Times in `status`, `doctor` and the event log are shown in local time with the time zone; they were UTC without saying so.
- Errors from `iphone-control update`, `service` and the update panel on the control page follow the chosen language; they were always in English.

## [0.2.14] - 2026-11-24

### New
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

## [Unreleased]

### 修复

- `status`、`doctor` 和事件日志里的时间改为本地时间并标明时区,之前显示的是 UTC 却没有说明。
- `iphone-control update`、`service` 和控制台更新面板里的报错跟随界面语言,之前总是英文。

## [0.2.14] - 2026-11-24

### 新功能
Expand Down
2 changes: 1 addition & 1 deletion apps/iphone-control/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ async fn update_command(action: UpdateAction, socket: &Path) -> anyhow::Result<(
println!("{report}");
}
if let Some(code) = report.error_code {
bail!("Update check failed: {code}")
bail!("{}", ictl_l10n::trf!("检查更新失败:{code}", "Update check failed: {code}"))
}
Ok(())
}
Expand Down
46 changes: 35 additions & 11 deletions apps/iphone-control/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ pub fn set_policy(socket: &Path, policy: update::Policy) -> Result<()> {
if let Err(e) = configure_job(socket, policy) {
// A partial timer install must not later run with unintended permission to replace files.
update::set_policy(update::Policy::Manual)?;
bail!("Update policy is manual; could not configure the user job: {e:#}")
bail!(
"{}",
ictl_l10n::trf!(
"更新策略已改为手动:配置不了自动更新任务:{e:#}",
"Update policy is manual; could not configure the user job: {e:#}"
)
)
}
println!(
"{}: {}",
Expand All @@ -44,7 +50,8 @@ fn configuration_locks() -> Result<(File, File)> {
.custom_flags(libc::O_NOFOLLOW)
.open(config.join("update-schedule.lock"))?;
if unsafe { libc::flock(lock.as_raw_fd(), libc::LOCK_EX) } != 0 {
return Err(std::io::Error::last_os_error()).context("could not lock the update schedule");
return Err(std::io::Error::last_os_error())
.context(ictl_l10n::tr!("锁不住自动更新的设置", "could not lock the update schedule"));
}
Ok((lock, ictl_daemon::maintenance::shared()?))
}
Expand All @@ -55,7 +62,7 @@ pub fn configure(socket: &Path) -> Result<()> {
}

fn write_file(path: &Path, bytes: &[u8]) -> Result<()> {
fs::create_dir_all(path.parent().context("invalid job path")?)?;
fs::create_dir_all(path.parent().context(ictl_l10n::tr!("自动更新任务的路径不对", "invalid job path"))?)?;
crate::update::write_atomic(path, bytes)
}

Expand All @@ -71,15 +78,19 @@ fn run(program: &str, args: &[&str]) -> Result<()> {
}

fn path_str(path: &Path) -> Result<&str> {
let s = path.to_str().context("non UTF-8 update job path")?;
ensure!(path.is_absolute() && !s.contains(['\r', '\n']), "expected an absolute update job path");
let s = path.to_str().context(ictl_l10n::tr!("自动更新任务的路径不是 UTF-8", "non UTF-8 update job path"))?;
ensure!(
path.is_absolute() && !s.contains(['\r', '\n']),
"{}",
ictl_l10n::tr!("自动更新任务的路径要是绝对路径", "expected an absolute update job path")
);
Ok(s)
}

fn launcher(exe: &Path, socket: &Path, config: &Path) -> Result<String> {
let exe = shell_quote(path_str(exe)?);
let sock = shell_quote(path_str(socket)?);
let xdg = shell_quote(path_str(config.parent().context("missing config home")?)?);
let xdg = shell_quote(path_str(config.parent().context(ictl_l10n::tr!("找不到配置目录", "missing config home"))?)?);
// launchd and the interactive shell often have different XDG environments. The timer
// must see the same release cache as Viewer, including a custom cache location.
let mut xdg_env = String::new();
Expand Down Expand Up @@ -111,7 +122,7 @@ fn configure_job(socket: &Path, policy: update::Policy) -> Result<()> {
let jobs = if mac {
envfile::home().join("Library/LaunchAgents")
} else {
config.parent().context("missing config home")?.join("systemd/user")
config.parent().context(ictl_l10n::tr!("找不到配置目录", "missing config home"))?.join("systemd/user")
};
let job = jobs.join(if mac { format!("{LABEL}.plist") } else { UNIT.into() });
let timer = jobs.join(TIMER);
Expand All @@ -121,15 +132,24 @@ fn configure_job(socket: &Path, policy: update::Policy) -> Result<()> {
if launcher_file.try_exists()? {
ensure!(
fs::read_to_string(&launcher_file)?.lines().nth(2) == Some(owner.as_str()),
"the updater job belongs to a different executable"
"{}",
ictl_l10n::tr!("自动更新任务属于另一个程序", "the updater job belongs to a different executable")
);
} else {
ensure!(!job.try_exists()? && (mac || !timer.try_exists()?), "an unrecognized update job already exists");
ensure!(
!job.try_exists()? && (mac || !timer.try_exists()?),
"{}",
ictl_l10n::tr!("已经有一个认不出来的自动更新任务", "an unrecognized update job already exists")
);
if !enabled {
return Ok(());
}
}
ensure!(!ictl_daemon::protocol::running_as_root(), "only user update jobs are supported");
ensure!(
!ictl_daemon::protocol::running_as_root(),
"{}",
ictl_l10n::tr!("只支持用户级的自动更新任务", "only user update jobs are supported")
);
if enabled {
write_file(&launcher_file, launcher(&service::stable_exe()?, socket, &config)?.as_bytes())?;
}
Expand All @@ -140,7 +160,11 @@ fn configure_job(socket: &Path, policy: update::Policy) -> Result<()> {
let loaded = if loaded.status.success() {
let listing = std::str::from_utf8(&loaded.stdout)?;
let path = listing.lines().find_map(|line| line.strip_prefix('\t')?.strip_prefix("path = "));
ensure!(path.map(Path::new) == Some(&job), "launchd loaded a different updater plist");
ensure!(
path.map(Path::new) == Some(&job),
"{}",
ictl_l10n::tr!("launchd 载入的是另一个自动更新 plist", "launchd loaded a different updater plist")
);
true
} else {
false
Expand Down
77 changes: 57 additions & 20 deletions apps/iphone-control/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,24 @@ pub fn managed(exe: &Path, method: &str) -> anyhow::Result<Service> {
(our_plist(), Service::Launchd { label: LABEL.into(), plist: our_plist(), ours: true })
}
"systemd" if cfg!(target_os = "linux") => (our_unit(), Service::Systemd { unit: UNIT.into(), ours: true }),
_ => bail!("a script-managed user service is required"),
_ => bail!("{}", ictl_l10n::tr!("需要由安装脚本管理的用户服务", "a script-managed user service is required")),
};
let meta = file.symlink_metadata()?;
ensure!(meta.is_file() && meta.uid() == uid() && meta.mode() & 0o022 == 0, "untrusted service file");
let exe = exe.to_str().context("invalid executable path")?;
ensure!(
meta.is_file() && meta.uid() == uid() && meta.mode() & 0o022 == 0,
"{}",
ictl_l10n::tr!("后台服务文件不可信", "untrusted service file")
);
let exe = exe.to_str().context(ictl_l10n::tr!("程序路径不对", "invalid executable path"))?;
match &service {
Service::Launchd { label, .. } => {
let plist = plist::Value::from_file(&file)?;
let dict = plist.as_dictionary().context("invalid service plist")?;
let args = dict.get("ProgramArguments").and_then(|v| v.as_array()).context("missing service arguments")?;
let dict =
plist.as_dictionary().context(ictl_l10n::tr!("后台服务的 plist 不对", "invalid service plist"))?;
let args = dict
.get("ProgramArguments")
.and_then(|v| v.as_array())
.context(ictl_l10n::tr!("后台服务缺少启动参数", "missing service arguments"))?;
let script = format!(
r#"set -a; f="$HOME/.config/iphone-control/env"; [ -f "$f" ] && . "$f"; set +a; exec "{exe}" daemon"#
);
Expand All @@ -149,18 +157,26 @@ pub fn managed(exe: &Path, method: &str) -> anyhow::Result<Service> {
&& !dict.contains_key("Program")
&& (args.iter().map(|v| v.as_string()).eq([Some(exe), Some("daemon")])
|| args.iter().map(|v| v.as_string()).eq([Some("/bin/sh"), Some("-c"), Some(script.as_str())])),
"the launch agent does not start the recorded binary"
"{}",
ictl_l10n::tr!(
"launchd 服务启动的不是记录里的程序",
"the launch agent does not start the recorded binary"
)
);
}
Service::Systemd { .. } => {
let unit = std::fs::read_to_string(&file)?;
let mut commands = unit.lines().filter_map(|line| line.trim().strip_prefix("ExecStart="));
let command = commands.next().context("missing ExecStart")?;
let command = commands.next().context(ictl_l10n::tr!("缺少 ExecStart", "missing ExecStart"))?;
ensure!(
commands.next().is_none()
&& (command == format!(r#""{exe}" daemon"#)
|| (!exe.contains(char::is_whitespace) && command == format!("{exe} daemon"))),
"the systemd unit does not start the recorded binary"
"{}",
ictl_l10n::tr!(
"systemd 服务启动的不是记录里的程序",
"the systemd unit does not start the recorded binary"
)
);
}
}
Expand All @@ -179,7 +195,8 @@ pub fn managed_pid(service: &Service, stopping: bool) -> anyhow::Result<Option<u
if !out.status.success() {
ensure!(
String::from_utf8_lossy(&out.stderr).contains("Could not find service"),
"cannot query launchd"
"{}",
ictl_l10n::tr!("查不了 launchd", "cannot query launchd")
);
return Ok(None);
}
Expand All @@ -195,23 +212,31 @@ pub fn managed_pid(service: &Service, stopping: bool) -> anyhow::Result<Option<u
"--property=ActiveState,LoadState,MainPID,FragmentPath,DropInPaths,NeedDaemonReload",
])
.output()?;
ensure!(out.status.success(), "cannot query systemd user service");
ensure!(
out.status.success(),
"{}",
ictl_l10n::tr!("查不了 systemd 用户服务", "cannot query systemd user service")
);
let info = std::str::from_utf8(&out.stdout)?;
let field = |key: &str| info.lines().find_map(|line| line.strip_prefix(key));
ensure!(
field("LoadState=") == Some("loaded")
&& field("NeedDaemonReload=") == Some("no")
&& field("FragmentPath=").map(Path::new) == Some(our_unit().as_path())
&& field("DropInPaths=") == Some(""),
"systemd unit is stale or overridden"
"{}",
ictl_l10n::tr!("systemd 服务文件过期或被覆盖了", "systemd unit is stale or overridden")
);
match (field("ActiveState="), field("MainPID=")) {
(Some("inactive" | "failed"), Some("0")) => Ok(None),
(Some("active"), Some(pid)) => {
Ok(Some(pid.parse::<u32>().ok().filter(|p| *p > 0).context("missing MainPID")?))
}
(Some("active"), Some(pid)) => Ok(Some(
pid.parse::<u32>()
.ok()
.filter(|p| *p > 0)
.context(ictl_l10n::tr!("缺少 MainPID", "missing MainPID"))?,
)),
(_, Some(pid)) if stopping => Ok(pid.parse::<u32>().ok().filter(|p| *p > 0)),
_ => bail!("systemd service is transitioning"),
_ => bail!("{}", ictl_l10n::tr!("systemd 服务正在启动或停止", "systemd service is transitioning")),
}
}
}
Expand All @@ -222,19 +247,31 @@ pub fn managed_pid(service: &Service, stopping: bool) -> anyhow::Result<Option<u
/// with no PID, for good: like an inactive systemd unit, it is stopped, not transitioning
fn launchd_pid(info: &str, plist: &Path, stopping: bool) -> anyhow::Result<Option<u32>> {
let field = |key: &str| info.lines().find_map(|line| line.strip_prefix('\t')?.strip_prefix(key));
ensure!(field("path = ").map(Path::new) == Some(plist), "launchd loaded a different plist");
ensure!(
field("path = ").map(Path::new) == Some(plist),
"{}",
ictl_l10n::tr!("launchd 载入的是另一个 plist", "launchd loaded a different plist")
);
let pid = field("pid = ");
if pid.is_none() && (stopping || field("state = ") == Some("not running")) {
return Ok(None);
}
ensure!(stopping || field("state = ") == Some("running"), "launchd service is transitioning");
Ok(Some(pid.context("no launchd PID")?.parse()?))
ensure!(
stopping || field("state = ") == Some("running"),
"{}",
ictl_l10n::tr!("launchd 服务正在启动或停止", "launchd service is transitioning")
);
Ok(Some(pid.context(ictl_l10n::tr!("launchd 没有给出进程号", "no launchd PID"))?.parse()?))
}

/// Restart exactly the service we stopped without changing the user's enable-at-login setting.
pub fn start_managed(s: &Service) -> anyhow::Result<()> {
if let Service::Systemd { unit, .. } = s {
ensure!(systemctl(&["start", unit]), "could not start systemd user service");
ensure!(
systemctl(&["start", unit]),
"{}",
ictl_l10n::tr!("启动不了 systemd 用户服务", "could not start systemd user service")
);
Ok(())
} else {
start(s)
Expand Down Expand Up @@ -570,7 +607,7 @@ pub fn pause_viewer() -> anyhow::Result<Option<Service>> {
std::thread::sleep(std::time::Duration::from_millis(200));
}
let _ = start(&s);
bail!("busy: the viewer service didn't stop")
bail!("{}", ictl_l10n::tr!("正忙:控制台服务没有停下", "busy: the viewer service didn't stop"))
}

/// Starts the control page's service again after [`pause_viewer`]; a failure is only reported
Expand Down
9 changes: 7 additions & 2 deletions apps/iphone-control/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ impl Report {
/// (the updater's store is private and checked, see `transaction::Store::open`)
pub(crate) fn write_atomic(path: &Path, bytes: &[u8]) -> Result<()> {
use std::io::Write;
let dir = path.parent().ok_or_else(|| anyhow::anyhow!("no parent directory: {}", path.display()))?;
let dir = path.parent().ok_or_else(|| {
anyhow::anyhow!("{}", ictl_l10n::trf!("没有上级目录:{}", "no parent directory: {}", path.display()))
})?;
let mut tmp = tempfile::NamedTempFile::new_in(dir)?;
tmp.write_all(bytes)?;
tmp.as_file().sync_all()?;
Expand Down Expand Up @@ -490,7 +492,10 @@ pub async fn upgrade(socket: &Path, report: Report, yes: bool) -> Result<()> {
if !confirm(&report, yes)? {
return Ok(());
}
let version = report.available_version.clone().ok_or_else(|| anyhow::anyhow!("missing release version"))?;
let version = report
.available_version
.clone()
.ok_or_else(|| anyhow::anyhow!("{}", ictl_l10n::tr!("缺少发布版本号", "missing release version")))?;
transaction::apply(socket, false, report).await?;
println!("{}", trf!("已升级到 {version}。", "Updated to {version}."));
}
Expand Down
Loading
Loading