-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathSystemTrayManager.json
More file actions
231 lines (231 loc) · 9.96 KB
/
SystemTrayManager.json
File metadata and controls
231 lines (231 loc) · 9.96 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
{
"author": "",
"category": "General",
"extensionNamespace": "",
"fullName": "System tray manager",
"gdevelopVersion": "",
"helpPath": "",
"iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0ibWRpLXRyYXktcGx1cyIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGQ9Ik0yIDEySDRWMTdIMjBWMTJIMjJWMTdBMiAyIDAgMCAxIDIwIDE5SDRBMiAyIDAgMCAxIDIgMTdNMTEgNUgxM1Y4SDE2VjEwSDEzVjEzSDExVjEwSDhWOEgxMVoiIC8+PC9zdmc+",
"name": "SystemTrayManager",
"previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/a2f86a77b5aa948a7d2b990e87f635cb29c56144c48942c2ea4f17483d61effc_tray-plus.svg",
"shortDescription": "Minimize your app to the Windows system tray, automatically giving it the app icon, and with the ablility to customize the cursor-hovering text and right-click options.",
"version": "1.0.0",
"description": [
"Send your app to the system tray when initializing the icon inside your project. This can be useful for things like:",
"- Creating a launcher that has to do processes in the background.",
"- Creating a tray icon for your app to replace the big icon on the taskbar when minimized, to simulate experiences like \"desktop pets\".",
"- Literally anything you ever dreamed of creating a tray icon for.",
"",
"It currently supports a \"Show label\" with customizable text, and \"Quit\" label with customizable text, and a fully custom third label, used for passing your own string into a scene variable called \"TrayAction\". Then, use that variable to trigger any events in your project."
],
"tags": [],
"authorIds": [],
"dependencies": [],
"globalVariables": [],
"sceneVariables": [],
"eventsFunctions": [
{
"description": "Initializes the system tray icon for the application. Use this event one time, from the moment you want the ability for your app to be minimized to the small system tray icon. For example, as the very first event of the very first scene.",
"fullName": "Initialize system tray",
"functionType": "Action",
"name": "InitializeSystemTray",
"sentence": "Initialize system tray, with the Tooltip Text _PARAM1_, Show Label _PARAM2_, Quit Label _PARAM3_, and if filled, Custom Label _PARAM4_ and Custom Value _PARAM5_",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"if (typeof require === 'undefined') return;",
"",
"if (gdjs._systemTrayInitialized) return;",
"",
"const runtimeGame = runtimeScene.getGame();",
"",
"const renderer = runtimeGame.getRenderer();",
"",
"let electron = null;",
"",
"let remote = null;",
"",
"try {",
"",
" electron = renderer.getElectron ? renderer.getElectron() : null;",
"",
" remote = renderer.getElectronRemote ? renderer.getElectronRemote() : null;",
"",
" if (!electron || !remote) {",
"",
" const e = require('electron');",
"",
" electron = e;",
"",
" remote = e.remote || (e.require ? e.require('@electron/remote') : null);",
"",
" }",
"",
"} catch (e) { return; }",
"",
"if (!electron || !remote) return;",
"",
"const { Tray, Menu, app, nativeImage } = remote;",
"",
"const currentWindow = remote.getCurrentWindow();",
"",
"const tooltipText = eventsFunctionContext.getArgument(\"TooltipText\") || \"App is running\";",
"",
"const showLabel = eventsFunctionContext.getArgument(\"ShowLabel\") || \"Show\";",
"",
"const quitLabel = eventsFunctionContext.getArgument(\"QuitLabel\") || \"Quit\";",
"",
"const customLabel = eventsFunctionContext.getArgument(\"CustomLabel\") || \"\";",
"",
"const customValue = eventsFunctionContext.getArgument(\"CustomValue\") || \"\";",
"",
"const initializeTray = async () => {",
"",
" try {",
"",
" const exePath = app.getPath('exe');",
"",
" const icon = await app.getFileIcon(exePath, { size: 'small' });",
"",
" gdjs._systemTrayIcon = new Tray(icon);",
"",
" gdjs._systemTrayIcon.setToolTip(tooltipText);",
"",
" const menuTemplate = [",
"",
" { label: showLabel, click: () => { currentWindow.show(); currentWindow.focus(); } }",
"",
" ];",
"",
" if (customLabel && customLabel.trim() !== \"\") {",
"",
" menuTemplate.push({",
"",
" label: customLabel,",
"",
" click: () => {",
"",
" // Get the CURRENT active scene to ensure the variable is set where the logic is running",
"",
" const activeScene = runtimeGame.getSceneStack().getCurrentScene();",
"",
" if (activeScene) {",
"",
" const sceneVars = activeScene.getVariables();",
"",
" // Create the variable if it doesn't exist, then set the value",
"",
" sceneVars.get(\"TrayAction\").setString(customValue);",
"",
" }",
"",
" }",
"",
" });",
"",
" }",
"",
" menuTemplate.push({ type: 'separator' });",
"",
" menuTemplate.push({ ",
"",
" label: quitLabel, ",
"",
" click: () => {",
"",
" gdjs._systemTrayQuitting = true;",
"",
" gdjs._systemTrayIcon.destroy();",
"",
" app.quit(); ",
"",
" } ",
"",
" });",
"",
" gdjs._systemTrayIcon.setContextMenu(Menu.buildFromTemplate(menuTemplate));",
"",
" gdjs._systemTrayIcon.on('click', () => {",
"",
" currentWindow.isVisible() ? currentWindow.hide() : currentWindow.show();",
"",
" });",
"",
" currentWindow.on('minimize', (event) => {",
"",
" event.preventDefault();",
"",
" currentWindow.hide();",
"",
" });",
"",
" currentWindow.on('close', (event) => {",
"",
" if (!gdjs._systemTrayQuitting) {",
"",
" event.preventDefault();",
"",
" currentWindow.hide();",
"",
" }",
"",
" });",
"",
" gdjs._systemTrayInitialized = true;",
"",
" gdjs._systemTrayQuitting = false;",
"",
" } catch (err) { console.error(\"System Tray Error:\", err); }",
"",
"};",
"",
"initializeTray();"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": false
}
],
"parameters": [
{
"description": "Tooltip Text",
"longDescription": "The text that shows upon hovering over the app's tray icon. By default, it's called \"My Game Name\", and you can change it however you want.",
"name": "TooltipText",
"supplementaryInformation": "[\"My Game Name\"]",
"type": "stringWithSelector"
},
{
"description": "Show Label",
"longDescription": "The label that restores the app window when clicked. By default, it's logically called \"Show\", but here's an option for you to change it however you want.",
"name": "ShowLabel",
"supplementaryInformation": "[\"Show\"]",
"type": "stringWithSelector"
},
{
"description": "Quit Label",
"longDescription": "The label that closes the app when clicked. By default, it's logically called \"Quit\", but here's an option for you to change it however you want.",
"name": "QuitLabel",
"supplementaryInformation": "[\"Quit\"]",
"type": "stringWithSelector"
},
{
"description": "Custom Label",
"longDescription": "A label that sends a string into a scene variable named \"TrayAction\" when clicked. By default, it's empty, and you don't have to use it if you don't want; in that case, just leave it like this.",
"name": "CustomLabel",
"supplementaryInformation": "[\"\"]",
"type": "string"
},
{
"description": "Custom Value",
"longDescription": "A custom string that gets sent into the \"TrayAction\" scene variable. Use it with the \"Custom Label\".",
"name": "CustomValue",
"type": "string"
}
],
"objectGroups": []
}
],
"eventsBasedBehaviors": [],
"eventsBasedObjects": []
}