This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathGtkPlatformServices.cs
121 lines (103 loc) · 2.85 KB
/
GtkPlatformServices.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
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
using System;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Platform.GTK
{
internal class GtkPlatformServices : IPlatformServices
{
public bool IsInvokeRequired => Thread.CurrentThread.IsBackground;
public string RuntimePlatform => Device.GTK;
public void BeginInvokeOnMainThread(Action action)
{
GLib.Idle.Add(delegate { action(); return false; });
}
public Ticker CreateTicker()
{
return new GtkTicker();
}
public Assembly[] GetAssemblies()
{
return AppDomain.CurrentDomain.GetAssemblies();
}
public string GetHash(string input) => Crc64.GetHash(input);
string IPlatformServices.GetMD5Hash(string input) => GetHash(input);
public double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes)
{
switch (size)
{
case NamedSize.Default:
return 11;
case NamedSize.Micro:
case NamedSize.Caption:
return 12;
case NamedSize.Medium:
return 17;
case NamedSize.Large:
return 22;
case NamedSize.Small:
case NamedSize.Body:
return 14;
case NamedSize.Header:
return 46;
case NamedSize.Subtitle:
return 20;
case NamedSize.Title:
return 24;
default:
throw new ArgumentOutOfRangeException(nameof(size));
}
}
public Color GetNamedColor(string name)
{
// Not supported on this platform
return Color.Default;
}
public async Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken)
{
using (var client = new HttpClient())
{
// Do not remove this await otherwise the client will dispose before
// the stream even starts
var result = await StreamWrapper.GetStreamAsync(uri, cancellationToken, client).ConfigureAwait(false);
return result;
}
}
public IIsolatedStorageFile GetUserStoreForApplication()
{
return new GtkIsolatedStorageFile();
}
public void OpenUriAction(Uri uri)
{
System.Diagnostics.Process.Start(uri.AbsoluteUri);
}
public void StartTimer(TimeSpan interval, Func<bool> callback)
{
GLib.Timeout.Add((uint)interval.TotalMilliseconds, () =>
{
var result = callback();
return result;
});
}
private static int Hex(int v)
{
if (v < 10)
return '0' + v;
return 'a' + v - 10;
}
public void QuitApplication()
{
Gtk.Application.Quit();
}
public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint)
{
return Platform.GetNativeSize(view, widthConstraint, heightConstraint);
}
public OSAppTheme RequestedTheme => OSAppTheme.Unspecified;
}
}