-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
203 lines (184 loc) · 6.38 KB
/
utils.js
File metadata and controls
203 lines (184 loc) · 6.38 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
const Gio = imports.gi.Gio;
var REGISTRAR_BUS_NAME = "com.canonical.AppMenu.Registrar";
var REGISTRAR_OBJECT_PATH = "/com/canonical/AppMenu/Registrar";
var DBUS_BUS_NAME = "org.freedesktop.DBus";
var DBUS_OBJECT_PATH = "/org/freedesktop/DBus";
var REGISTRAR_IFACE = `
<node>
<interface name="com.canonical.AppMenu.Registrar">
<method name="GetMenuForWindow">
<arg type="u" name="windowId" direction="in"/>
<arg type="s" name="service" direction="out"/>
<arg type="o" name="path" direction="out"/>
</method>
<method name="GetMenus">
<arg type="a(uso)" name="menus" direction="out"/>
</method>
<signal name="WindowRegistered">
<arg type="u" name="windowId"/>
<arg type="s" name="service"/>
<arg type="o" name="path"/>
</signal>
<signal name="WindowUnregistered">
<arg type="u" name="windowId"/>
</signal>
</interface>
</node>`;
var REGISTRAR_SERVER_IFACE = `
<node>
<interface name="com.canonical.AppMenu.Registrar">
<method name="RegisterWindow">
<arg type="u" name="windowId" direction="in"/>
<arg type="o" name="menuObjectPath" direction="in"/>
</method>
<method name="UnregisterWindow">
<arg type="u" name="windowId" direction="in"/>
</method>
<method name="GetMenuForWindow">
<arg type="u" name="windowId" direction="in"/>
<arg type="s" name="service" direction="out"/>
<arg type="o" name="menuObjectPath" direction="out"/>
</method>
<method name="GetMenus">
<arg type="a(uso)" name="menus" direction="out"/>
</method>
<signal name="WindowRegistered">
<arg type="u" name="windowId"/>
<arg type="s" name="service"/>
<arg type="o" name="menuObjectPath"/>
</signal>
<signal name="WindowUnregistered">
<arg type="u" name="windowId"/>
</signal>
</interface>
</node>`;
var DBUS_IFACE = `
<node>
<interface name="org.freedesktop.DBus">
<method name="NameHasOwner">
<arg type="s" name="name" direction="in"/>
<arg type="b" name="hasOwner" direction="out"/>
</method>
<signal name="NameOwnerChanged">
<arg type="s" name="name"/>
<arg type="s" name="oldOwner"/>
<arg type="s" name="newOwner"/>
</signal>
</interface>
</node>`;
var GTK_MENUS_IFACE = `
<node>
<interface name="org.gtk.Menus">
<method name="Start">
<arg type="au" name="groups" direction="in"/>
<arg type="a(uuaa{sv})" name="content" direction="out"/>
</method>
<method name="End">
<arg type="au" name="groups" direction="in"/>
</method>
<signal name="Changed"/>
</interface>
</node>`;
var GTK_ACTIONS_IFACE = `
<node>
<interface name="org.gtk.Actions">
<method name="DescribeAll">
<arg type="a{s(bgav)}" name="descriptions" direction="out"/>
</method>
<method name="Activate">
<arg type="s" name="action_name" direction="in"/>
<arg type="av" name="parameter" direction="in"/>
<arg type="a{sv}" name="platform_data" direction="in"/>
</method>
<signal name="Changed">
<arg type="as" name="removals"/>
<arg type="a{sb}" name="enable_changes"/>
<arg type="a{sv}" name="state_changes"/>
<arg type="a{s(bgav)}" name="additions"/>
</signal>
</interface>
</node>`;
var DBUS_MENU_IFACE = `
<node>
<interface name="com.canonical.dbusmenu">
<method name="GetLayout">
<arg type="i" name="parentId" direction="in"/>
<arg type="i" name="recursionDepth" direction="in"/>
<arg type="as" name="propertyNames" direction="in"/>
<arg type="u" name="revision" direction="out"/>
<arg type="(ia{sv}av)" name="layout" direction="out"/>
</method>
<method name="GetGroupProperties">
<arg type="ai" name="ids" direction="in"/>
<arg type="as" name="propertyNames" direction="in"/>
<arg type="a(ia{sv})" name="properties" direction="out"/>
</method>
<method name="Event">
<arg type="i" name="id" direction="in"/>
<arg type="s" name="eventId" direction="in"/>
<arg type="v" name="data" direction="in"/>
<arg type="u" name="timestamp" direction="in"/>
</method>
<method name="AboutToShow">
<arg type="i" name="id" direction="in"/>
<arg type="b" name="needUpdate" direction="out"/>
</method>
<signal name="ItemsPropertiesUpdated">
<arg type="a(ia{sv})" name="updatedProps"/>
<arg type="a(ias)" name="removedProps"/>
</signal>
<signal name="LayoutUpdated">
<arg type="u" name="revision"/>
<arg type="i" name="parent"/>
</signal>
<signal name="ItemActivationRequested">
<arg type="i" name="id"/>
<arg type="u" name="timestamp"/>
</signal>
</interface>
</node>`;
var RegistrarProxy = Gio.DBusProxy.makeProxyWrapper(REGISTRAR_IFACE);
var DBusProxy = Gio.DBusProxy.makeProxyWrapper(DBUS_IFACE);
var GtkMenusProxy = Gio.DBusProxy.makeProxyWrapper(GTK_MENUS_IFACE);
var GtkActionsProxy = Gio.DBusProxy.makeProxyWrapper(GTK_ACTIONS_IFACE);
var DBusMenuProxy = Gio.DBusProxy.makeProxyWrapper(DBUS_MENU_IFACE);
function variantToValue(value) {
if (value === null || value === undefined) {
return null;
}
if (value.deep_unpack) {
return value.deep_unpack();
}
return value;
}
function cleanMnemonic(label) {
if (!label) {
return "";
}
return label
.replace(/__/g, "\u0000")
.replace(/_([^_])/g, "$1")
.replace(/\u0000/g, "_");
}
function actionNameFromDetailed(action) {
if (!action) {
return null;
}
let actionName = action;
let dot = actionName.indexOf(".");
if (dot >= 0) {
actionName = actionName.slice(dot + 1);
}
let targetIndex = actionName.indexOf("::");
if (targetIndex >= 0) {
actionName = actionName.slice(0, targetIndex);
}
return actionName;
}
function actionGroupFromDetailed(action) {
if (!action) {
return null;
}
let dot = action.indexOf(".");
return dot >= 0 ? action.slice(0, dot) : null;
}