mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 14:53:50 +02:00
URI Scheme 2
This commit is contained in:
@@ -344,6 +344,14 @@ namespace VRCX
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void FocusWindow()
|
||||||
|
{
|
||||||
|
if (MainForm.Instance.WindowState == FormWindowState.Minimized)
|
||||||
|
MainForm.Instance.WindowState = FormWindowState.Normal;
|
||||||
|
MainForm.Instance.Show();
|
||||||
|
MainForm.Instance.Activate();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetStartup(bool enabled)
|
public void SetStartup(bool enabled)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -6,67 +6,52 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO.Pipes;
|
using System.IO.Pipes;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace VRCX
|
namespace VRCX
|
||||||
{
|
{
|
||||||
class StartupArgs
|
class StartupArgs
|
||||||
{
|
{
|
||||||
[DllImport("user32.dll")]
|
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
|
||||||
private static extern bool ShowWindow(IntPtr hWnd, int flags);
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
private static extern int SetForegroundWindow(IntPtr hwnd);
|
|
||||||
|
|
||||||
public static string LaunchCommand;
|
public static string LaunchCommand;
|
||||||
|
public static Process[] processList;
|
||||||
|
|
||||||
public static void ArgsCheck()
|
public static void ArgsCheck()
|
||||||
{
|
{
|
||||||
string[] args = Environment.GetCommandLineArgs();
|
string[] args = Environment.GetCommandLineArgs();
|
||||||
if (args.Length == 0)
|
processList = Process.GetProcessesByName("VRCX");
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (string arg in args)
|
foreach (string arg in args)
|
||||||
{
|
{
|
||||||
if (arg.Length > 12 && arg.Substring(0, 12) == "/uri=vrcx://")
|
if (arg.Length > 12 && arg.Substring(0, 12) == "/uri=vrcx://")
|
||||||
{
|
|
||||||
LaunchCommand = arg.Substring(12);
|
LaunchCommand = arg.Substring(12);
|
||||||
ProcessCheck(LaunchCommand);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static void ProcessCheck(string command)
|
if (processList.Length > 1 && String.IsNullOrEmpty(LaunchCommand))
|
||||||
{
|
{
|
||||||
Process currentProcess = Process.GetCurrentProcess();
|
var result = MessageBox.Show("VRCX is already running, start another instance?", "VRCX", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||||
Process[] processList = Process.GetProcessesByName("VRCX");
|
if (result == DialogResult.Yes)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (processList.Length > 1)
|
if (processList.Length > 1)
|
||||||
{
|
{
|
||||||
new IPCServer().CreateIPCServer();
|
IPCToMain();
|
||||||
var ipcClient = new NamedPipeClientStream(".", "vrcx-ipc", PipeDirection.InOut);
|
|
||||||
ipcClient.Connect();
|
|
||||||
|
|
||||||
if (ipcClient.IsConnected)
|
|
||||||
{
|
|
||||||
var buffer = Encoding.UTF8.GetBytes($"{{\"type\":\"LaunchCommand\",\"command\":\"{command}\"}}" + (char)0x00);
|
|
||||||
ipcClient.BeginWrite(buffer, 0, buffer.Length, IPCClient.OnSend, ipcClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Process process in processList)
|
|
||||||
{
|
|
||||||
if (process.Id != currentProcess.Id)
|
|
||||||
{
|
|
||||||
IntPtr handle = process.MainWindowHandle;
|
|
||||||
ShowWindow(handle, 9);
|
|
||||||
SetForegroundWindow(handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void IPCToMain()
|
||||||
|
{
|
||||||
|
new IPCServer().CreateIPCServer();
|
||||||
|
var ipcClient = new NamedPipeClientStream(".", "vrcx-ipc", PipeDirection.InOut);
|
||||||
|
ipcClient.Connect();
|
||||||
|
|
||||||
|
if (ipcClient.IsConnected)
|
||||||
|
{
|
||||||
|
var buffer = Encoding.UTF8.GetBytes($"{{\"type\":\"LaunchCommand\",\"command\":\"{LaunchCommand}\"}}" + (char)0x00);
|
||||||
|
ipcClient.BeginWrite(buffer, 0, buffer.Length, IPCClient.OnSend, ipcClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15593,6 +15593,7 @@ speechSynthesis.getVoices();
|
|||||||
this.eventPing(data);
|
this.eventPing(data);
|
||||||
break;
|
break;
|
||||||
case 'LaunchCommand':
|
case 'LaunchCommand':
|
||||||
|
AppApi.FocusWindow();
|
||||||
this.eventLaunchCommand(data.command);
|
this.eventLaunchCommand(data.command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user