Skip to content

Commit 7f3a8ac

Browse files
authored
Merge pull request #5 from dimojang/tomato
Tomato
2 parents bd605df + 38faf66 commit 7f3a8ac

File tree

13 files changed

+134
-81
lines changed

13 files changed

+134
-81
lines changed

App.xaml.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
using System.Windows;
1414
using System.Windows.Input;
1515
using System.Threading;
16+
using System.Security.Principal;
17+
18+
using Frogy.Methods;
1619

1720
namespace Frogy
1821
{
@@ -27,6 +30,11 @@ public partial class App : Application
2730

2831
protected override void OnStartup(StartupEventArgs e)
2932
{
33+
//Promote permission if not Administrator
34+
var principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
35+
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
36+
MyDeviceHelper.PromotePermission();
37+
3038
//Launage switch
3139
ResourceDictionary dict = new ResourceDictionary();
3240
switch (appData.LanguageSetting)
@@ -41,6 +49,7 @@ protected override void OnStartup(StartupEventArgs e)
4149
break;
4250
default: //english default
4351
dict.Source = new Uri(@"Resources\Language\en-US.xaml", UriKind.Relative);
52+
ConfigHelper.Instance.SetLang("en");
4453
break;
4554
}
4655
Current.Resources.MergedDictionaries.Add(dict);
@@ -68,7 +77,7 @@ protected override void OnStartup(StartupEventArgs e)
6877

6978
//tray icon
7079
mutex = new Mutex(true, "FrogyMainProgram");
71-
if (mutex.WaitOne(0, false))
80+
if (mutex.WaitOne(0, false) || e.Args[0] == "restart")
7281
{
7382
taskbarIcon = (TaskbarIcon)FindResource("icon");
7483

@@ -91,10 +100,11 @@ protected override void OnStartup(StartupEventArgs e)
91100
MessageBoxButton.OK,
92101
MessageBoxImage.Warning);
93102

94-
Current.Shutdown();
103+
Environment.Exit(1);
95104
}
96105
}
97106

107+
98108
private void SystemEvents_SessionEnded(object sender, SessionEndedEventArgs e)
99109
{
100110
appData.Save();

Frogy.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<Prefer32Bit>true</Prefer32Bit>
7575
</PropertyGroup>
7676
<PropertyGroup>
77-
<TargetZone>LocalIntranet</TargetZone>
77+
<TargetZone>Internet</TargetZone>
7878
</PropertyGroup>
7979
<PropertyGroup>
8080
<GenerateManifests>false</GenerateManifests>
@@ -168,7 +168,6 @@
168168
<DependentUpon>Resources.resx</DependentUpon>
169169
</Compile>
170170
<Compile Include="Resources\Language\LanguageHelper.cs" />
171-
<Compile Include="Resources\Theme\ThemeHelper.cs" />
172171
<Compile Include="ViewModels\DashboardViewModel.cs" />
173172
<Compile Include="ViewModels\OptionViewModel.cs" />
174173
<Compile Include="ViewModels\OverViewViewModel.cs" />

Methods/MyDeviceHelper.cs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using Microsoft.Win32;
22
using System;
33
using System.Collections.Generic;
4+
using System.Diagnostics;
45
using System.Linq;
6+
using System.Reflection;
57
using System.Runtime.InteropServices;
68
using System.Text;
79
using System.Threading.Tasks;
10+
using System.Windows;
811

912
namespace Frogy.Methods
1013
{
@@ -110,7 +113,6 @@ private struct LARGE_INTEGER //此结构体在C++中使用的为union结构,
110113
readonly long QuadPart;
111114
}
112115

113-
114116
/// <summary>
115117
/// 读取设备状态
116118
/// 0 代表锁定
@@ -138,5 +140,66 @@ public static int DeviceState
138140
return dwFlags;
139141
}
140142
}
143+
144+
public static void RegisterStartup()
145+
{
146+
try
147+
{
148+
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true) ??
149+
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
150+
151+
Assembly curAssembly = Assembly.GetExecutingAssembly();
152+
key.SetValue(curAssembly.GetName().Name, curAssembly.Location);
153+
}
154+
catch { }
155+
}
156+
157+
public static void DeregisterStartup()
158+
{
159+
try
160+
{
161+
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true) ??
162+
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
163+
164+
Assembly curAssembly = Assembly.GetExecutingAssembly();
165+
key.DeleteValue(curAssembly.GetName().Name);
166+
}
167+
catch { }
168+
}
169+
170+
public static bool GetStartupStatus()
171+
{
172+
bool result = false;
173+
try
174+
{
175+
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true) ??
176+
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
177+
178+
Assembly curAssembly = Assembly.GetExecutingAssembly();
179+
180+
string[] values = key.GetValueNames();
181+
foreach(string s in values) if (s == curAssembly.GetName().Name) result = true;
182+
}
183+
catch { }
184+
185+
return result;
186+
}
187+
188+
public static void PromotePermission()
189+
{
190+
ProcessStartInfo psi = new ProcessStartInfo();
191+
Assembly curAssembly = Assembly.GetExecutingAssembly();
192+
193+
psi.FileName = curAssembly.Location;
194+
psi.Verb = "runas";
195+
psi.Arguments = "restart";
196+
197+
try
198+
{
199+
Process.Start(psi);
200+
Environment.Exit(1);
201+
}
202+
catch { }
203+
}
141204
}
142205
}

