forked from vrcx-team/VRCX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
171 lines (153 loc) · 5.3 KB
/
MainForm.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright(c) 2019 pypy. All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
namespace VRCX
{
public partial class MainForm : Form
{
public static MainForm Instance;
public ChromiumWebBrowser Browser;
private int LastLocationX;
private int LastLocationY;
private int LastSizeWidth;
private int LastSizeHeight;
public MainForm()
{
Instance = this;
InitializeComponent();
try
{
var location = Assembly.GetExecutingAssembly().Location;
var icon = Icon.ExtractAssociatedIcon(location);
Icon = icon;
TrayIcon.Icon = icon;
}
catch
{
}
Browser = new ChromiumWebBrowser(
Path.Combine(Program.BaseDirectory, "html/index.html")
)
{
DragHandler = new NoopDragHandler(),
BrowserSettings =
{
DefaultEncoding = "UTF-8",
},
Dock = DockStyle.Fill
};
Browser.IsBrowserInitializedChanged += (A, B) =>
{
// Browser.ShowDevTools();
};
Util.ApplyJavascriptBindings(Browser.JavascriptObjectRepository);
Controls.Add(Browser);
}
private void MainForm_Load(object sender, System.EventArgs e)
{
try
{
int.TryParse(VRCXStorage.Instance.Get("VRCX_LocationX"), out LastLocationX);
int.TryParse(VRCXStorage.Instance.Get("VRCX_LocationY"), out LastLocationY);
int.TryParse(VRCXStorage.Instance.Get("VRCX_SizeWidth"), out LastSizeWidth);
int.TryParse(VRCXStorage.Instance.Get("VRCX_SizeHeight"), out LastSizeHeight);
var location = new Point(LastLocationX, LastLocationY);
var size = new Size(LastSizeWidth, LastSizeHeight);
var screen = Screen.FromPoint(location);
if (screen.Bounds.Contains(location.X, location.Y))
{
Location = location;
}
if (size.Width > 0 && size.Height > 0)
{
Size = size;
}
}
catch
{
}
try
{
var state = WindowState;
if (int.TryParse(VRCXStorage.Instance.Get("VRCX_WindowState"), out int v))
{
state = (FormWindowState)v;
}
if (state == FormWindowState.Minimized)
{
state = FormWindowState.Normal;
}
if ("true".Equals(VRCXStorage.Instance.Get("VRCX_StartAsMinimizedState")))
{
state = FormWindowState.Minimized;
}
WindowState = state;
}
catch
{
}
// 가끔 화면 위치가 안맞음.. 이걸로 해결 될지는 모르겠음
Browser.Invalidate();
}
private void MainForm_Resize(object sender, System.EventArgs e)
{
if (WindowState != FormWindowState.Normal)
{
return;
}
LastSizeWidth = Size.Width;
LastSizeHeight = Size.Height;
}
private void MainForm_Move(object sender, System.EventArgs e)
{
if (WindowState != FormWindowState.Normal)
{
return;
}
LastLocationX = Location.X;
LastLocationY = Location.Y;
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing &&
"true".Equals(SharedVariable.Instance.Get("config:vrcx_closetotray")))
{
e.Cancel = true;
Hide();
}
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
VRCXStorage.Instance.Set("VRCX_LocationX", LastLocationX.ToString());
VRCXStorage.Instance.Set("VRCX_LocationY", LastLocationY.ToString());
VRCXStorage.Instance.Set("VRCX_SizeWidth", LastSizeWidth.ToString());
VRCXStorage.Instance.Set("VRCX_SizeHeight", LastSizeHeight.ToString());
VRCXStorage.Instance.Set("VRCX_WindowState", ((int)WindowState).ToString());
}
private void TrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
TrayMenu_Open_Click(sender, e);
}
private void TrayMenu_Open_Click(object sender, System.EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
WindowState = FormWindowState.Normal;
}
Show();
Focus();
}
private void TrayMenu_Quit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}