From 7d2f68a66a3ee6fdcaf9a43cdf9bb53d19b505d4 Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 14 Sep 2021 19:03:36 +0200 Subject: [PATCH] - Add GitHub and Download plugins button - Add auto updater - Disable calender --- src/DesktopMagic/App.xaml.cs | 36 +++++++++++++++++- src/DesktopMagic/CalendarManagment.cs | 16 ++------ src/DesktopMagic/DesktopMagic.csproj | 7 ++-- src/DesktopMagic/MainWindow.xaml | 13 +++++-- src/DesktopMagic/MainWindow.xaml.cs | 21 +++++++++- .../Resources/StringResources.de.xaml | 1 + .../Resources/StringResources.en.xaml | 1 + src/DesktopMagicPlugin.Test/PluginScript.cs | 2 +- update/DesktopMagic.zip | Bin 0 -> 6935126 bytes update/updateInfo.json | 4 ++ 10 files changed, 77 insertions(+), 24 deletions(-) create mode 100644 update/DesktopMagic.zip create mode 100644 update/updateInfo.json diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index 4a87422..7120f71 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -1,4 +1,6 @@ -using System; +using AlwaysUpToDate; +using System; +using System.Diagnostics; using System.Threading; using System.Windows; @@ -10,6 +12,11 @@ namespace DesktopMagic public partial class App : Application { private Mutex _mutex; +#if DEBUG + private readonly Updater updater = new Updater(TimeSpan.FromHours(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/develop/update/updateInfo.json"); +#else + private readonly Updater updater = new Updater(TimeSpan.FromHours(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json"); +#endif public App() { @@ -25,11 +32,36 @@ namespace DesktopMagic } else { - // Add Event handler to exit event. Exit += CloseMutexHandler; + + updater.ProgressChanged += Updater_ProgressChanged; + updater.OnException += Updater_OnException; + updater.NoUpdateAvailible += Updater_NoUpdateAvailible; + updater.UpdateAvailible += Updater_UpdateAvailible; + updater.Start(); } } + private void Updater_UpdateAvailible(string version, string additionalInformation) + { + updater.Update(); + } + + private void Updater_NoUpdateAvailible() + { + Debug.WriteLine("No update avalible."); + } + + private void Updater_OnException(Exception exception) + { + Debug.WriteLine("Update exception: " + exception); + } + + private void Updater_ProgressChanged(long? totalFileSize, long totalBytesDownloaded, double? progressPercentage) + { + Debug.WriteLine($"{progressPercentage}% {totalBytesDownloaded}/{totalFileSize}"); + } + protected virtual void CloseMutexHandler(object sender, EventArgs e) { _mutex?.Close(); diff --git a/src/DesktopMagic/CalendarManagment.cs b/src/DesktopMagic/CalendarManagment.cs index 63bd82b..96f0f6b 100644 --- a/src/DesktopMagic/CalendarManagment.cs +++ b/src/DesktopMagic/CalendarManagment.cs @@ -5,6 +5,7 @@ using Google.Apis.Services; using Google.Apis.Util.Store; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Threading; @@ -21,14 +22,11 @@ namespace DesktopMagic List upcomingEventNames = new List(); List upcomingEventTimes = new List(); UserCredential credential; - Console.WriteLine("1"); if (!File.Exists("credentials.json")) return (new(), new()); - using (var stream = - new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) + using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) { - Console.WriteLine("2"); // The file token.json stores the user's access and refresh tokens, and is created // automatically when the authorization flow completes for the first time. string credPath = "token.json"; @@ -38,9 +36,8 @@ namespace DesktopMagic "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; - Console.WriteLine("Credential file saved to: " + credPath); + Debug.WriteLine("Credential file saved to: " + credPath); } - Console.WriteLine("3"); // Create Google Calendar API service. var service = new CalendarService(new BaseClientService.Initializer() @@ -49,8 +46,6 @@ namespace DesktopMagic ApplicationName = ApplicationName, }); - Console.WriteLine("4"); - // Define parameters of request. EventsResource.ListRequest request = service.Events.List("primary"); request.TimeMin = DateTime.Now; @@ -59,11 +54,8 @@ namespace DesktopMagic request.MaxResults = 10; request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime; - Console.WriteLine("5"); // List events. Events events = request.Execute(); - Console.WriteLine("6"); - Console.WriteLine("Upcoming events:"); if (events.Items != null && events.Items.Count > 0) { foreach (var eventItem in events.Items) @@ -80,8 +72,6 @@ namespace DesktopMagic } } } - - Console.WriteLine("7"); return (upcomingEventNames, upcomingEventTimes); } } diff --git a/src/DesktopMagic/DesktopMagic.csproj b/src/DesktopMagic/DesktopMagic.csproj index 836e3b8..9b79f9a 100644 --- a/src/DesktopMagic/DesktopMagic.csproj +++ b/src/DesktopMagic/DesktopMagic.csproj @@ -20,11 +20,12 @@ + - + - - + + diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml index 52b8869..0cdac8e 100644 --- a/src/DesktopMagic/MainWindow.xaml +++ b/src/DesktopMagic/MainWindow.xaml @@ -9,9 +9,9 @@ Background="{DynamicResource MaterialDesignPaper}" FontFamily="{DynamicResource MaterialDesignFont}" Height="520" - Width="550" + Width="570" MinHeight="520" - MinWidth="500" + MinWidth="570" WindowState="Minimized" StateChanged="Window_StateChanged" Loaded="Window_Loaded"> @@ -38,7 +38,7 @@ - + @@ -104,15 +104,20 @@ + - +