Methods/MyProcessHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Runtime.InteropServices;
88
using System.Drawing;
99
using System.Windows.Media.Imaging;
10+
using System.Windows;
1011

1112
namespace Frogy.Methods
1213
{
@@ -150,7 +151,7 @@ public static bool IsProcessUWP(Process process)
150151
}
151152
catch(Exception e)
152153
{
153-
throw e;
154+
throw (e);
154155
}
155156
}
156157
}

Properties/app.manifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
Remove this element if your application requires this virtualization for backwards
1717
compatibility.
1818
-->
19-
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
19+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
2020
</requestedPrivileges>
2121
<applicationRequestMinimum>
2222
<defaultAssemblyRequest permissionSetReference="Custom" />
23-
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" Unrestricted="true" />
23+
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" />
2424
</applicationRequestMinimum>
2525
</security>
2626
</trustInfo>

Resources/Language/en-US.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@
2828
<system:String x:Key="Option_LanguageTitle">Launage</system:String>
2929
<system:String x:Key="Option_Info">*Some of the setting(s) will take effect after restarting Frogy.</system:String>
3030
<system:String x:Key="Option_ThemeTitle">Theme</system:String>
31+
<system:String x:Key="Option_ThemeDefault">Default</system:String>
32+
<system:String x:Key="Option_ThemeNight">Night</system:String>
33+
<system:String x:Key="Option_SystemTitle">System</system:String>
34+
<system:String x:Key="Option_Startup">Start with windows</system:String>
3135

3236
</ResourceDictionary>

Resources/Language/zh-CN.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@
2828
<system:String x:Key="Option_LanguageTitle">语言</system:String>
2929
<system:String x:Key="Option_Info">*部分设置在重启 时常 后生效。</system:String>
3030
<system:String x:Key="Option_ThemeTitle">主题</system:String>
31+
<system:String x:Key="Option_ThemeDefault">默认</system:String>
32+
<system:String x:Key="Option_ThemeNight">夜晚</system:String>
33+
<system:String x:Key="Option_SystemTitle">系统</system:String>
34+
<system:String x:Key="Option_Startup">开机自启</system:String>
3135

3236
</ResourceDictionary>

Resources/Theme/DarkTheme.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf">
4-
3+
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
4+
xmlns:system="clr-namespace:System;assembly=mscorlib">
5+
6+
<system:String x:Key="en-US">Dark</system:String>
7+
<system:String x:Key="zh-CN">夜间模式</system:String>
8+
59
<Style x:Key="DefaultChartStyle" TargetType="lvc:CartesianChart">
610
<Setter Property="Foreground" Value="White"/>
711
</Style>

Resources/Theme/DefaultTheme.xaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:system="clr-namespace:System;assembly=mscorlib"
4-
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf">
3+
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
4+
xmlns:system="clr-namespace:System;assembly=mscorlib">
5+
6+
<system:String x:Key="en-US">Default</system:String>
7+
<system:String x:Key="zh-CN">默认</system:String>
58

69
<Style x:Key="DefaultChartStyle" TargetType="lvc:CartesianChart">
710
<Setter Property="Foreground" Value="Black"/>

Resources/Theme/ThemeHelper.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

ViewModels/OptionViewModel.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using System.Windows.Input;
1313

