Skip to content

Commit

Permalink
added desktop background mode, and refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
hookmanuk committed Apr 22, 2022
1 parent 03925c9 commit 5a816a9
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 26 deletions.
2 changes: 2 additions & 0 deletions BlockClocksWindows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<None Remove="plus-solid.png" />
<None Remove="plus-solid.svg" />
<None Remove="quit.png" />
<None Remove="refresh.png" />
</ItemGroup>

<ItemGroup>
Expand All @@ -41,6 +42,7 @@
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
<Resource Include="quit.png" />
<Resource Include="refresh.png" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion CardanoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Net;
using System.Threading.Tasks;

namespace ChainTime
namespace BlockClocksWindows
{
public partial class CardanoManager
{
Expand Down
38 changes: 31 additions & 7 deletions Config.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Window x:Class="ChainTime.Config"
<Window x:Class="BlockClocksWindows.Config"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ChainTime"
xmlns:local="clr-namespace:BlockClocksWindows"
xmlns:xctk1="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
ShowInTaskbar="False"
Expand All @@ -13,7 +13,14 @@
WindowStartupLocation="CenterOwner"
WindowStyle="ToolWindow"
Title="Config"
Loaded="Window_Loaded"
Closing="Window_Closing"
KeyUp="Window_KeyUp">

<Window.Resources>
<local:BoolRadioConverter x:Key="BoolRadioConverter" />
<local:BoolRadioConverter x:Key="InverseBoolRadioConverter" Inverse="True" />
</Window.Resources>
<Grid Margin="10">
<Grid.Resources>
<!-- Default settings for controls -->
Expand All @@ -38,6 +45,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
Expand All @@ -48,6 +56,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>

Expand All @@ -59,8 +68,14 @@
<TextBox Name="ADAAmount" Grid.Column="1" Grid.Row="2" IsReadOnly="True"/>
<Label Name="TransactionId" Grid.Column="0" Grid.Row="3">Transaction id:</Label>
<TextBox Name="TransactionAddress" Grid.Column="1" Grid.Row="3" TextChanged="TransactionAddress_LostFocus" />

<Label Name="WalletLabel" Grid.Column="0" Grid.Row="4">Linked address:</Label>
<TextBox Name="WalletAddress" Grid.Column="1" Grid.Row="4" IsEnabled="False" Text="{Binding Path=LinkedAddress}" LostFocus="WalletAddress_LostFocus" />
<Button x:Name="Refresh" Height="25" Width="25" Grid.Column="2" Grid.Row="4" Cursor="Hand" Background="Transparent" BorderThickness="0" BorderBrush="Transparent" HorizontalAlignment="Right" VerticalAlignment="Top" PreviewMouseDown="Refresh_PreviewMouseDown" >
<ContentControl>
<Image Height="20" Width="20" Source="refresh.png" />
</ContentControl>
</Button>

<Label Grid.Column="0" Grid.Row="5">Clock:</Label>
<ComboBox Name="Clock" Grid.Column="1" Grid.Row="5"
Expand All @@ -78,12 +93,21 @@
</ComboBox>

<Label Grid.Column="0" Grid.Row="6" >Show UTC:</Label>
<CheckBox Grid.Column="1" Grid.Row="6" HorizontalAlignment="Left" Name="ShowUTC" VerticalAlignment="Center" Checked="ShowUTC_Checked" Unchecked="ShowUTC_Unchecked"></CheckBox>
<CheckBox Grid.Column="1" Grid.Row="6" HorizontalAlignment="Left" Name="ShowUTC" VerticalAlignment="Center" IsChecked="{Binding Source={x:Static local:Properties.Settings.Default}, Path=UTCDetails, Mode=TwoWay}" Checked="ShowUTC_Checked" Unchecked="ShowUTC_Unchecked"></CheckBox>

<Label Grid.Column="0" Grid.Row="7">Style:</Label>
<RadioButton Grid.Column="1" Grid.Row="7" x:Name = "AlwaysOnTop" Content = "Always on Top" HorizontalAlignment = "Left"
Margin = "0,5,0,0" VerticalAlignment = "Top" IsChecked="{Binding Source={x:Static local:Properties.Settings.Default}, Path=BackgroundStyle, Mode=TwoWay, Converter={StaticResource InverseBoolRadioConverter}}" Checked="AlwaysOnTop_Checked"
GroupName = "WindowStyle" Width = "100" />

<RadioButton Grid.Column="1" Grid.Row="7" x:Name = "AlwaysInBackground" Content = "In background" HorizontalAlignment = "Left"
Margin = "150,5,0,0" VerticalAlignment = "Top"
GroupName = "WindowStyle" Width = "100" IsChecked="{Binding Source={x:Static local:Properties.Settings.Default}, Path=BackgroundStyle, Mode=TwoWay, Converter={StaticResource BoolRadioConverter}}" Checked="AlwaysInBackground_Checked"/>

<Label Grid.Column="0" Grid.Row="7" Name="TransparencyLabel" Visibility="Collapsed">Opacity:</Label>
<Slider Grid.Column="1" Grid.Row="7" Maximum="255" Minimum="0" Width="200" HorizontalAlignment="Left" Name="Transparency" Visibility="Collapsed" ValueChanged="Transparency_ValueChanged" ></Slider>
<Label Grid.Column="0" Grid.Row="8" Name="TransparencyLabel" Visibility="Collapsed">Opacity:</Label>
<Slider Grid.Column="1" Grid.Row="8" Maximum="255" Minimum="0" Width="200" HorizontalAlignment="Left" Name="Transparency" Visibility="Collapsed" ValueChanged="Transparency_ValueChanged" ></Slider>

<Label Grid.Column="0" Grid.Row="8" Margin="0,40,0,0">Status:</Label>
<Label Grid.Column="1" Grid.Row="8" Margin="0,40,0,0" Name="Status">Waiting for input</Label>
<Label Grid.Column="0" Grid.Row="9" Margin="0,40,0,0">Status:</Label>
<Label Grid.Column="1" Grid.Row="9" Margin="0,40,0,0" Name="Status">Waiting for input</Label>
</Grid >
</Window>
60 changes: 58 additions & 2 deletions Config.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -14,7 +15,7 @@
using System.Windows.Shapes;
using System.Windows.Threading;

namespace ChainTime
namespace BlockClocksWindows
{
/// <summary>
/// Interaction logic for Config.xaml
Expand All @@ -30,7 +31,9 @@ public Config()
Instance = this;
InitializeComponent();
Topmost = true;


Deactivated += Window_Deactivated;

Clock.DataContext = MainWindow.Instance;
WalletAddress.DataContext = MainWindow.Instance;

Expand Down Expand Up @@ -268,5 +271,58 @@ private void ShowUTC_Unchecked(object sender, RoutedEventArgs e)

MainWindow.Instance.UpdateClock();
}

private void Refresh_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
FindNFTs();
}

private void AlwaysOnTop_Checked(object sender, RoutedEventArgs e)
{
MainWindow.Instance.SetToForeground();
}

private void AlwaysInBackground_Checked(object sender, RoutedEventArgs e)
{
MainWindow.Instance.SetToBackground();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.Activate();
this.Topmost = false;
this.Topmost = true;
this.Focus();
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
MainWindow.Instance.Topmost = true;
}
}

