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 1 commit
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
Prev Previous commit
better startup
  • Loading branch information
dimojang committed Mar 28, 2021
commit 38faf6626487b904f3b532fb9d29a9dbd23b4d1b
13 changes: 11 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 Down Expand Up @@ -69,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 @@ -92,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
19 changes: 19 additions & 0 deletions Methods/MyDeviceHelper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +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 @@ -182,5 +184,22 @@ public static bool GetStartupStatus()

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
2 changes: 1 addition & 1 deletion Properties/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
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