This repository was 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 pathNativeServices.cs
88 lines (75 loc) · 2.03 KB
/
NativeServices.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
using System;
using System.IO;
using AppKit;
using Xamarin.Forms;
using Xamarin.Forms.ControlGallery.MacOS;
using Xamarin.Forms.Controls;
using Xamarin.Forms.Platform.MacOS;
using IOPath = System.IO.Path;
[assembly: Dependency(typeof(TestCloudService))]
[assembly: Dependency(typeof(CacheService))]
[assembly: Dependency(typeof(NativeColorService))]
[assembly: ExportRenderer(typeof(DisposePage), typeof(DisposePageRenderer))]
[assembly: ExportRenderer(typeof(DisposeLabel), typeof(DisposeLabelRenderer))]
namespace Xamarin.Forms.ControlGallery.MacOS
{
public class CacheService : ICacheService
{
public void ClearImageCache()
{
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var cache = IOPath.Combine(documents, ".config", ".isolated-storage", "ImageLoaderCache");
foreach (var file in Directory.GetFiles(cache))
{
File.Delete(file);
}
}
}
public class NativeColorService : INativeColorService
{
public Color GetConvertedColor(bool shouldCrash)
{
if (shouldCrash)
return NSColor.ControlText.ToColor();
return NSColor.ControlText.ToColor(NSColorSpace.DeviceRGBColorSpace);
}
}
public class DisposePageRenderer : PageRenderer
{
protected override void Dispose(bool disposing)
{
if (disposing)
{
((DisposePage)Element).SendRendererDisposed();
}
base.Dispose(disposing);
}
}
public class DisposeLabelRenderer : LabelRenderer
{
protected override void Dispose(bool disposing)
{
if (disposing)
{
((DisposeLabel)Element).SendRendererDisposed();
}
base.Dispose(disposing);
}
}
public class TestCloudService : ITestCloudService
{
public bool IsOnTestCloud()
{
var isInTestCloud = Environment.GetEnvironmentVariable("XAMARIN_TEST_CLOUD");
return isInTestCloud != null && isInTestCloud.Equals("1");
}
public string GetTestCloudDeviceName()
{
return Environment.GetEnvironmentVariable("XTC_DEVICE_NAME");
}
public string GetTestCloudDevice()
{
return Environment.GetEnvironmentVariable("XTC_DEVICE");
}
}
}