public class BoolRadioConverter : IValueConverter
{
public bool Inverse { get; set; }

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool boolValue = (bool)value;

return this.Inverse ? !boolValue : boolValue;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
bool boolValue = (bool)value;

if (!boolValue)
{
// We only care when the user clicks a radio button to select it.
return null;
}

return !this.Inverse;
}
}
}
4 changes: 2 additions & 2 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="ChainTime.MainWindow"
<Window x:Class="BlockClocksWindows.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -7,7 +7,7 @@
xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
mc:Ignorable="d"
Closing="Window_Closing"
KeyUp="Window_KeyUp"
KeyUp="Window_KeyUp"
Title="MainWindow" Height="450" Width="450" WindowStyle="None" AllowsTransparency="True">
<Window.Background>
<SolidColorBrush Color="White" Opacity="0"/>
Expand Down
68 changes: 59 additions & 9 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using CefSharp;
using BlockClocksWindows;
using CefSharp;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Timers;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;

namespace ChainTime
namespace BlockClocksWindows
{
/// <summary>
/// Interaction logic for MainWindow.xaml
Expand All @@ -25,7 +28,9 @@ public partial class MainWindow : Window
public List<clockassetcontents> Clocks { get; set; } = new List<clockassetcontents>();
public string LinkedAddress { get; set; }
public int ClockOpacity { get; set; }
public bool ConfigShown { get; set; }
public bool ConfigShown { get; set; }
public BlockClocksWindows.WindowSinker WS { get; set; }


public MainWindow()
{
Expand Down Expand Up @@ -68,8 +73,30 @@ public MainWindow()
}

PositionClock();

//WS = new BlockClocksWindows.WindowSinker(this);

this.SourceInitialized += new EventHandler(OnSourceInitialized);

if (Properties.Settings.Default.BackgroundStyle)
{
SetToBackground();
}
}

