forked from NtsFranz/Spark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
86 lines (72 loc) · 2.13 KB
/
App.xaml.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;
using System.Numerics;
using System.Windows;
namespace Spark
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// load settings file
SparkSettings.Load();
if (SparkSettings.instance == null)
{
new MessageBox($"Error accessing settings.\nTry renaming/deleting the file in C:\\Users\\[USERNAME]\\AppData\\Roaming\\IgniteVR\\Spark\\settings.json").Show();
return;
}
System.Threading.Thread.CurrentThread.CurrentUICulture = SparkSettings.instance.languageIndex switch
{
0 => new System.Globalization.CultureInfo("en"),
1 => new System.Globalization.CultureInfo("ja-JP"),
_ => System.Threading.Thread.CurrentThread.CurrentUICulture
};
ThemesController.SetTheme((ThemesController.ThemeTypes)SparkSettings.instance.theme);
CheckWindowPositionsValid();
base.OnStartup(e);
Program.Main(e.Args, this);
}
private static void CheckWindowPositionsValid()
{
if (OffScreen(
new Vector2(
SparkSettings.instance.liveWindowLeft,
SparkSettings.instance.liveWindowTop
),
new Vector2(500, 500)))
{
SparkSettings.instance.liveWindowLeft = 0;
SparkSettings.instance.liveWindowTop = 0;
}
if (OffScreen(
new Vector2(
SparkSettings.instance.settingsWindowLeft,
SparkSettings.instance.settingsWindowTop
),
new Vector2(500, 500)))
{
SparkSettings.instance.settingsWindowLeft = 0;
SparkSettings.instance.settingsWindowTop = 0;
}
}
private static bool OffScreen(Vector2 topLeft, Vector2 size)
{
return
(topLeft.X <= SystemParameters.VirtualScreenLeft - size.X) ||
(topLeft.Y <= SystemParameters.VirtualScreenTop - size.Y) ||
(SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth <= topLeft.X) ||
(SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight <= topLeft.Y);
}
public void ExitApplication()
{
Program.running = false;
Dispatcher.Invoke(() =>
{
Current.Shutdown();
Environment.Exit(Environment.ExitCode);
});
}
}
}