-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathProgram.cs
60 lines (53 loc) · 2.1 KB
/
Program.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
using System;
using System.IO;
using Avalonia;
using Xilium.CefGlue.Common;
using Xilium.CefGlue.Common.Shared;
namespace Xilium.CefGlue.Demo.Avalonia
{
class Program
{
static int Main(string[] args)
{
// generate a unique cache path to avoid problems when launching more than one process
// https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=19665
var cachePath = Path.Combine(Path.GetTempPath(), "CefGlue_" + Guid.NewGuid().ToString().Replace("-", null));
AppDomain.CurrentDomain.ProcessExit += delegate { Cleanup(cachePath); };
AppBuilder.Configure<App>()
.UsePlatformDetect()
.With(new Win32PlatformOptions())
.AfterSetup(_ => CefRuntimeLoader.Initialize(new CefSettings() {
RootCachePath = cachePath,
#if WINDOWLESS
// its recommended to leave this off (false), since its less performant and can cause more issues
WindowlessRenderingEnabled = true
#else
WindowlessRenderingEnabled = false
#endif
},
customSchemes: new[] {
new CustomScheme()
{
SchemeName = "test",
SchemeHandlerFactory = new CustomSchemeHandler()
}
}))
.StartWithClassicDesktopLifetime(args);
return 0;
}
private static void Cleanup(string cachePath)
{
CefRuntime.Shutdown(); // must shutdown cef to free cache files (so that cleanup is able to delete files)
try {
var dirInfo = new DirectoryInfo(cachePath);
if (dirInfo.Exists) {
dirInfo.Delete(true);
}
} catch (UnauthorizedAccessException) {
// ignore
} catch (IOException) {
// ignore
}
}
}
}