-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmake.lua
More file actions
79 lines (65 loc) · 3.31 KB
/
xmake.lua
File metadata and controls
79 lines (65 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
set_project("auto-blue")
set_version("1.0.0")
set_xmakever("3.0.3")
set_allowedplats("windows")
set_license("Apache-2.0")
add_rules("mode.debug", "mode.release")
add_rules("plugin.compile_commands.autoupdate", {outputdir = "build"})
set_languages("cxx20")
add_requires("nuget::Microsoft.Windows.CppWinRT", {alias = "cppwinrt"})
add_requires("spdlog")
target("auto-blue")
set_kind("binary")
add_files("src/main.cpp")
add_includedirs("include")
set_installdir("$(scriptdir)/install")
add_installfiles("README.md", "license")
add_cxflags("/utf-8", "/EHsc", "/permissive-")
add_packages("cppwinrt", "spdlog")
add_links("WindowsApp", "user32")
after_install(function(target)
cprint("${green}Enabling auto-start setting for auto-blue...")
local ab_dir = path.join(target:installdir(), "bin", target:filename())
local register_task = string.format([[Register-ScheduledTask -TaskName 'abAutoBlueTooth' -Action (New-ScheduledTaskAction -Execute '%s') -Trigger (New-ScheduledTaskTrigger -AtLogOn) -Settings (New-ScheduledTaskSettingsSet -ExecutionTimeLimit ([TimeSpan]::Zero) -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable) -RunLevel Highest -Force]], ab_dir)
import("lib.detect.find_tool")
local powershell = (find_tool("powershell") or find_tool("pwsh") or {}).program
if not powershell then
cprint("${red}Found no powershell. Plz consider manually setting this auto-start feature.")
return
end
local admin_wrapper = string.format([[Start-Process -FilePath "%s" -Verb RunAs -ArgumentList "-NoProfile -Command &{ %s } -Wait"]], powershell, register_task)
local ok, err = os.execv(powershell, {"-Command", admin_wrapper, "-Wait"})
if ok == 0 then
cprint("${green}Successfully finished the auto-start setting!")
else
cprint("${red}Failed to excute the powershell script due to", err)
end
end)
before_uninstall(function(target)
cprint("${green}Removing auto-start setting for auto-blue...")
import("lib.detect.find_tool")
local powershell = (find_tool("powershell") or find_tool("pwsh") or {}).program
if not powershell then
cprint("${red}Found no powershell. Plz consider manually removing the scheduled task.")
return
end
local admin_wrapper = string.format([[Start-Process -FilePath "schtasks" -Verb RunAs -ArgumentList '/Delete','/TN','abAutoBlueTooth','/F' -Wait]])
local ok, err = os.execv(powershell, {"-Command", admin_wrapper})
if ok == 0 then
cprint("${green}Successfully removed the auto-start setting!")
else
cprint("${red}Failed to remove the scheduled task due to", err)
end
end)
target_end()
includes("@builtin/xpack")
xpack("AutoBlue")
set_formats("zip")
set_title("auto-blue")
set_description("Automatically turn Bluetooth on and off according to the power status of the Windows laptop.")
set_author("Willaaaaaaa <willaaaaaaa936@gmail.com>")
set_homepage("https://github.com/Willaaaaaaa/auto-blue")
set_licensefile("LICENSE")
add_targets("auto-blue")
add_installfiles("scripts/**")
add_installfiles("README.md")