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

Commit

Permalink
Merge pull request #4734 from toggl-open-source/fix/crash-in-tutorial
Browse files Browse the repository at this point in the history
Fix crash with NullReferenceException in Tutorial
  • Loading branch information
atsvirchkova authored Dec 7, 2020
2 parents 64dbeb9 + deb3c55 commit 578058e
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 38 deletions.
10 changes: 9 additions & 1 deletion src/ui/windows/TogglDesktop/TogglDesktop/Toggl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,15 @@ public static readonly BehaviorSubject<UpdateStatus> OnUpdateDownloadStatus
public static readonly BehaviorSubject<DateTime> TimelineSelectedDate = new BehaviorSubject<DateTime>(DateTime.Today);

public static readonly BehaviorSubject<TogglTimeEntryView?> RunningTimeEntry = new BehaviorSubject<TogglTimeEntryView?>(null);
public static IObservable<Unit> StoppedTimerState = RunningTimeEntry.Where(te => te == null).Select(_ => Unit.Default);

public static readonly IObservable<Unit> StoppedTimerState =
RunningTimeEntry
.Where(te => te == null)
.Select(_ => Unit.Default);
public static readonly IObservable<TogglTimeEntryView> RunningTimerState =
RunningTimeEntry
.Where(te => te != null)
.Select(te => te.Value);
public static event DisplayTimelineUI OnDisplayTimelineUI = delegate { };
private static void listenToLibEvents()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<FontFamily x:Key="DefaultFont">Segoe UI</FontFamily>

<sys:Double x:Key="TimerHeight">68</sys:Double>
<sys:Double x:Key="TabsHeight">40</sys:Double>

<Style TargetType="Control">
<Setter Property="FontFamily" Value="{StaticResource DefaultFont}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

using System;
using System.Reactive.Disposables;
using System;

namespace TogglDesktop.Tutorial
{
Expand All @@ -14,7 +12,7 @@ public BasicTutorialScreen2()
private IDisposable _runningTimeEntryObservable;
protected override void initialise()
{
_runningTimeEntryObservable = Toggl.RunningTimeEntry.Subscribe(this.onRunningTimerState);
_runningTimeEntryObservable = Toggl.RunningTimerState.Subscribe(this.onRunningTimerState);
this.tutorialManager.Timer.DescriptionTextBoxTextChanged += this.onDescriptionTextChanged;
}

Expand All @@ -24,7 +22,7 @@ protected override void cleanup()
this.tutorialManager.Timer.DescriptionTextBoxTextChanged -= this.onDescriptionTextChanged;
}

