Skip to content

Commit

Permalink
add tomatoNow button and adjust layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Moedrian committed Dec 17, 2024
1 parent 1fc6b50 commit 48d2e14
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 34 deletions.
52 changes: 41 additions & 11 deletions src/Tomato/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
FontSize="24"
Title="Tomato Clock" Height="300" Width="620" ResizeMode="CanMinimize">
Title="Tomato Clock" Height="300" Width="680" ResizeMode="CanMinimize">
<Window.Resources>
<Style TargetType="Label">
<Setter Property="FontFamily" Value="Bell MT"/>
Expand All @@ -15,7 +15,8 @@
<Setter Property="Margin" Value="5"/>
</Style>
<Style TargetType="TextBlock">
<Setter Property="FontFamily" Value="Consolas"/>
<Setter Property="FontFamily" Value="Courier New"/>
<Setter Property="FontWeight" Value="DemiBold"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="5"/>
Expand All @@ -24,12 +25,13 @@
<Setter Property="FontFamily" Value="Bell MT"/>
<Setter Property="Height" Value="40"/>
<Setter Property="BorderThickness" Value="0.5"/>
<Setter Property="Background" Value="#FFCCBC"/>
<Setter Property="Background" Value="#EF9A9A"/>
<Setter Property="BorderBrush" Value="Beige"/>
<Setter Property="Margin" Value="5"/>
</Style>
<Style TargetType="ComboBox">
<Setter Property="FontFamily" Value="Consolas"/>
<Setter Property="FontFamily" Value="Courier New"/>
<Setter Property="FontWeight" Value="DemiBold"/>
<Setter Property="Height" Value="40"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
Expand All @@ -40,7 +42,7 @@
<Setter Property="Background" Value="#FBE9E7"/>
</Style>
</Window.Resources>
<Grid Background="#FBE9E7">
<Grid Background="#FFCDD2">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
Expand All @@ -49,9 +51,9 @@
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.5*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1.5*"/>
</Grid.ColumnDefinitions>

<Label Grid.Row="0" Grid.Column="0" Content="Interval:"/>
Expand All @@ -66,14 +68,42 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ComboBox Grid.Column="0" Name="HourBox"/>
<TextBlock Grid.Column="1" Text=":"/>
<TextBlock Grid.Column="1" Text=":" Padding="0"/>
<ComboBox Grid.Column="2" Name="MinuteBox"/>
</Grid>

<Label Grid.Row="2" Grid.Column="0" Content="Next Notification:"/>
<TextBlock Grid.Row="2" Grid.Column="1" Name="CounterDown"/>
<Label Grid.Row="3" Grid.Column="0" Content="Next Tomato Launch:"/>
<TextBlock Grid.Row="3" Grid.Column="1" Name="CounterDown" Padding="0, 6, 0, 0"/>
<Button Grid.Row="3" Grid.Column="2" Name="TomatoNowButton"
Background="#FFCDD2"
BorderBrush="#FFCDD2"
HorizontalAlignment="Center"
Width="120" Height="40">
<StackPanel Orientation="Horizontal">
<Image Source="tomato.ico" Height="32"/>
<TextBlock Text="Now!" FontFamily="Bell MT" FontWeight="Normal"/>
</StackPanel>
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="Border" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FFEBEE" TargetName="Border"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>

<Button Grid.Row="3" Grid.Column="1" Content="Apply" Name="ApplyButton"/>
<Button Grid.Row="2" Grid.Column="1" Content="Apply" Name="ApplyButton"/>
</Grid>
</Window>

