feat(autostart): 支持 MacOS
This commit is contained in:
parent
2a899712d5
commit
477a579044
@ -2,13 +2,15 @@
|
||||
#
|
||||
# Copyright (C) 2022 KAAAsS
|
||||
|
||||
# 设置自启脚本
|
||||
export def install [
|
||||
path: path
|
||||
] {
|
||||
let filename = ($path | path basename)
|
||||
mkdir $"($env.HOME_DIR)/.config/autostart"
|
||||
echo $"[Desktop Entry]
|
||||
use constraints.nu
|
||||
|
||||
module linux {
|
||||
export def install [
|
||||
path: path
|
||||
] {
|
||||
let filename = ($path | path basename)
|
||||
mkdir $"($env.HOME_DIR)/.config/autostart"
|
||||
echo $"[Desktop Entry]
|
||||
Exec=($path)
|
||||
Icon=dialog-scripts
|
||||
Name=($filename)
|
||||
@ -16,6 +18,68 @@ Path=
|
||||
Type=Application
|
||||
X-KDE-AutostartScript=true
|
||||
" | save -f $"($env.HOME_DIR)/.config/autostart/($filename).desktop"
|
||||
null
|
||||
}
|
||||
|
||||
export def uninstall [
|
||||
path: path
|
||||
] {
|
||||
let filename = ($path | path basename)
|
||||
rm -f $"($env.HOME_DIR)/.config/autostart/($filename).desktop"
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
module darwin {
|
||||
export def install [
|
||||
path: path
|
||||
] {
|
||||
let filename = ($path | path basename)
|
||||
mkdir $"($env.HOME_DIR)/Library/LaunchAgents"
|
||||
echo $"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
|
||||
<plist version=\"1.0\">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>($filename)</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>($path)</string>
|
||||
</array>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
" | save -f $"($env.HOME_DIR)/Library/LaunchAgents/($filename).plist"
|
||||
launchctl load $"($env.HOME_DIR)/Library/LaunchAgents/($filename).plist"
|
||||
null
|
||||
}
|
||||
|
||||
export def uninstall [
|
||||
path: path
|
||||
] {
|
||||
let filename = ($path | path basename)
|
||||
launchctl stop $"($filename)"
|
||||
launchctl unload $"($env.HOME_DIR)/Library/LaunchAgents/($filename).plist"
|
||||
rm -f $"($env.HOME_DIR)/Library/LaunchAgents/($filename).plist"
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
use linux
|
||||
use darwin
|
||||
|
||||
# 设置自启脚本
|
||||
export def install [
|
||||
path: path
|
||||
] {
|
||||
if (constraints os linux) {
|
||||
linux install $path
|
||||
} else if (constraints os darwin) {
|
||||
darwin install $path
|
||||
} else {
|
||||
error make { msg: "当前系统不支持自启脚本" }
|
||||
}
|
||||
null
|
||||
}
|
||||
|
||||
@ -23,7 +87,12 @@ X-KDE-AutostartScript=true
|
||||
export def uninstall [
|
||||
path: path
|
||||
] {
|
||||
let filename = ($path | path basename)
|
||||
rm -f $"($env.HOME_DIR)/.config/autostart/($filename).desktop"
|
||||
if (constraints os linux) {
|
||||
linux uninstall $path
|
||||
} else if (constraints os darwin) {
|
||||
darwin uninstall $path
|
||||
} else {
|
||||
error make { msg: "当前系统不支持自启脚本" }
|
||||
}
|
||||
null
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user