-
Notifications
You must be signed in to change notification settings - Fork 28
/
StartupCheck.vala
455 lines (428 loc) · 15.6 KB
/
StartupCheck.vala
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/*
* Copyright 2014-2017 Jiří Janoušek <janousek.jiri@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Nuvola
{
private const string XDG_DESKTOP_PORTAL_SIGSEGV = "GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildSignaled: " +
"Process org.freedesktop.portal.Desktop received signal 11";
/**
* Class performing a system check on start-up of Nuvola
*/
public class StartupCheck : GLib.Object
{
[Description (nick="XDG Desktop Portal status", blurb="XDG Desktop Portal is required for proxy settings and opening URIs.")]
public Status xdg_desktop_portal_status {get; set; default = Status.UNKNOWN;}
[Description (nick="XDG Desktop Portal message", blurb="Null unless the check went wrong.")]
public string? xdg_desktop_portal_message {get; set; default = null;}
[Description (nick="Nuvola Service status", blurb="Status of the connection to Nuvola Service (master process).")]
public Status nuvola_service_status {get; set; default = Status.UNKNOWN;}
[Description (nick="Nuvola Service message", blurb="Null unless the check went wrong.")]
public string? nuvola_service_message {get; set; default = null;}
[Description (nick="OpenGL driver status", blurb="If OpenGL driver is misconfigured, WebKitGTK may crash.")]
public Status opengl_driver_status {get; set; default = Status.UNKNOWN;}
[Description (nick="OpenGL driver message", blurb="Null unless the check went wrong.")]
public string? opengl_driver_message {get; set; default = null;}
[Description (nick="VA-API driver status", blurb="One of the two APIs for video acceleration.")]
public Status vaapi_driver_status {get; set; default = Status.UNKNOWN;}
[Description (nick="VA-API driver message", blurb="Null unless the check went wrong.")]
public string? vaapi_driver_message {get; set; default = null;}
[Description (nick="VDPAU driver status", blurb="One of the two APIs for video acceleration.")]
public Status vdpau_driver_status {get; set; default = Status.UNKNOWN;}
[Description (nick="VDPAU driver message", blurb="Null unless the check went wrong.")]
public string? vdpau_driver_message {get; set; default = null;}
[Description (nick="Web App Requirements status", blurb="A web app may have certain requirements, e.g. Flash plugin, MP3 codec, etc.")]
public Status app_requirements_status {get; set; default = Status.UNKNOWN;}
[Description (nick="Web App Requirements message", blurb="Null unless the check went wrong.")]
public string? app_requirements_message {get; set; default = null;}
[Description (nick="Number of running tasks", blurb="The current number of running checks.")]
public int running_tasks {get; private set; default = 0;}
[Description (nick="Number of finished tasks", blurb="The current number of finished checks.")]
public int finished_tasks {get; private set; default = 0;}
[Description (nick="Final status of all checks.", blurb="Set after mark_finished is called.")]
public StartupCheck.Status final_status {get; private set; default = StartupCheck.Status.UNKNOWN;}
[Description (nick="Format support info", blurb="Associated format support information to check web app requirements.")]
public FormatSupport format_support {get; construct;}
#if TILIADO_API
[Description (nick="Tiliado Account status", blurb="Tiliado account is required for premium features.")]
public Status tiliado_account_status {get; set; default = Status.UNKNOWN;}
[Description (nick="Tiliado Account message", blurb="Null unless the check went wrong.")]
public string? tiliado_account_message {get; set; default = null;}
[Description (nick="Tiliado activation", blurb="Tiliado account activation.")]
public TiliadoActivation activation {get; private set;}
#endif
[Description (nick="Web App object", blurb="Currently loaded web application")]
public WebApp web_app {get; construct;}
public WebOptions web_options {get; construct;}
/**
* Create new StartupCheck object.
*
* @param web_app Web application to check its requirements.
* @param format_support Information about supported formats and technologies.
*/
public StartupCheck(WebApp web_app, WebOptions web_options, FormatSupport format_support) {
GLib.Object(format_support: format_support, web_app: web_app, web_options: web_options);
}
~StartupCheck() {
}
/**
* Emitted when a check is started.
*
* @param name The name of the check.
*/
public virtual signal void task_started(string name) {
running_tasks++;
}
/**
* Emitted when a check is finished.
*
* @param name The name of the check.
*/
public virtual signal void task_finished(string name) {
running_tasks--;
finished_tasks++;
}
/**
* Emitted when all checks are considered finished.
*/
public signal void finished(Status final_status);
/**
* Mark all checks as finished.
*
* Emits {@link finished} signal.
*
* @return {@link Status.ERROR} if any of checks ended up with {@link Status.ERROR},
* {@link Status.WARNING} if there was any warning, finally {@link Status.OK} otherwise.
*/
public Status mark_as_finished() {
var status = get_overall_status();
final_status = status;
finished(status);
return status;
}
/**
* Get overall status based on statuses of all checks.
*
* @return {@link Status.ERROR} if any of checks ended up with {@link Status.ERROR},
* {@link Status.WARNING} if there was any warning, finally {@link Status.OK} otherwise.
*/
public Status get_overall_status() {
Status result = Status.OK;
(unowned ParamSpec)[] properties = get_class().list_properties();
foreach (weak ParamSpec property in properties) {
if (property.name != "final-status" && property.name.has_suffix("-status")) {
Status status = Status.UNKNOWN;
this.get(property.name, out status);
if (status == Status.ERROR) {
return status;
}
if (status == Status.WARNING) {
result = status;
}
}
}
return result;
}
/**
* Check whether XDG desktop portal is available.
*
* The {@link xdg_desktop_portal_status} property is populated with the result of this check.
*/
public async void check_desktop_portal_available() {
const string NAME = "XDG Desktop Portal";
task_started(NAME);
#if FLATPAK
xdg_desktop_portal_status = Status.IN_PROGRESS;
try {
yield Drt.Flatpak.check_desktop_portal_available(null);
xdg_desktop_portal_status = Status.OK;
} catch (GLib.Error e) {
if (XDG_DESKTOP_PORTAL_SIGSEGV in e.message) {
xdg_desktop_portal_message = ("In case you have the 'xdg-desktop-portal-kde' package installed, "
+ "uninstall it and install the 'xdg-desktop-portal-gtk' package instead. Error message: "
+ e.message);
} else {
xdg_desktop_portal_message = e.message;
}
xdg_desktop_portal_status = Status.ERROR;
}
#else
xdg_desktop_portal_status = Status.NOT_APPLICABLE;
#endif
yield Drt.EventLoop.resume_later();
task_finished(NAME);
}
/**
* Check requirements of the associated web app {@link web_app}.
*
* The {@link app_requirements_status} property is populated with the result of this check.
*/
public async void check_app_requirements() {
const string NAME = "Web App Requirements";
task_started(NAME);
app_requirements_status = Status.IN_PROGRESS;
var result_status = Status.OK;
string? result_message = null;
try {
yield format_support.check();
} catch (GLib.Error e) {
result_message = e.message;
}
var webkit_options = web_options as WebkitOptions;
if (webkit_options != null) {
webkit_options.format_support = format_support;
}
var parser = new RequirementParser(web_options);
try {
parser.eval(web_app.requirements);
if (parser.n_unsupported > 0) {
result_status = Status.ERROR;
Drt.String.append(ref result_message, "\n", Markup.printf_escaped(
"This web app requires certain technologies to function properly but these requirements "
+ "have not been satisfied.\n\nFailed requirements: <i>%s</i>\n\n"
+ "<a href=\"%s\">Get help with installation</a>",
parser.failed_requirements ?? "", WEB_APP_REQUIREMENTS_HELP_URL));
} else if (parser.n_unknown > 0) {
yield web_options.gather_format_support_info(web_app);
parser.eval(web_app.requirements);
if (parser.n_unsupported + parser.n_unknown > 0) {
result_status = Status.ERROR;
Drt.String.append(ref result_message, "\n", Markup.printf_escaped(
"This web app requires certain technologies to function properly but these requirements "
+ "have not been satisfied.\n\nFailed requirements: <i>%s %s</i>\n\n"
+ "<a href=\"%s\">Get help with installation</a>",
parser.failed_requirements ?? "", parser.unknown_requirements ?? "", WEB_APP_REQUIREMENTS_HELP_URL));
}
}
} catch (Drt.RequirementError e) {
Drt.String.append(ref result_message, "\n", Markup.printf_escaped(
"This web app provides invalid metadata about its requirements."
+ " Please create a bug report. The error message is: %s\n\n%s",
e.message, web_app.requirements));
result_status = Status.ERROR;
}
var warnings = web_options.get_format_support_warnings();
if (warnings.length > 0) {
if (result_status < Status.WARNING) {
result_status = Status.WARNING;
}
foreach (unowned string entry in warnings) {
Drt.String.append(ref result_message, "\n\n", entry);
}
}
yield Drt.EventLoop.resume_later();
app_requirements_message = (owned) result_message;
app_requirements_status = result_status;
task_finished(NAME);
}
/**
* Check the status of graphics drivers.
*
* The {@link opengl_driver_status}, {@link vaapi_driver_status} and {@link vdpau_driver_status}
* properties are populated with the result of this check.
*/
public async void check_graphics_drivers()
{
const string NAME = "Graphics drivers";
task_started(NAME);
opengl_driver_status = Status.IN_PROGRESS;
vaapi_driver_status = Status.IN_PROGRESS;
vdpau_driver_status = Status.IN_PROGRESS;
yield Drt.EventLoop.resume_later();
#if FLATPAK
string? gl_extension = null;
if (!Graphics.is_required_gl_extension_mounted(out gl_extension))
{
opengl_driver_message = Markup.printf_escaped(
"Graphics driver '%s' for Flatpak has not been found on your system. Please consult "
+ "<a href=\"https://github.com/tiliado/nuvolaruntime/wiki/Graphics-Drivers\">documentation"
+ " on graphics drivers</a> to get help with installation.", gl_extension);
opengl_driver_status = Status.ERROR;
}
else
{
opengl_driver_status = Status.OK;
}
#else
opengl_driver_status = Status.NOT_APPLICABLE;
#endif
try
{
const string DRIVER_NOT_FOUND_TEMPLATE = (
"%s Driver for '%s' not found. Rendering performance of some web apps may suffer. "
#if !FLATPAK
+ "Contact your distributor to get help with installation."
#else
+ "Please <a href=\"https://github.com/tiliado/nuvolaruntime/issues/280\">report your issue</a>"
+" so that the driver can be added to Nuvola Runtime flatpak."
#endif
);
var dri2_driver = Graphics.dri2_get_driver_name();
if (!Graphics.have_vdpau_driver(dri2_driver))
{
vdpau_driver_message = Markup.printf_escaped(DRIVER_NOT_FOUND_TEMPLATE, "VDPAU", dri2_driver);
vdpau_driver_status = Status.WARNING;
}
else
{
vdpau_driver_status = Status.OK;
}
if (!Graphics.have_vaapi_driver(dri2_driver))
{
vaapi_driver_message = Markup.printf_escaped(DRIVER_NOT_FOUND_TEMPLATE, "VA-API", dri2_driver);
vaapi_driver_status = Status.WARNING;
}
else
{
vaapi_driver_status = Status.OK;
}
}
catch (Graphics.DriError e)
{
if (e is Graphics.DriError.NO_X_DISPLAY || e is Graphics.DriError.EXTENSION_QUERY
|| e is Graphics.DriError.CONNECT)
{
vdpau_driver_status = Status.NOT_APPLICABLE;
vaapi_driver_status = Status.NOT_APPLICABLE;
}
else
{
var msg = Markup.printf_escaped("Failed to get DRI2 driver name. %s", e.message);
vdpau_driver_message = msg;
vdpau_driver_status = Status.WARNING;
vaapi_driver_message = (owned) msg;
vaapi_driver_status = Status.WARNING;
}
}
yield Drt.EventLoop.resume_later();
task_finished(NAME);
}
#if TILIADO_API
/**
* Check whether sufficient Tiliado account is available.
*
* The {@link tiliado_account_status} property is populated with the result of this check.
*/
public async void check_tiliado_account(TiliadoActivation activation)
{
const string NAME = "Tiliado account";
task_started(NAME);
tiliado_account_status = Status.IN_PROGRESS;
yield Drt.EventLoop.resume_later();
this.activation = activation;
var user = activation.get_user_info();
if (user != null) {
tiliado_account_message = Markup.printf_escaped("Tiliado account: %s", user.name);
tiliado_account_status = Status.OK;
} else {
tiliado_account_message ="No Tiliado account.";
tiliado_account_status = Status.OK;
}
yield Drt.EventLoop.resume_later();
task_finished(NAME);
}
#endif
/**
* Statuses of {@link StartupCheck}s.
*/
public enum Status
{
/**
* The corresponding check hasn't run yet.
*/
UNKNOWN,
/**
* The check is irrelevant in current environment.
*/
NOT_APPLICABLE,
/**
* The corresponding check has stared but not finished yet.
*/
IN_PROGRESS,
/**
* Everything is OK.
*/
OK,
/**
* There is an issue but it is not so severe. See the corresponding message property for more info.
*/
WARNING,
/**
* The corresponding check failed. See the corresponding message property for more info.
*/
ERROR;
/**
* Get short string representing the status.
*
* @return A short status string.
*/
public string get_blurb()
{
switch (this)
{
case UNKNOWN:
return "Unknown";
case IN_PROGRESS:
return "In Progress";
case OK:
return "OK";
case WARNING:
return "Warning";
case ERROR:
return "Error";
case NOT_APPLICABLE:
return "Not Applicable";
default:
return "";
}
}
/**
* Return suitable CSS class for a badge.
*
* @return A suitable CSS class.
*/
public string get_badge_class()
{
switch (this)
{
case IN_PROGRESS:
return Drtgtk.Css.BADGE_INFO;
case OK:
return Drtgtk.Css.BADGE_OK;
case WARNING:
return Drtgtk.Css.BADGE_WARNING;
case ERROR:
return Drtgtk.Css.BADGE_ERROR;
case NOT_APPLICABLE:
case UNKNOWN:
return Drtgtk.Css.BADGE_DEFAULT;
default:
return Drtgtk.Css.BADGE_DEFAULT;
}
}
public static Status[] all()
{
return {UNKNOWN, NOT_APPLICABLE, IN_PROGRESS, OK, WARNING, ERROR};
}
}
}
} // namespace Nuvola