feat(autostart): 支持 MacOS
This commit is contained in:
parent
2a899712d5
commit
477a579044
@ -2,13 +2,15 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2022 KAAAsS
|
# Copyright (C) 2022 KAAAsS
|
||||||
|
|
||||||
# 设置自启脚本
|
use constraints.nu
|
||||||
export def install [
|
|
||||||
path: path
|
module linux {
|
||||||
] {
|
export def install [
|
||||||
let filename = ($path | path basename)
|
path: path
|
||||||
mkdir $"($env.HOME_DIR)/.config/autostart"
|
] {
|
||||||
echo $"[Desktop Entry]
|
let filename = ($path | path basename)
|
||||||
|
mkdir $"($env.HOME_DIR)/.config/autostart"
|
||||||
|
echo $"[Desktop Entry]
|
||||||
Exec=($path)
|
Exec=($path)
|
||||||
Icon=dialog-scripts
|
Icon=dialog-scripts
|
||||||
Name=($filename)
|
Name=($filename)
|
||||||
@ -16,6 +18,68 @@ Path=
|
|||||||
Type=Application
|
Type=Application
|
||||||
X-KDE-AutostartScript=true
|
X-KDE-AutostartScript=true
|
||||||
" | save -f $"($env.HOME_DIR)/.config/autostart/($filename).desktop"
|
" | 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
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +87,12 @@ X-KDE-AutostartScript=true
|
|||||||
export def uninstall [
|
export def uninstall [
|
||||||
path: path
|
path: path
|
||||||
] {
|
] {
|
||||||
let filename = ($path | path basename)
|
if (constraints os linux) {
|
||||||
rm -f $"($env.HOME_DIR)/.config/autostart/($filename).desktop"
|
linux uninstall $path
|
||||||
|
} else if (constraints os darwin) {
|
||||||
|
darwin uninstall $path
|
||||||
|
} else {
|
||||||
|
error make { msg: "当前系统不支持自启脚本" }
|
||||||
|
}
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user