Skip to content

Tomato #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
using System.Windows;
using System.Windows.Input;
using System.Threading;
using System.Security.Principal;

using Frogy.Methods;

namespace Frogy
{
Expand All @@ -27,6 +30,11 @@ public partial class App : Application

protected override void OnStartup(StartupEventArgs e)
{
//Promote permission if not Administrator
var principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
MyDeviceHelper.PromotePermission();

//Launage switch
ResourceDictionary dict = new ResourceDictionary();
switch (appData.LanguageSetting)
Expand All @@ -41,6 +49,7 @@ protected override void OnStartup(StartupEventArgs e)
break;
default: //english default
dict.Source = new Uri(@"Resources\Language\en-US.xaml", UriKind.Relative);
ConfigHelper.Instance.SetLang("en");
break;
}
Current.Resources.MergedDictionaries.Add(dict);
Expand Down Expand Up @@ -68,7 +77,7 @@ protected override void OnStartup(StartupEventArgs e)

//tray icon
mutex = new Mutex(true, "FrogyMainProgram");
if (mutex.WaitOne(0, false))
if (mutex.WaitOne(0, false) || e.Args[0] == "restart")
{
taskbarIcon = (TaskbarIcon)FindResource("icon");

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

Current.Shutdown();
Environment.Exit(1);
}
}


private void SystemEvents_SessionEnded(object sender, SessionEndedEventArgs e)
{
appData.Save();
Expand Down
3 changes: 1 addition & 2 deletions Frogy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
<TargetZone>Internet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
Expand Down Expand Up @@ -168,7 +168,6 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Resources\Language\LanguageHelper.cs" />
<Compile Include="Resources\Theme\ThemeHelper.cs" />
<Compile Include="ViewModels\DashboardViewModel.cs" />
<Compile Include="ViewModels\OptionViewModel.cs" />
<Compile Include="ViewModels\OverViewViewModel.cs" />
Expand Down
65 changes: 64 additions & 1 deletion Methods/MyDeviceHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

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


/// <summary>
/// 读取设备状态
/// 0 代表锁定
Expand Down Expand Up @@ -138,5 +140,66 @@ public static int DeviceState
return dwFlags;
}
}

public static void RegisterStartup()
{
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true) ??
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

Assembly curAssembly = Assembly.GetExecutingAssembly();
key.SetValue(curAssembly.GetName().Name, curAssembly.Location);
}
catch { }
}

public static void DeregisterStartup()
{
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true) ??
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

Assembly curAssembly = Assembly.GetExecutingAssembly();
key.DeleteValue(curAssembly.GetName().Name);
}
catch { }
}

public static bool GetStartupStatus()
{
bool result = false;
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true) ??
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

Assembly curAssembly = Assembly.GetExecutingAssembly();

string[] values = key.GetValueNames();
foreach(string s in values) if (s == curAssembly.GetName().Name) result = true;
}
catch { }

return result;
}

public static void PromotePermission()
{
ProcessStartInfo psi = new ProcessStartInfo();
Assembly curAssembly = Assembly.GetExecutingAssembly();

psi.FileName = curAssembly.Location;
psi.Verb = "runas";
psi.Arguments = "restart";

try
{
Process.Start(psi);
Environment.Exit(1);
}
catch { }
}
}
}
3 changes: 2 additions & 1 deletion Methods/MyProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Media.Imaging;
using System.Windows;

