mirror of
https://github.com/ckaczor/SystemTemperatureStatusWindow.git
synced 2026-01-14 01:25:42 -05:00
Start working towards Squirrel install/update
This commit is contained in:
@@ -1,29 +1,91 @@
|
||||
using FloatingStatusWindowLibrary;
|
||||
using Microsoft.Win32.TaskScheduler;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Windows.Threading;
|
||||
using SystemTemperatureStatusWindow.Options;
|
||||
using SystemTemperatureStatusWindow.Properties;
|
||||
using SystemTemperatureStatusWindow.SystemTemperatureService;
|
||||
using Common.Wpf.Windows;
|
||||
using Task = Microsoft.Win32.TaskScheduler.Task;
|
||||
|
||||
namespace SystemTemperatureStatusWindow
|
||||
{
|
||||
public class WindowSource : IWindowSource, IDisposable
|
||||
{
|
||||
private const string ScheduledTaskName = "SystemTemperatureService";
|
||||
|
||||
private readonly FloatingStatusWindow _floatingStatusWindow;
|
||||
private readonly Timer _refreshTimer;
|
||||
private readonly Dispatcher _dispatcher;
|
||||
|
||||
private CategoryWindow _optionsWindow;
|
||||
|
||||
internal WindowSource()
|
||||
{
|
||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||
|
||||
try
|
||||
{
|
||||
using (var taskService = new TaskService())
|
||||
{
|
||||
var existingTask = taskService.FindTask(ScheduledTaskName);
|
||||
|
||||
if (existingTask == null)
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
|
||||
var path = Path.GetDirectoryName(assembly.Location);
|
||||
|
||||
if (path != null)
|
||||
{
|
||||
var fileName = Path.Combine(path, "SystemTemperatureService.exe");
|
||||
|
||||
Process.Start(fileName, "-install");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignored
|
||||
}
|
||||
|
||||
_floatingStatusWindow = new FloatingStatusWindow(this);
|
||||
_floatingStatusWindow.SetText(Resources.Loading);
|
||||
|
||||
_refreshTimer = new Timer(Settings.Default.UpdateInterval) { AutoReset = false };
|
||||
_refreshTimer.Elapsed += HandleTimerElapsed;
|
||||
_refreshTimer.Start();
|
||||
|
||||
|
||||
System.Threading.Tasks.Task.Factory.StartNew(UpdateApp).ContinueWith(task => StartUpdate(task.Result.Result));
|
||||
}
|
||||
|
||||
private void StartUpdate(bool updateRequired)
|
||||
{
|
||||
if (updateRequired)
|
||||
return;
|
||||
|
||||
System.Threading.Tasks.Task.Factory.StartNew(() => _refreshTimer.Start());
|
||||
}
|
||||
|
||||
private async Task<bool> UpdateApp()
|
||||
{
|
||||
return await UpdateCheck.CheckUpdate(HandleUpdateStatus);
|
||||
}
|
||||
|
||||
private void HandleUpdateStatus(UpdateCheck.UpdateStatus status, string message)
|
||||
{
|
||||
if (status == UpdateCheck.UpdateStatus.None)
|
||||
message = Resources.Loading;
|
||||
|
||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(message));
|
||||
}
|
||||
|
||||
private void HandleTimerElapsed(object sender, ElapsedEventArgs e)
|
||||
@@ -119,12 +181,36 @@ namespace SystemTemperatureStatusWindow
|
||||
_refreshTimer.Start();
|
||||
}
|
||||
|
||||
public void ShowAbout()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name => "System Temperature";
|
||||
|
||||
public System.Drawing.Icon Icon => Resources.ApplicationIcon;
|
||||
|
||||
public void ShowSettings()
|
||||
{
|
||||
var panels = new List<CategoryPanel>
|
||||
{
|
||||
new GeneralOptionsPanel(),
|
||||
new AboutOptionsPanel()
|
||||
};
|
||||
|
||||
if (_optionsWindow == null)
|
||||
{
|
||||
_optionsWindow = new CategoryWindow(null, panels, Resources.ResourceManager, "OptionsWindow");
|
||||
_optionsWindow.Closed += (o, args) => { _optionsWindow = null; };
|
||||
}
|
||||
|
||||
var dialogResult = _optionsWindow.ShowDialog();
|
||||
|
||||
if (dialogResult.HasValue && dialogResult.Value)
|
||||
{
|
||||
Settings.Default.Save();
|
||||
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
@@ -132,8 +218,9 @@ namespace SystemTemperatureStatusWindow
|
||||
Update();
|
||||
}
|
||||
|
||||
public bool HasSettingsMenu => false;
|
||||
public bool HasSettingsMenu => true;
|
||||
public bool HasRefreshMenu => true;
|
||||
public bool HasAboutMenu => false;
|
||||
|
||||
public string WindowSettings
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user