private void onRunningTimerState(Toggl.TogglTimeEntryView? te)
private void onRunningTimerState(Toggl.TogglTimeEntryView te)
{
this.tutorialManager.ActivateScreen<BasicTutorialScreen4>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

using System;
using System.Reactive.Disposables;

namespace TogglDesktop.Tutorial
{
Expand All @@ -14,15 +13,15 @@ public BasicTutorialScreen3()
private IDisposable _runningTimeEntryObservable;
protected override void initialise()
{
_runningTimeEntryObservable = Toggl.RunningTimeEntry.Subscribe(this.onRunningTimerState);
_runningTimeEntryObservable = Toggl.RunningTimerState.Subscribe(this.onRunningTimerState);
}

protected override void cleanup()
{
_runningTimeEntryObservable.Dispose();
}

private void onRunningTimerState(Toggl.TogglTimeEntryView? te)
private void onRunningTimerState(Toggl.TogglTimeEntryView te)
{
this.activateScreen<BasicTutorialScreen4>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override void initialise()
protected override void cleanup()
{
Toggl.OnTimeEntryEditor -= this.onTimeEntryEditor;
_timerStateObservable.Dispose();
_timerStateObservable?.Dispose();
}

private void onTimeEntryEditor(bool open, Toggl.TogglTimeEntryView te, string focusedFieldName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void initialise()
protected override void cleanup()
{
Toggl.OnTimeEntryList -= this.onTimeEntryList;
_timerStateObservable.Dispose();
_timerStateObservable?.Dispose();
}

private void onTimeEntryList(bool open, List<Toggl.TogglTimeEntryView> list, bool showLoadMoreButton)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected override void initialise()

protected override void cleanup()
{
_timerStateObservable.Dispose();
_timerStateObservable?.Dispose();
}

private void onStoppedTimerState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:tutorial="clr-namespace:TogglDesktop.Tutorial"
xmlns:toggl="clr-namespace:TogglDesktop"
xmlns:system="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
d:DesignHeight="559.069" d:DesignWidth="381.927"
Style="{StaticResource TutorialScreen}">
Expand All @@ -13,16 +14,18 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<FrameworkElement Grid.Row="0" Height="{DynamicResource TimerHeight}"/>
<FrameworkElement Grid.Row="1" Height="{StaticResource TimeEntryDayHeaderHeight}"/>
<FrameworkElement Grid.Row="2" Height="{StaticResource TimeEntryHeight}"/>
<FrameworkElement Grid.Row="1" Height="{StaticResource TabsHeight}"/>
<FrameworkElement Grid.Row="2" Height="{StaticResource TimeEntryDayHeaderHeight}"/>
<FrameworkElement Grid.Row="3" Height="{StaticResource TimeEntryHeight}"/>

<Grid Grid.Row="3" Background="{StaticResource ViewBackgroundLight}">
<Grid Grid.Row="4" Background="{StaticResource ViewBackgroundLight}">
<StackPanel Background="{StaticResource TutorialDarkOverlay}">
<Grid Margin="0 0 0 40">
<TextBlock Margin="20 10 10 10" TextAlignment="Center"
<TextBlock Margin="30 10 10 10" TextAlignment="Center"
HorizontalAlignment="Left">
<Image Source="/TogglDesktop;component/Resources/tutorial-arrow-curved.png"
Height="22" VerticalAlignment="Top" Margin="-20 -5 -10 5">
Expand All @@ -36,7 +39,7 @@
in the list.
</TextBlock>

<TextBlock Margin="10" HorizontalAlignment="Right">
<TextBlock Margin="10 10 20 10" HorizontalAlignment="Right">
Or <Bold>continue</Bold>
<Image Source="/TogglDesktop;component/Resources/tutorial-arrow-curved.png"
Height="22" VerticalAlignment="Top" Margin="-15 -5 -10 5">
Expand All @@ -60,7 +63,7 @@
</StackPanel>
</Grid>

<toggl:ProgressBar Grid.Row="3" Margin="30 20"
<toggl:ProgressBar Grid.Row="4" Margin="30 20"
VerticalAlignment="Bottom"
MaxValue="6" Value="6"/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

using System;
using System.Windows;

namespace TogglDesktop.Tutorial
{
Expand All @@ -14,7 +13,7 @@ public BasicTutorialScreen7()
private IDisposable _runningTimeEntryObservable;
protected override void initialise()
{
_runningTimeEntryObservable = Toggl.RunningTimeEntry.Subscribe(this.onRunningTimerState);
_runningTimeEntryObservable = Toggl.RunningTimerState.Subscribe(this.onRunningTimerState);
Toggl.OnTimeEntryEditor += this.onTimerEntryEditor;
}

Expand All @@ -24,7 +23,7 @@ protected override void cleanup()
Toggl.OnTimeEntryEditor -= this.onTimerEntryEditor;
}

private void onRunningTimerState(Toggl.TogglTimeEntryView? te)
private void onRunningTimerState(Toggl.TogglTimeEntryView te)
{
this.quitTutorial();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public TimerViewModel(bool isMiniTimer)

setupSecondsTimer();

Toggl.RunningTimeEntry.Subscribe(onRunningTimerState);
Toggl.RunningTimerState.Subscribe(onRunningTimerState);
Toggl.StoppedTimerState.Subscribe(_ => this.onStoppedTimerState());

ResetRunningTimeEntry(false, true);
Expand Down Expand Up @@ -72,12 +72,11 @@ private void setupSecondsTimer()
};
}

private void onRunningTimerState(Toggl.TogglTimeEntryView? te)
private void onRunningTimerState(Toggl.TogglTimeEntryView te)
{
using (Performance.Measure("timer responding to OnRunningTimerState"))
{
if (te != null)
SetRunningTimeEntry(te.Value);
SetRunningTimeEntry(te);
secondsTimer.IsEnabled = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Border BorderThickness="0" Margin="0,0,0,0" Background="{DynamicResource Toggl.CardBackground}" Height="40"
<Border BorderThickness="0" Margin="0,0,0,0" Background="{DynamicResource Toggl.CardBackground}"
Height="{StaticResource TabsHeight}"
Visibility="{Binding Path=IsTimelineViewEnabled, Converter={StaticResource BooleanToVisibilityConverter}}">
<UniformGrid Rows="1" x:Name="HeaderPanel" IsItemsHost="True"
VerticalAlignment="Stretch"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ private void initializeEvents()
Toggl.OnOnlineState += this.onOnlineState;
Toggl.OnURL += this.onURL;
Toggl.OnUserTimeEntryStart += this.onUserTimeEntryStart;
Toggl.RunningTimeEntry.Subscribe(this.onRunningTimerState);
Toggl.StoppedTimerState.Subscribe(_ => this.onStoppedTimerState());
Toggl.RunningTimeEntry.Subscribe(this.onRunningTimeEntry);
Toggl.OnSettings += this.onSettings;
Toggl.OnDisplayInAppNotification += this.onDisplayInAppNotification;
}
Expand Down Expand Up @@ -301,17 +300,9 @@ private void onTimeEntryEditor(bool open, Toggl.TogglTimeEntryView te, string fo
}
}

private void onStoppedTimerState()
private void onRunningTimeEntry(Toggl.TogglTimeEntryView? te)
{
if (this.TryBeginInvoke(this.onStoppedTimerState))
return;

this.updateTracking(null);
}

private void onRunningTimerState(Toggl.TogglTimeEntryView? te)
{
if (this.TryBeginInvoke(this.onRunningTimerState, te))
if (this.TryBeginInvoke(this.onRunningTimeEntry, te))
return;

this.updateTracking(te);
Expand Down

0 comments on commit 578058e

Please sign in to comment.