Skip to content

Commit

Permalink
Fix misc bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed Jul 11, 2012
1 parent eb56b98 commit 4aa9688
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
6 changes: 4 additions & 2 deletions Shotclock/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Window x:Class="Shotclock.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
Title="MainWindow" Height="350" Width="525" Background="Black">
<Grid>

<Viewbox>
<TextBlock FontSize="64" Text="{Binding CommitAge}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
</Viewbox>
</Grid>
</Window>
7 changes: 7 additions & 0 deletions Shotclock/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -11,6 +13,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Shotclock.ViewModels;

namespace Shotclock
{
Expand All @@ -21,6 +24,10 @@ public partial class MainWindow : Window
{
public MainWindow()
{
DataContext =
new MainViewModel(
Observable.FromEventPattern(x => Activated += x, x => Activated -= x).Select(_ => Unit.Default));

InitializeComponent();
}
}
Expand Down
18 changes: 9 additions & 9 deletions Shotclock/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Shotclock.ViewModels
public interface IMainViewModel : IReactiveNotifyPropertyChanged
{
bool IsVersionControlled { get; }
string RepositoryRoot { get; }
string RepositoryRoot { get; }

IObservable<Unit> RefreshNotification { get; }
IObservable<Unit> GotFocusNotification { get; }
Expand Down Expand Up @@ -49,29 +49,29 @@ public TimeSpan CommitAge {
get { return _CommitAge.Value; }
}

public MainViewModel(IObservable<Unit> gotFocusNotification = null, IObservable<Unit> refreshNotification = null)
public MainViewModel(IObservable<Unit> gotFocusNotification = null, IObservable<Unit> refreshNotification = null, Func<TimeSpan> getIdleTime = null)
{
RepositoryRoot = findRepositoryRoot();
RepositoryRoot = findRepositoryRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
IsVersionControlled = (!String.IsNullOrEmpty(RepositoryRoot));

GotFocusNotification = gotFocusNotification ?? Observable.Never<Unit>();
RefreshNotification = refreshNotification ??
(IsVersionControlled ? createFileChangeWatch(RepositoryRoot) : Observable.Never<Unit>());
RefreshNotification = refreshNotification ??
(IsVersionControlled ? createFileChangeWatch(RepositoryRoot).Select(_ => Unit.Default) : Observable.Never<Unit>());

Observable.Merge(gotFocusNotification, refreshNotification)
Observable.Merge(GotFocusNotification, RefreshNotification)
.Where(_ => IsVersionControlled)
.Select(_ => fetchLatestCommitForHead(RepositoryRoot))
.Select(x => x.Author.When)
.ToProperty(this, x => LatestCommit, DateTimeOffset.MinValue);
.ToProperty(this, x => x.LatestCommit, DateTimeOffset.MinValue);

var shouldUpdateClock = Observable.Merge(
gotFocusNotification,
this.WhenAny(x => x.LatestCommit, _ => Unit.Default),
Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1.0)).Select(_ => Unit.Default)
Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1.0), RxApp.DeferredScheduler).Select(_ => Unit.Default)
).Where(_ => IsVersionControlled);

shouldUpdateClock
.Select(_ => getIdleTime())
.Select(_ => getIdleTime != null ? getIdleTime() : this.getIdleTime())
.Buffer(2, 1).Where(x => x[1] < TimeSpan.FromSeconds(5.0) && x[0] > TimeSpan.FromSeconds(30.0))
.Select(_ => RxApp.DeferredScheduler.Now)
.StartWith(RxApp.DeferredScheduler.Now)
Expand Down

0 comments on commit 4aa9688

Please sign in to comment.