namespace Frogy.Methods
{
Expand Down Expand Up @@ -150,7 +151,7 @@ public static bool IsProcessUWP(Process process)
}
catch(Exception e)
{
throw e;
throw (e);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Properties/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" Unrestricted="true" />
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
Expand Down
4 changes: 4 additions & 0 deletions Resources/Language/en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@
<system:String x:Key="Option_LanguageTitle">Launage</system:String>
<system:String x:Key="Option_Info">*Some of the setting(s) will take effect after restarting Frogy.</system:String>
<system:String x:Key="Option_ThemeTitle">Theme</system:String>
<system:String x:Key="Option_ThemeDefault">Default</system:String>
<system:String x:Key="Option_ThemeNight">Night</system:String>
<system:String x:Key="Option_SystemTitle">System</system:String>
<system:String x:Key="Option_Startup">Start with windows</system:String>

</ResourceDictionary>
4 changes: 4 additions & 0 deletions Resources/Language/zh-CN.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@
<system:String x:Key="Option_LanguageTitle">语言</system:String>
<system:String x:Key="Option_Info">*部分设置在重启 时常 后生效。</system:String>
<system:String x:Key="Option_ThemeTitle">主题</system:String>
<system:String x:Key="Option_ThemeDefault">默认</system:String>
<system:String x:Key="Option_ThemeNight">夜晚</system:String>
<system:String x:Key="Option_SystemTitle">系统</system:String>
<system:String x:Key="Option_Startup">开机自启</system:String>

</ResourceDictionary>
8 changes: 6 additions & 2 deletions Resources/Theme/DarkTheme.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf">

xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:system="clr-namespace:System;assembly=mscorlib">

<system:String x:Key="en-US">Dark</system:String>
<system:String x:Key="zh-CN">夜间模式</system:String>

<Style x:Key="DefaultChartStyle" TargetType="lvc:CartesianChart">
<Setter Property="Foreground" Value="White"/>
</Style>
Expand Down
7 changes: 5 additions & 2 deletions Resources/Theme/DefaultTheme.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf">
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:system="clr-namespace:System;assembly=mscorlib">

<system:String x:Key="en-US">Default</system:String>
<system:String x:Key="zh-CN">默认</system:String>

<Style x:Key="DefaultChartStyle" TargetType="lvc:CartesianChart">
<Setter Property="Foreground" Value="Black"/>
Expand Down
21 changes: 0 additions & 21 deletions Resources/Theme/ThemeHelper.cs

This file was deleted.

32 changes: 17 additions & 15 deletions ViewModels/OptionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System.Windows.Input;

using Frogy.Resources.Language;
using Frogy.Resources.Theme;
using System.Windows.Controls;

namespace Frogy.ViewModels
Expand Down Expand Up @@ -116,20 +115,6 @@ public int LanguageListSelectedIndex
#endregion

#region Theme setting
private List<string> themeList = new List<string>();
public List<string> ThemeList
{
get
{
themeList.Clear();

foreach (KeyValuePair<int, string> pair in ThemeHelper.ThemeSets)
themeList.Add(pair.Value);

return themeList;
}
}

private int themeListSelectedIndex = ((App)Application.Current).appData.ThemeSetting >= 0 && ((App)Application.Current).appData.ThemeSetting <= 1 ?
((App)Application.Current).appData.ThemeSetting : 0;
public int ThemeListSelectedIndex
Expand All @@ -147,6 +132,23 @@ public int ThemeListSelectedIndex
}
#endregion

#region
private bool startupStatus = MyDeviceHelper.GetStartupStatus();
public bool StartupStatus
{
get { return startupStatus; }
set
{
if (value)
MyDeviceHelper.RegisterStartup();
else
MyDeviceHelper.DeregisterStartup();

startupStatus = value;
}
}
#endregion

#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged = delegate { };
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
Expand Down
30 changes: 3 additions & 27 deletions ViewModels/OverViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,14 @@ private List<DetailViewItem> PrintSummaryView(List<MyTimeDuration> durations)
{
List<DetailViewItem> result = new List<DetailViewItem>();

string systemState;

foreach (MyTimeDuration timeSpan in durations)
{
switch (timeSpan.TimeDurationTask.ComputerStatus)
{
case 1:
systemState = "On active";
break;

case 0:
systemState = "Locked";
break;

case 2:
systemState = "Forgy exited";
break;
}

DetailViewItem tmp = new DetailViewItem()
{
StartTime = timeSpan.StartTime.ToString(),
StopTime = timeSpan.StopTime.ToString(),
AppDuration = timeSpan.Duration.ToString(),
AppIcon = MyDataHelper.BitmapToBitmapImage(
MyDataHelper.Base64StringToImage(timeSpan.TimeDurationTask.ApplicationIcon_Base64)),
AppIcon = MyDataHelper.BitmapToBitmapImage(MyDataHelper.Base64StringToImage(timeSpan.TimeDurationTask.ApplicationIcon_Base64)),
AppName = timeSpan.TimeDurationTask.ApplicationName,
WindowTitle = timeSpan.TimeDurationTask.ApplicationTitle,
SystemState = timeSpan.TimeDurationTask.ComputerStatus.ToString()
Expand All @@ -164,18 +146,12 @@ public OverViewViewModel()
"13:00", "14:00", "15:00", "16:00", "17:00", "18:00",
"19:00", "20:00", "21:00", "22:00", "23:00"};



OverviewChartFormatter = value => value + "min";
}

private async void Update()
{
await Task.Run(() =>
{
((App)Application.Current).appData.Load(displayDate);
});

((App)Application.Current).appData.Load(displayDate);
MyDay today = ((App)Application.Current).appData.AllDays[displayDate];

await Task.Run(() =>
Expand All @@ -191,7 +167,7 @@ await Task.Run(() =>
foreach (StackedColumnSeries i in OverviewChart_tmp)
{
OverviewChart.Add(i);
Thread.Sleep(220);
Thread.Sleep(20);
}
});
}
Expand Down
Loading