64 changes: 41 additions & 23 deletions src/Tomato/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class MainWindow : Window
{
private NotifyIcon? _icon;

private readonly string[] _intervals = new[] { 5, 10, 15, 20, 25, 30, 35, 40, 45 }.Select(i => i.ToString()).ToArray();
private readonly string[] _intervals = Enumerable.Range(1, 9).Select(i => (i * 5).ToString()).ToArray();
private readonly string[] _hours = Enumerable.Range(0, 24).Select(x => x.ToString("00")).ToArray();
private readonly string[] _minutes = Enumerable.Range(0, 60).Select(x => x.ToString("00")).ToArray();

Expand All @@ -26,6 +26,8 @@ public partial class MainWindow : Window
private const string DismissButtonArgKey = "action";
private const string DismissButtonArgValue = "start";

private bool _toastOn;

public MainWindow()
{
var p = Process.GetProcessesByName("Tomato");
Expand Down Expand Up @@ -110,7 +112,7 @@ private void AddEvents()
{
ShowInTaskbar = false;
const string title = "Tomato Minimized";
const string text = "Click the tray icon to the config window.";
const string text = "Double click the tray icon to the config window.";
_icon?.ShowBalloonTip(0, title, text, ToolTipIcon.Info);
}
else if (WindowState == WindowState.Normal)
Expand All @@ -133,11 +135,22 @@ private void AddEvents()
{
Reset();
_timerCtrDwn?.Start();
_toastOn = false;
});
}
}
};

TomatoNowButton.Click += delegate
{
_ctrDwnInterval = TimeSpan.Zero;
CounterDown.Text = GetCtrDwnString();
_timerCtrDwn?.Stop();

if (!_toastOn)
DisplayTomatoNotification();
};

ApplyButton.Click += delegate
{
StoreUserConfig();
Expand All @@ -164,36 +177,41 @@ private void Reset()
{
var cfg = TomatoConfig.Deserialize();

IntervalBox.SelectedIndex = cfg.Interval / 5 - 1;
//IntervalBox.SelectedIndex = cfg.Interval / 5 - 1;
HourBox.SelectedIndex = cfg.OffTimeHour;
MinuteBox.SelectedIndex = cfg.OffTimeMinute;

_ctrDwnInterval = TimeSpan.FromMinutes(cfg.Interval);
}

private void DisplayTomatoNotification()
public static ToastContentBuilder GetToastContentBuilder()
{
const string title = "Tomato Clock Is Here.";
const string text = "Get up to drink some water!";
var msg = text + Environment.NewLine + CalculateOff();

Dispatcher.Invoke(delegate
{
var builder = new ToastContentBuilder()
.AddText(title)
.AddText(msg)
.SetToastScenario(ToastScenario.Reminder)
.AddButton(new ToastButton()
.SetContent("Dismiss")
.AddArgument(DismissButtonArgKey, DismissButtonArgValue)
.SetBackgroundActivation());

if (File.Exists(TomatoConfig.GetTomatoPicture()))
builder.AddAppLogoOverride(new Uri("file:///" + TomatoConfig.GetTomatoPicture()),
ToastGenericAppLogoCrop.Circle);

builder.Show();
});
var builder = new ToastContentBuilder()
.AddText(title)
.AddText(msg)
.SetToastScenario(ToastScenario.Reminder)
.AddButton(new ToastButton()
.SetContent("Start Another Tomato")
.AddArgument(DismissButtonArgKey, DismissButtonArgValue)
.SetBackgroundActivation());

if (File.Exists(TomatoConfig.GetTomatoPicture()))
builder.AddAppLogoOverride(new Uri("file:///" + TomatoConfig.GetTomatoPicture()),
ToastGenericAppLogoCrop.Circle);

return builder;
}

private void DisplayTomatoNotification()
{
if (!_toastOn)
GetToastContentBuilder().Show();

_toastOn = true;
}

private void Start()
Expand Down Expand Up @@ -230,13 +248,13 @@ private void StoreUserConfig()
{
try
{
var interval = int.Parse(IntervalBox.SelectedItem as string ?? throw new Exception("Interval parsing error."));
//var interval = int.Parse(IntervalBox.SelectedItem as string ?? throw new Exception("Interval parsing error."));
var hour = int.Parse(HourBox.SelectedItem as string ?? throw new Exception("Hour parsing error."));
var minute = int.Parse(MinuteBox.SelectedItem as string ?? throw new Exception("Minute parsing error."));

var cfg = new TomatoConfig
{
Interval = interval,
//Interval = interval,
OffTimeHour = hour,
OffTimeMinute = minute
};
Expand Down

0 comments on commit 48d2e14

Please sign in to comment.