Skip to content

Commit

Permalink
给Desktop增加重复启动启动的二次确认;修复VLC播放器音量设置共享的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CHKZL committed Jun 19, 2024
1 parent 336cbed commit f6e5fb1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 35 deletions.
12 changes: 0 additions & 12 deletions Core/Network/WebHook.cs

This file was deleted.

55 changes: 54 additions & 1 deletion Desktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public partial class MainWindow : FluentWindow

public MainWindow()
{
if(Application_Startup())
{
Environment.Exit(-114514);
return;
}
InitializeComponent();

this.DataContext = configViewModel;
Expand All @@ -90,7 +95,7 @@ public void Init()
//设置登录失效事件(失效后弹出扫码框)
DataSource.LoginStatus.LoginFailureEvent += LoginStatus_LoginFailureEvent;
//设置登录态检测定时任务
DataSource.LoginStatus.Timer_LoginStatus = new Timer(DataSource.LoginStatus.RefreshLoginStatus, null, 1000*10, 1000 * 60 * 30);
DataSource.LoginStatus.Timer_LoginStatus = new Timer(DataSource.LoginStatus.RefreshLoginStatus, null, 1000 * 10, 1000 * 60 * 30);
//版本更新检测
Core.Tools.ProgramUpdates.NewVersionAvailableEvent += ProgramUpdates_NewVersionAvailableEvent;
//设置默认显示页
Expand Down Expand Up @@ -162,6 +167,54 @@ private void InitializeTitleMode()
});
}

public bool Application_Startup()
{
Process process = RuningInstance();
if (process != null)
{
System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show(
"已经有DDTV的Desktop实例正在运行中" +
"\r点击‘是’强制启动一个新DDTV" +
"\r点击‘否’阻止打开新窗口和新DDTV" +
$"\r======参考信息======" +
$"\rId:{process.Id}" +
$"\rProcessName:{process.ProcessName}"
, "已有DDTV实例正在运行", System.Windows.MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result != System.Windows.MessageBoxResult.Yes)
{
this.Show(); // 显示窗口
this.WindowState = WindowState.Normal; // 设置窗口状态为正常
System.Threading.Thread.Sleep(500);
return true;

}
}
return false;
}
public static Process RuningInstance(bool IsStart = true)
{
try
{
Process currentProcess = Process.GetCurrentProcess();
Process[] Processes = Process.GetProcessesByName(currentProcess.ProcessName);
foreach (Process process in Processes)
{
if (!IsStart || process.Id != currentProcess.Id)
{
string PA = Assembly.GetExecutingAssembly().Location.Replace("/", "\\");
string PB = currentProcess.MainModule.FileName;
string PAA = PA.Replace(PA.Split('.')[PA.Split('.').Length - 1], "");
string PBA = PB.Replace(PB.Split('.')[PB.Split('.').Length - 1], "");
if (PAA == PBA)
{
return process;
}
}
}
}
catch (Exception) { }
return null;
}
private void notify()
{
notifyIcon = new System.Windows.Forms.NotifyIcon();
Expand Down
28 changes: 11 additions & 17 deletions Desktop/Views/Windows/VlcPlayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,9 @@ public class DanMuOrbitInfo
public VlcPlayWindow(long uid)
{
InitializeComponent();

Task.Run(() => InitVlcPlay(uid));

}
public void InitVlcPlay(long uid)
{
vlcPlayModels = new();
Dispatcher.Invoke(() =>
{
this.DataContext = vlcPlayModels;
});

this.DataContext = vlcPlayModels;
_Room.GetCardForUID(uid, ref roomCard);

vlcPlayModels.VolumeVisibility = Visibility.Collapsed;
Expand All @@ -93,14 +84,17 @@ public void InitVlcPlay(long uid)

_libVLC = new LibVLC([$"--network-caching={new Random().Next(3000, 4000)} --no-cert-verification"]);
_mediaPlayer = new LibVLCSharp.Shared.MediaPlayer(_libVLC);
Dispatcher.Invoke(() =>
{
videoView.MediaPlayer = _mediaPlayer;
videoView.MediaPlayer.Playing += MediaPlayer_Playing;
videoView.MediaPlayer.EndReached += MediaPlayer_EndReached;
videoView.MediaPlayer.Volume = 30;
});

videoView.MediaPlayer = _mediaPlayer;
videoView.MediaPlayer.Playing += MediaPlayer_Playing;
videoView.MediaPlayer.EndReached += MediaPlayer_EndReached;
videoView.MediaPlayer.Volume = 30;

Task.Run(() => InitVlcPlay(uid));

}
public void InitVlcPlay(long uid)
{
PlaySteam();
Dispatcher.Invoke(() =>
{
Expand Down
14 changes: 9 additions & 5 deletions Server/WebAppServices/MessageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public static string MssagePack<T>(string cmd, T data, string message = "", code
{
code = code.LoginInfoFailure;
}
//# if DEBUG
// Log.Debug(nameof(MessageBase), cmd + " " + code, false);
//#endif
OperationQueue.pack<T> pack = new OperationQueue.pack<T>()
{
cmd = cmd,
Expand All @@ -54,8 +51,15 @@ public static void WS_Send(string message)
ArraySegment<byte> buffer = new ArraySegment<byte>(Encoding.UTF8.GetBytes(message));
foreach (WebSocket item in Middleware.WebSocketControl.webSockets)
{
if (item.State == WebSocketState.Open || item.State == WebSocketState.Connecting)
item.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None);
try
{
if (item.State == WebSocketState.Open || item.State == WebSocketState.Connecting)
item.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None);
}
catch (System.Exception ex)
{
Log.Warn(nameof(WS_Send), "WebSocket信息推送失败", ex, false);
}
}
}

Expand Down

0 comments on commit f6e5fb1

Please sign in to comment.