INNER CODE UNIT · Go

writeStartupLog

openocta/openocta · src/main.go:31

func writeStartupLog(msg string) {
	env := func(k string) string { return os.Getenv(k) }
	stateDir := paths.ResolveStateDir(env)
	_ = os.MkdirAll(stateDir, 0700)
	logPath := filepath.Join(stateDir, "desktop-startup.log")
	_ = os.WriteFile(logPath, []byte(msg+"\n"), 0600)
	// macOS: 弹窗提示用户查看日志
	if runtime.GOOS == "darwin" {
		esc := escapeForAppleScript(msg)
		_ = exec.Command("osascript", "-e", fmt.Sprintf("display alert \"OpenOcta 启动失败\" message \"%s\" & return & \"详见: %s\" as critical", esc, escapeForAppleScript(logPath))).Run()
	}
}

func escapeForAppleScript(s string) string {
	return strings.ReplaceAll(strings.ReplaceAll(s, "\\", "\\\\"), "\"", "\\\"")
}

func main() {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…