跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

浏览文件

App.xaml.cs

61 行 · 1.5 KB历史下载
1using System;
2using System.Collections.Generic;
3using System.Configuration;
4using System.Data;
5using System.Linq;
6using System.Threading.Tasks;
7using System.Windows;
8
9namespace Updater
10{
11 /// <summary>
12 /// App.xaml 的交互逻辑
13 /// </summary>
14 public partial class App : Application
15 {
16 private System.Threading.Mutex mutex;
17
18 protected override void OnStartup(StartupEventArgs e)
19 {
20 base.OnStartup(e);
21 // 阻止多开和用户主动启动
22 if (e.Args.Length == 0 || IsRuned())
23 {
24 Shutdown();
25 }
26
27 Activated += (s, e2) =>
28 {
29 var mainWindow = App.Current.MainWindow;
30 if (mainWindow.DataContext != null)
31 {
32 var mainModel = mainWindow.DataContext as MainModel;
33 if (string.IsNullOrEmpty(mainModel.Version))
34 {
35 mainModel.Version = e.Args[0];
36 }
37 }
38 };
39 }
40
41
42
43
44
45 #region 获取当前程序是否已运行
46 /// <summary>
47 /// 获取当前程序是否已运行
48 /// </summary>
49 private bool IsRuned()
50 {
51 bool ret;
52 mutex = new System.Threading.Mutex(true, System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name, out ret);
53 if (!ret)
54 {
55 return true;
56 }
57 return false;
58 }
59 #endregion
60 }
61}