Skip to content

Commit

Permalink
Merge pull request #47 from Sandip124/fix/notificationMessageContainer
Browse files Browse the repository at this point in the history
Fix/notification message container
  • Loading branch information
Sandip124 authored Jul 6, 2022
2 parents ac6be13 + 1fdb5a0 commit 7f61c7a
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 57 deletions.
2 changes: 1 addition & 1 deletion BatteryNotifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<NugetTools>$(PkgNuGet_CommandLine)\tools</NugetTools>
<SquirrelTools>$(Pkgsquirrel_windows)\tools</SquirrelTools>

<Version>2.0.3</Version>
<Version>2.0.4</Version>

<NuspecFile>$(SolutionDir)ReleaseSpec.nuspec</NuspecFile>
</PropertyGroup>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion Deployment/Releases/RELEASES
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ C74E7B149399495BA580E3C0787D003A08872910 BatteryNotifier-1.9.1-full.nupkg 169455
4806AB34AB9C2A73AEB937564D2B6DB5FC679287 BatteryNotifier-2.0.2-delta.nupkg 24341
5A139C32C0C59B5F876E1582A18C9B4B888F3A35 BatteryNotifier-2.0.2-full.nupkg 5112906
A3E0F13A323576C0092DDC02253BF231E74989E5 BatteryNotifier-2.0.3-delta.nupkg 24843
29C57A2CFA3CAE4FE5220E0CD4EFE998D56EBFF6 BatteryNotifier-2.0.3-full.nupkg 5112125
29C57A2CFA3CAE4FE5220E0CD4EFE998D56EBFF6 BatteryNotifier-2.0.3-full.nupkg 5112125
075D7698594B7479E20993FE7A731F093FF918DC BatteryNotifier-2.0.4-delta.nupkg 26237
C953C570D0CB63BC9B82A8D72EBB89925657BD85 BatteryNotifier-2.0.4-full.nupkg 5112438
Binary file modified Deployment/Releases/Setup.exe
Binary file not shown.
Binary file modified Deployment/Releases/Setup.msi
Binary file not shown.
15 changes: 8 additions & 7 deletions Forms/Dashboard.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Forms/Dashboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ public void SetVersion(string? ver)
public void Notify(string status, int timeout = DefaultNotificationTimeout)
{
NotificationText.Text = status;
_debouncer.Debounce(() =>
{
NotificationText.Text = string.Empty;
}, timeout);
System.Threading.Thread.Sleep(timeout);
NotificationText.Text = string.Empty;
}

private void CloseIcon_Click(object? sender, EventArgs e)
Expand Down
81 changes: 37 additions & 44 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ internal static class Program

private static Form? MainForm;

private static bool IsUpdateInProgress = false;

private static string? version = UtilityHelper.AssemblyVersion;

/// <summary>
Expand All @@ -24,42 +22,47 @@ internal static class Program
[STAThread]
static void Main()
{
var appId = Setting.appSetting.Default.AppId;
if (string.IsNullOrEmpty(appId))
try
{
appId = Setting.appSetting.Default.AppId = Guid.NewGuid().ToString();
Setting.appSetting.Default.Save();
}
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledExpection);
AppDomain.CurrentDomain.ProcessExit += OnExit;
var appId = Setting.appSetting.Default.AppId;
if (string.IsNullOrEmpty(appId))
{
appId = Setting.appSetting.Default.AppId = Guid.NewGuid().ToString();
Setting.appSetting.Default.Save();
}

using Mutex mutex = new(false, "Global\\" + appId);
if (!mutex.WaitOne(0, false))
{
return;
}
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledExpection);

using Mutex mutex = new(false, "Global\\" + appId);
if (!mutex.WaitOne(0, false))
{
return;
}

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

MainForm = new Dashboard();
var dashboard = MainForm as Dashboard;
MainForm = new Dashboard();
var dashboard = MainForm as Dashboard;
#if RELEASE

if (InternetConnectivityHelper.CheckForInternetConnection())
if (InternetConnectivityHelper.CheckForInternetConnection())
{
dashboard?.Notify("🤿 Checking for update ...");
Task.Run( () =>InitUpdateManager()).Wait();
Task UpdateTask = new(CheckForUpdates);
UpdateTask.Start();
version = UpdateManager?.CurrentlyInstalledVersion().ToString();
}
#endif
dashboard?.SetVersion(version);

Application.Run(dashboard);
}
catch (Exception e)
{
Task.Run(() => InitUpdateManager()).Wait();
Task UpdateTask = new(CheckForUpdates);
UpdateTask.Start();
version = UpdateManager!.CurrentlyInstalledVersion().ToString();
dashboard?.Notify("🤿 Checking for update ...");
IsUpdateInProgress = true;
(MainForm as Dashboard)?.Notify(e.Message);
}
#endif
dashboard?.SetVersion(version);

Application.Run(dashboard);

}

Expand All @@ -79,41 +82,31 @@ static async void CheckForUpdates()
{
try
{
var updateInfo = await UpdateManager!.CheckForUpdate();

if (!IsUpdateInProgress) return;
var updateInfo = await UpdateManager?.CheckForUpdate()!;

if (updateInfo.ReleasesToApply.Count > 0)
{
var releaseEntry = await UpdateManager.UpdateApp();

if (releaseEntry != null)
{
IsUpdateInProgress = false;
(MainForm as Dashboard)?.Notify($"✅ Battery Notifier {releaseEntry.Version} downloaded. Restart to apply." );
(MainForm as Dashboard)?.Notify($"✅ Battery Notifier {releaseEntry.Version} downloaded. Restart to apply.");
}
}
else
{

IsUpdateInProgress = false;
(MainForm as Dashboard)?.Notify("✌ No Update Available");
}
}
catch (Exception)
{
MessageBox.Show("💀 Could not update app!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
(MainForm as Dashboard)?.Notify("💀 Could not update app!");
}
}

private static void OnExit(object? sender, EventArgs e)
{
UpdateManager?.Dispose();
}

static void OnUnhandledExpection(object? sender, UnhandledExceptionEventArgs args)
{
MessageBox.Show(args.ExceptionObject.ToString(),"Battery Notifier error!");
(MainForm as Dashboard)?.Notify("Unhandled exception occured.");
}

}
Expand Down

0 comments on commit 7f61c7a

Please sign in to comment.