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

[WIP] Move from library events to observables #3878

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
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