feat: 统一 Commilitia Drop 全客户端命名与分发

This commit is contained in:
2026-07-31 22:56:10 +08:00
parent f7b0f04c9c
commit c480f0d1c2
77 changed files with 861 additions and 263 deletions
+36 -3
View File
@@ -10,8 +10,8 @@ import (
"strings"
)
// launchAgentLabel is the reverse-DNS label + plist filename for the per-user
// LaunchAgent that starts cdrop at login.
// launchAgentLabel is a stable internal identifier. The product name shown to
// users comes from the application metadata, not this LaunchAgent label.
const launchAgentLabel = "net.commilitia.cdrop"
func launchAgentPath() (string, error) {
@@ -71,7 +71,40 @@ func SetLaunchAtLogin(enabled bool) error {
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
return err
}
return os.WriteFile(p, []byte(buildLaunchAgentPlist(launchAgentLabel, args)), 0o644)
if err := writeLaunchAgentAtomically(
p,
[]byte(buildLaunchAgentPlist(launchAgentLabel, args)),
); err != nil {
return err
}
return nil
}
func writeLaunchAgentAtomically(path string, contents []byte) error {
dir := filepath.Dir(path)
f, err := os.CreateTemp(dir, "."+filepath.Base(path)+".tmp-*")
if err != nil {
return err
}
tempPath := f.Name()
defer os.Remove(tempPath)
if err := f.Chmod(0o644); err != nil {
f.Close()
return err
}
if _, err := f.Write(contents); err != nil {
f.Close()
return err
}
if err := f.Sync(); err != nil {
f.Close()
return err
}
if err := f.Close(); err != nil {
return err
}
return os.Rename(tempPath, path)
}
// IsLaunchAtLoginEnabled reports whether the LaunchAgent plist is present.