Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Move from library events to observables (win)
Browse files Browse the repository at this point in the history
  • Loading branch information
skel35 committed Mar 25, 2020
1 parent c9c5aa2 commit 99f57b9
Show file tree
Hide file tree
Showing 34 changed files with 553 additions and 735 deletions.
28 changes: 15 additions & 13 deletions src/ui/windows/TogglDesktop/TogglDesktop/BugsnagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,26 @@ public static void Init()
});
});

Toggl.OnError += delegate(string errmsg, bool user_error)
{
Toggl.Debug(errmsg);
try
{
if (!user_error && bugsnag.Configuration.ReleaseStage != "development")
NotifyBugsnag(new Exception(errmsg));
}
catch (Exception ex)
{
Toggl.Debug("Could not check if can notify bugsnag: " + ex);
}
};
Toggl.OnError.Subscribe(x => OnError(x.errorMessage, x.isUserError));

Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}

private static void OnError(string errorMessage, bool isUserError)
{
Toggl.Debug(errorMessage);
try
{
if (!isUserError && bugsnag.Configuration.ReleaseStage != "development")
NotifyBugsnag(new Exception(errorMessage));
}
catch (Exception ex)
{
Toggl.Debug("Could not check if can notify bugsnag: " + ex);
}
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
NotifyBugsnag(e.ExceptionObject as Exception);
Expand Down
12 changes: 5 additions & 7 deletions src/ui/windows/TogglDesktop/TogglDesktop/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Diagnostics;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reflection;
using System.Windows.Interop;
using System.Windows.Media;
Expand All @@ -10,10 +12,8 @@ namespace TogglDesktop
static class Program
{
private static SingleInstanceManager<App> singleInstanceManager;
public static ulong UserId {
get;
private set;
}
private static readonly BehaviorSubject<ulong> UserIdSubject = new BehaviorSubject<ulong>(0);
public static ulong UserId => UserIdSubject.Value;
public static bool IsLoggedIn => UserId > 0;

[STAThread]
Expand All @@ -29,9 +29,7 @@ static void Main(string[] args)

private static void OnBeforeStartup()
{
Toggl.OnLogin += delegate (bool open, ulong user_id) {
UserId = user_id;
};
Toggl.OnLogin.Select(x => x.userId).Subscribe(UserIdSubject);
BugsnagService.Init();
singleInstanceManager.BeforeStartup -= OnBeforeStartup;
}
Expand Down
Loading

0 comments on commit 99f57b9

Please sign in to comment.