-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (65 loc) · 1.69 KB
/
index.js
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
let controller;
let preferenceMessagePort = undefined;
let myFirstVariable = false;
exports.loadPackage = async function (gridController, persistedData) {
controller = gridController;
gridController.sendMessageToEditor({
type: "add-action",
info: {
actionId: 0,
rendering: "standard",
category: "template",
color: "#5865F2",
icon: "<div />",
blockIcon: "<div />",
selectable: true,
movable: true,
hideIcon: false,
type: "single",
toggleable: true,
short: "xta",
displayName: "Template Action",
defaultLua: 'gps("package-svelte-template", val)',
actionComponent: "template-action",
},
});
myFirstVariable = persistedData?.myFirstVariable ?? false;
};
exports.unloadPackage = async function () {
controller.sendMessageToEditor({
type: "remove-action",
actionId: 0,
});
};
exports.addMessagePort = async function (port, senderId) {
if (senderId == "preferences") {
preferenceMessagePort?.close();
preferenceMessagePort = port;
port.on("close", () => {
preferenceMessagePort = undefined;
});
port.on("message", (e) => {
console.log({ e });
if (e.data.type === "set-setting") {
myFirstVariable = e.data.myFirstVariable;
controller.sendMessageToEditor({
type: "persist-data",
data: {
myFirstVariable,
},
});
}
});
port.start();
notifyStatusChange();
}
};
exports.sendMessage = async function (args) {
console.log(args); //Can be seen in Editor logs
};
function notifyStatusChange() {
preferenceMessagePort?.postMessage({
type: "client-status",
myFirstVariable,
});
}