1414
using Frogy.Resources.Language;
15-
using Frogy.Resources.Theme;
1615
using System.Windows.Controls;
1716

1817
namespace Frogy.ViewModels
@@ -116,20 +115,6 @@ public int LanguageListSelectedIndex
116115
#endregion
117116

118117
#region Theme setting
119-
private List<string> themeList = new List<string>();
120-
public List<string> ThemeList
121-
{
122-
get
123-
{
124-
themeList.Clear();
125-
126-
foreach (KeyValuePair<int, string> pair in ThemeHelper.ThemeSets)
127-
themeList.Add(pair.Value);
128-
129-
return themeList;
130-
}
131-
}
132-
133118
private int themeListSelectedIndex = ((App)Application.Current).appData.ThemeSetting >= 0 && ((App)Application.Current).appData.ThemeSetting <= 1 ?
134119
((App)Application.Current).appData.ThemeSetting : 0;
135120
public int ThemeListSelectedIndex
@@ -147,6 +132,23 @@ public int ThemeListSelectedIndex
147132
}
148133
#endregion
149134

135+
#region
136+
private bool startupStatus = MyDeviceHelper.GetStartupStatus();
137+
public bool StartupStatus
138+
{
139+
get { return startupStatus; }
140+
set
141+
{
142+
if (value)
143+
MyDeviceHelper.RegisterStartup();
144+
else
145+
MyDeviceHelper.DeregisterStartup();
146+
147+
startupStatus = value;
148+
}
149+
}
150+
#endregion
151+
150152
#region INotifyPropertyChanged
151153
public event PropertyChangedEventHandler PropertyChanged = delegate { };
152154
public void OnPropertyChanged([CallerMemberName] string propertyName = null)

ViewModels/OverViewViewModel.cs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,14 @@ private List<DetailViewItem> PrintSummaryView(List<MyTimeDuration> durations)
120120
{
121121
List<DetailViewItem> result = new List<DetailViewItem>();
122122

123-
string systemState;
124-
125123
foreach (MyTimeDuration timeSpan in durations)
126124
{
127-
switch (timeSpan.TimeDurationTask.ComputerStatus)
128-
{
129-
case 1:
130-
systemState = "On active";
131-
break;
132-
133-
case 0:
134-
systemState = "Locked";
135-
break;
136-
137-
case 2:
138-
systemState = "Forgy exited";
139-
break;
140-
}
141-
142125
DetailViewItem tmp = new DetailViewItem()
143126
{
144127
StartTime = timeSpan.StartTime.ToString(),
145128
StopTime = timeSpan.StopTime.ToString(),
146129
AppDuration = timeSpan.Duration.ToString(),
147-
AppIcon = MyDataHelper.BitmapToBitmapImage(
148-
MyDataHelper.Base64StringToImage(timeSpan.TimeDurationTask.ApplicationIcon_Base64)),
130+
AppIcon = MyDataHelper.BitmapToBitmapImage(MyDataHelper.Base64StringToImage(timeSpan.TimeDurationTask.ApplicationIcon_Base64)),
149131
AppName = timeSpan.TimeDurationTask.ApplicationName,
150132
WindowTitle = timeSpan.TimeDurationTask.ApplicationTitle,
151133
SystemState = timeSpan.TimeDurationTask.ComputerStatus.ToString()
@@ -164,18 +146,12 @@ public OverViewViewModel()
164146
"13:00", "14:00", "15:00", "16:00", "17:00", "18:00",
165147
"19:00", "20:00", "21:00", "22:00", "23:00"};
166148

167-
168-
169149
OverviewChartFormatter = value => value + "min";
170150
}
171151

172152
private async void Update()
173153
{
174-
await Task.Run(() =>
175-
{
176-
((App)Application.Current).appData.Load(displayDate);
177-
});
178-
154+
((App)Application.Current).appData.Load(displayDate);
179155
MyDay today = ((App)Application.Current).appData.AllDays[displayDate];
180156

181157
await Task.Run(() =>
@@ -191,7 +167,7 @@ await Task.Run(() =>
191167
foreach (StackedColumnSeries i in OverviewChart_tmp)
192168
{
193169
OverviewChart.Add(i);
194-
Thread.Sleep(220);
170+
Thread.Sleep(20);
195171
}
196172
});
197173
}

0 commit comments

Comments
 (0)