Skip to content

Commit 4c731d3

Browse files
authored
Merge pull request #1461 from bdyebd/develop
Delay write of plist file to fix frequent notification issue on Ventura
2 parents e42131e + 6c8c162 commit 4c731d3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ShadowsocksX-NG/LaunchAgentUtils.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func generateSSLocalLauchAgentPlist() -> Bool {
3232
let sslocalPath = NSHomeDirectory() + APP_SUPPORT_DIR + "ss-local/ss-local"
3333
let logFilePath = NSHomeDirectory() + "/Library/Logs/ss-local.log"
3434
let launchAgentDirPath = NSHomeDirectory() + LAUNCH_AGENT_DIR
35+
let plistTempFilepath = NSHomeDirectory() + APP_SUPPORT_DIR + LAUNCH_AGENT_CONF_SSLOCAL_NAME
3536
let plistFilepath = launchAgentDirPath + LAUNCH_AGENT_CONF_SSLOCAL_NAME
3637

3738
// Ensure launch agent directory is existed.
@@ -69,9 +70,10 @@ func generateSSLocalLauchAgentPlist() -> Bool {
6970
"ProgramArguments": arguments,
7071
"EnvironmentVariables": ["DYLD_LIBRARY_PATH": dyld_library_paths.joined(separator: ":")]
7172
]
72-
dict.write(toFile: plistFilepath, atomically: true)
73-
let Sha1Sum = getFileSHA1Sum(plistFilepath)
73+
dict.write(toFile: plistTempFilepath, atomically: true)
74+
let Sha1Sum = getFileSHA1Sum(plistTempFilepath)
7475
if oldSha1Sum != Sha1Sum {
76+
dict.write(toFile: plistFilepath, atomically: true)
7577
NSLog("generateSSLocalLauchAgentPlist - File has been changed.")
7678
return true
7779
} else {
@@ -283,6 +285,7 @@ func generatePrivoxyLauchAgentPlist() -> Bool {
283285
let privoxyPath = NSHomeDirectory() + APP_SUPPORT_DIR + "privoxy/privoxy"
284286
let logFilePath = NSHomeDirectory() + "/Library/Logs/privoxy.log"
285287
let launchAgentDirPath = NSHomeDirectory() + LAUNCH_AGENT_DIR
288+
let plistTempFilePath = NSHomeDirectory() + APP_SUPPORT_DIR + LAUNCH_AGENT_CONF_PRIVOXY_NAME
286289
let plistFilepath = launchAgentDirPath + LAUNCH_AGENT_CONF_PRIVOXY_NAME
287290

288291
// Ensure launch agent directory is existed.
@@ -303,9 +306,10 @@ func generatePrivoxyLauchAgentPlist() -> Bool {
303306
"StandardErrorPath": logFilePath,
304307
"ProgramArguments": arguments
305308
]
306-
dict.write(toFile: plistFilepath, atomically: true)
307-
let Sha1Sum = getFileSHA1Sum(plistFilepath)
309+
dict.write(toFile: plistTempFilePath, atomically: true)
310+
let Sha1Sum = getFileSHA1Sum(plistTempFilePath)
308311
if oldSha1Sum != Sha1Sum {
312+
dict.write(toFile: plistFilepath, atomically: true)
309313
return true
310314
} else {
311315
return false

0 commit comments

Comments
 (0)