mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-06 22:46:06 +02:00
add tray menu and remember window state (closes #34)
This commit is contained in:
Generated
+56
-3
@@ -33,21 +33,74 @@ namespace VRCX
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
this.components = new System.ComponentModel.Container();
|
||||||
|
this.TrayMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||||
|
this.TrayMenu_Open = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.TrayMenu_Separator = new System.Windows.Forms.ToolStripSeparator();
|
||||||
|
this.TrayMenu_Quit = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.TrayIcon = new System.Windows.Forms.NotifyIcon(this.components);
|
||||||
|
this.TrayMenu.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
|
// TrayMenu
|
||||||
|
//
|
||||||
|
this.TrayMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.TrayMenu_Open,
|
||||||
|
this.TrayMenu_Separator,
|
||||||
|
this.TrayMenu_Quit});
|
||||||
|
this.TrayMenu.Name = "TrayMenu";
|
||||||
|
this.TrayMenu.Size = new System.Drawing.Size(132, 54);
|
||||||
|
//
|
||||||
|
// TrayMenu_Open
|
||||||
|
//
|
||||||
|
this.TrayMenu_Open.Name = "TrayMenu_Open";
|
||||||
|
this.TrayMenu_Open.Size = new System.Drawing.Size(131, 22);
|
||||||
|
this.TrayMenu_Open.Text = "Open";
|
||||||
|
this.TrayMenu_Open.Click += new System.EventHandler(this.TrayMenu_Open_Click);
|
||||||
|
//
|
||||||
|
// TrayMenu_Separator
|
||||||
|
//
|
||||||
|
this.TrayMenu_Separator.Name = "TrayMenu_Separator";
|
||||||
|
this.TrayMenu_Separator.Size = new System.Drawing.Size(128, 6);
|
||||||
|
//
|
||||||
|
// TrayMenu_Quit
|
||||||
|
//
|
||||||
|
this.TrayMenu_Quit.Name = "TrayMenu_Quit";
|
||||||
|
this.TrayMenu_Quit.Size = new System.Drawing.Size(131, 22);
|
||||||
|
this.TrayMenu_Quit.Text = "Quit VRCX";
|
||||||
|
this.TrayMenu_Quit.Click += new System.EventHandler(this.TrayMenu_Quit_Click);
|
||||||
|
//
|
||||||
|
// TrayIcon
|
||||||
|
//
|
||||||
|
this.TrayIcon.ContextMenuStrip = this.TrayMenu;
|
||||||
|
this.TrayIcon.Text = "VRCX";
|
||||||
|
this.TrayIcon.Visible = true;
|
||||||
|
this.TrayIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.TrayIcon_MouseDoubleClick);
|
||||||
|
//
|
||||||
// MainForm
|
// MainForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||||
this.ClientSize = new System.Drawing.Size(1263, 842);
|
this.ClientSize = new System.Drawing.Size(842, 561);
|
||||||
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
|
|
||||||
this.Name = "MainForm";
|
this.Name = "MainForm";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "VRCX";
|
this.Text = "VRCX";
|
||||||
|
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
|
||||||
|
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed);
|
||||||
|
this.Load += new System.EventHandler(this.MainForm_Load);
|
||||||
|
this.Move += new System.EventHandler(this.MainForm_Move);
|
||||||
|
this.Resize += new System.EventHandler(this.MainForm_Resize);
|
||||||
|
this.TrayMenu.ResumeLayout(false);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.ContextMenuStrip TrayMenu;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem TrayMenu_Open;
|
||||||
|
private System.Windows.Forms.ToolStripSeparator TrayMenu_Separator;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem TrayMenu_Quit;
|
||||||
|
private System.Windows.Forms.NotifyIcon TrayIcon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+113
-1
@@ -15,6 +15,10 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
public static MainForm Instance { get; private set; }
|
public static MainForm Instance { get; private set; }
|
||||||
public static ChromiumWebBrowser Browser { get; private set; }
|
public static ChromiumWebBrowser Browser { get; private set; }
|
||||||
|
private int LastLocationX;
|
||||||
|
private int LastLocationY;
|
||||||
|
private int LastSizeWidth;
|
||||||
|
private int LastSizeHeight;
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
@@ -22,7 +26,10 @@ namespace VRCX
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
|
var location = Assembly.GetExecutingAssembly().Location;
|
||||||
|
var icon = Icon.ExtractAssociatedIcon(location);
|
||||||
|
Icon = icon;
|
||||||
|
TrayIcon.Icon = icon;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -52,5 +59,110 @@ namespace VRCX
|
|||||||
};
|
};
|
||||||
Controls.Add(Browser);
|
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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(VRCXStorage.Instance.Get("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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,4 +117,10 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<metadata name="TrayMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="TrayIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>124, 17</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
||||||
@@ -5304,6 +5304,14 @@ CefSharp.BindObjectAsync(
|
|||||||
VRCXStorage.SetBool('isDarkMode', this.isDarkMode);
|
VRCXStorage.SetBool('isDarkMode', this.isDarkMode);
|
||||||
$appDarkStyle.disabled = this.isDarkMode === false;
|
$appDarkStyle.disabled = this.isDarkMode === false;
|
||||||
};
|
};
|
||||||
|
$app.data.isStartAsMinimizedState = VRCXStorage.GetBool('VRCX_StartAsMinimizedState');
|
||||||
|
$app.data.isCloseToTray = VRCXStorage.GetBool('VRCX_CloseToTray');
|
||||||
|
var saveVRCXWindowOption = function () {
|
||||||
|
VRCXStorage.SetBool('VRCX_StartAsMinimizedState', this.isStartAsMinimizedState);
|
||||||
|
VRCXStorage.SetBool('VRCX_CloseToTray', this.isCloseToTray);
|
||||||
|
};
|
||||||
|
$app.watch.isStartAsMinimizedState = saveVRCXWindowOption;
|
||||||
|
$app.watch.isCloseToTray = saveVRCXWindowOption;
|
||||||
|
|
||||||
API.$on('LOGIN', function () {
|
API.$on('LOGIN', function () {
|
||||||
$app.currentUserTreeData = [];
|
$app.currentUserTreeData = [];
|
||||||
|
|||||||
@@ -791,6 +791,17 @@
|
|||||||
<el-switch v-model="openVRAlways"></el-switch>
|
<el-switch v-model="openVRAlways"></el-switch>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div style="margin-top:30px">
|
||||||
|
<span style="font-weight:bold">Window</span>
|
||||||
|
<div style="font-size:12px;margin-top:5px">
|
||||||
|
<span style="display:inline-block;min-width:150px">Start as Minimized State</span>
|
||||||
|
<el-switch v-model="isStartAsMinimizedState"></el-switch>
|
||||||
|
</div>
|
||||||
|
<div style="font-size:12px;margin-top:5px">
|
||||||
|
<span style="display:inline-block;min-width:150px">Close to Tray</span>
|
||||||
|
<el-switch v-model="isCloseToTray"></el-switch>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div style="margin-top:45px;border-top:1px solid #eee;padding-top:30px">
|
<div style="margin-top:45px;border-top:1px solid #eee;padding-top:30px">
|
||||||
<span style="font-weight:bold">Legal Notice</span>
|
<span style="font-weight:bold">Legal Notice</span>
|
||||||
<div style="margin-top:5px;font-size:12px">
|
<div style="margin-top:5px;font-size:12px">
|
||||||
|
|||||||
Reference in New Issue
Block a user