forked from OpenTabletDriver/OpenTabletDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinuxApp.cs
86 lines (73 loc) · 2.18 KB
/
LinuxApp.cs
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
using System.Diagnostics;
using Eto;
using Eto.Drawing;
using Eto.Forms;
namespace OpenTabletDriver.UX.Gtk
{
public class LinuxApp : App
{
private Process? _daemon;
public LinuxApp(string[] args) : base(Platforms.Gtk, args)
{
}
protected override bool EnableTray { get; } = IsVariableSet("OTD_TRAY_ICON");
protected override void ApplyStyles()
{
Style.Add<GroupBox>(null, c =>
{
c.Padding = 5;
});
Style.Add<GroupBox>("labeled", c =>
{
c.BackgroundColor = SystemColors.WindowBackground;
});
Style.Add<Scrollable>(null, c =>
{
c.Border = BorderType.None;
});
}
protected override void OpenInternal(string uri, bool isDirectory)
{
Process.Start("xdg-open", uri);
}
public override void StartDaemon()
{
if (Instance.Exists("OpenTabletDriver.Daemon") || !IsVariableSet("OTD_UI_HOST"))
return;
var daemonPath = Path.Join(AppContext.BaseDirectory, "OpenTabletDriver.Daemon");
if (File.Exists(daemonPath))
{
_daemon = new Process
{
StartInfo = new ProcessStartInfo(daemonPath),
EnableRaisingEvents = true
};
_daemon.Start();
_daemon.Exited += HandleDaemonExited;
}
}
public override void StopDaemon()
{
if (_daemon != null)
{
_daemon.Exited -= HandleDaemonExited;
_daemon.Close();
}
}
public override void Exit(int code)
{
StopDaemon();
base.Exit(code);
}
private void HandleDaemonExited(object? o, EventArgs eventArgs)
{
_daemon = null;
StartDaemon();
}
private static bool IsVariableSet(string envVar)
{
var str = Environment.GetEnvironmentVariable(envVar);
return str?.ToLower() is "1" or "true";
}
}
}