public void SetToBackground()
{
WS = new BlockClocksWindows.WindowSinker(this);
}

public void SetToForeground()
{
if (WS != null)
{
WS.DisableSinker();
WS.Dispose();
}
this.Focus();
}

private void Window_KeyUp(object sender, KeyEventArgs e)
Expand All @@ -88,7 +115,10 @@ private void Window_KeyUp(object sender, KeyEventArgs e)

private void PositionClock()
{
if (Properties.Settings.Default.Height == 0)
if (Properties.Settings.Default.Top <= 0 ||
Properties.Settings.Default.Left <= 0 ||
Properties.Settings.Default.Height <= 0 ||
Properties.Settings.Default.Width <= 0)
{
Properties.Settings.Default.Left = System.Windows.SystemParameters.PrimaryScreenHeight / 4;
Properties.Settings.Default.Top = System.Windows.SystemParameters.PrimaryScreenHeight / 4;
Expand Down Expand Up @@ -177,8 +207,8 @@ private void TimerHover_Elapsed(object sender, ElapsedEventArgs e)
private void Window_Deactivated(object sender, EventArgs e)
{
// The Window was deactivated
Topmost = false; // set topmost false first
Topmost = true; // then set topmost true again.
//Topmost = false; // set topmost false first
//Topmost = true; // then set topmost true again.
}

private void Window_MouseDown(object sender, MouseButtonEventArgs e)
Expand All @@ -198,7 +228,7 @@ private void Minus_Click(object sender, RoutedEventArgs e)
timer.AutoReset = true;
timer.Elapsed += Timer_Elapsed_Minus;
timer.Start();
Timer_Elapsed_Minus(sender, null);
Timer_Elapsed_Minus(sender, null);
}

private void Timer_Elapsed_Minus(object sender, ElapsedEventArgs e)
Expand Down Expand Up @@ -231,15 +261,16 @@ private void Timer_Elapsed_Plus(object sender, ElapsedEventArgs e)
}

private void Config_Click(object sender, MouseButtonEventArgs e)
{
{
ShowConfig();
}

private void ShowConfig()
{
Topmost = false;
ConfigShown = true;
Config ConfigDialog = new Config();
ConfigDialog.Show();
ConfigDialog.Show();
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
Expand All @@ -256,5 +287,24 @@ private void Quit_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
System.Windows.Application.Current.Shutdown();
}

private void OnSourceInitialized(object sender, EventArgs e)
{
HwndSource source = (HwndSource)PresentationSource.FromVisual(this);
source.AddHook(new HwndSourceHook(HandleMessages));
}

private IntPtr HandleMessages(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// 0x0112 == WM_SYSCOMMAND, 'Window' command message.
// 0xF020 == SC_MINIMIZE, command to minimize the window.
if (msg == 0x0112 && ((int)wParam & 0xFFF0) == 0xF020)
{
// Cancel the minimize.
handled = true;
}

return IntPtr.Zero;
}
}
}
14 changes: 13 additions & 1 deletion Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="ChainTime.Properties" GeneratedClassName="Settings">
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="BlockClocksWindows.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="Clocks" Type="System.String" Scope="User">
Expand Down Expand Up @@ -29,5 +29,8 @@
<Setting Name="UTCDetails" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="BackgroundStyle" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit 5a816a9

Please sign in to comment.