-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtray.lua
More file actions
87 lines (77 loc) · 3.18 KB
/
tray.lua
File metadata and controls
87 lines (77 loc) · 3.18 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
80
81
82
83
84
85
86
87
local ID_EXIT = 100
local ID_CONFIG_DISABLE_DESKTOP_EFFECTS = 101
local ID_CONFIG_SET_CPU_AFFINITY = 102
local ID_CONFIG_DISABLE_NON_PRIMARY_DISPLAYS = 103
local ID_CONFIG_ENSURE_RUNNING_AS_ADMIN = 104
local ID_OPEN_GAME_GUI = 200
local ID_VERSION_INFO = 300
-- Cleanup existing tray if needed
gcb.tray.destroy()
-- Initialize tray with version in tooltip
local tooltip = string.format("Game Core Bind - Version %d (%s)", gcb.version.Build, gcb.version.GitRev)
gcb.tray.init(tooltip)
-- Version info as disabled menu entry
local versionText = string.format("Version %d (%s)", gcb.version.Build, gcb.version.GitRev)
gcb.tray.addMenuItem(versionText, ID_VERSION_INFO)
-- Open GUI
gcb.tray.addMenuItem("Edit Games", ID_OPEN_GAME_GUI)
-- Create config submenu
local configMenu = gcb.tray.createSubMenu()
gcb.tray.addMenuItemToSubMenu(configMenu, "Disable Desktop Effects (When Ingame)", ID_CONFIG_DISABLE_DESKTOP_EFFECTS)
gcb.tray.addMenuItemToSubMenu(configMenu, "Enable Per-Game Core Binding", ID_CONFIG_SET_CPU_AFFINITY)
gcb.tray.addMenuItemToSubMenu(configMenu, "Disable Non-Primary Displays (When Ingame)", ID_CONFIG_DISABLE_NON_PRIMARY_DISPLAYS)
gcb.tray.addMenuItemToSubMenu(configMenu, "Run as admin", ID_CONFIG_ENSURE_RUNNING_AS_ADMIN)
-- Attach submenu
gcb.tray.addSubMenu("Config", configMenu)
-- Exit menu item
gcb.tray.addMenuItem("Exit", ID_EXIT)
-- Set initial check states
gcb.tray.setMenuChecked(ID_CONFIG_DISABLE_DESKTOP_EFFECTS, Config.DisableDesktopEffects)
gcb.tray.setMenuChecked(ID_CONFIG_SET_CPU_AFFINITY, Config.SetCpuAffinity)
gcb.tray.setMenuChecked(ID_CONFIG_DISABLE_NON_PRIMARY_DISPLAYS, Config.DisableNonPrimaryDisplays)
gcb.tray.setMenuChecked(ID_CONFIG_ENSURE_RUNNING_AS_ADMIN, Config.EnsureRunningAsAdmin)
-- Event callback for menu clicks
function gcb.onTrayEvent(id)
if id == ID_EXIT then
gcb.shutdown()
elseif id == ID_CONFIG_DISABLE_DESKTOP_EFFECTS then
local state = not gcb.tray.isMenuChecked(id)
gcb.tray.setMenuChecked(id, state)
Config.DisableDesktopEffects = state
gcb.saveConfig()
elseif id == ID_CONFIG_SET_CPU_AFFINITY then
local state = not gcb.tray.isMenuChecked(id)
gcb.tray.setMenuChecked(id, state)
Config.SetCpuAffinity = state
gcb.saveConfig()
elseif id == ID_CONFIG_DISABLE_NON_PRIMARY_DISPLAYS then
local state = not gcb.tray.isMenuChecked(id)
gcb.tray.setMenuChecked(id, state)
Config.DisableNonPrimaryDisplays = state
gcb.saveConfig()
elseif id == ID_CONFIG_ENSURE_RUNNING_AS_ADMIN then
local state = not gcb.tray.isMenuChecked(id)
gcb.tray.setMenuChecked(id, state)
Config.EnsureRunningAsAdmin = state
gcb.saveConfig()
if state and not gcb.isRunningAsAdmin() then
gcb.restartAsAdmin()
end
elseif id == ID_OPEN_GAME_GUI then
if type(showGameConfigWindow) == "function" then
showGameConfigWindow()
else
gcb.showMessageBox("Error", "Function 'showGameConfigWindow' is not defined.")
end
elseif id == ID_VERSION_INFO then
gcb.showMessageBox(
"GCB Version",
string.format(
"You are using GCB Version %d (%s).\n\n%s",
gcb.version.Build,
gcb.version.GitRev,
"https://github.com/tpoechtrager/game-core-bind"
)
)
end
end