mirror of
https://github.com/tuxdotrs/highminded.git
synced 2025-08-23 08:01:03 +05:30
refactor: cleaup and implemented mvvm
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:iconPacks="https://github.com/MahApps/IconPacks.Avalonia"
|
||||
xmlns:vm="using:highminded.models"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="highminded.ui.windows.MainWindow"
|
||||
x:DataType="vm:MainViewModel"
|
||||
Title="highminded"
|
||||
Height="600"
|
||||
Width="800"
|
||||
@@ -18,10 +20,20 @@
|
||||
Foreground="#fff"
|
||||
TransparencyBackgroundFallback="Transparent"
|
||||
FontSize="16">
|
||||
|
||||
<Window.Styles>
|
||||
<Style Selector="Border.recording">
|
||||
<Setter Property="BorderBrush" Value="#19ffffff" />
|
||||
</Style>
|
||||
<Style Selector="Border.recording[IsVisible=True]">
|
||||
<Setter Property="BorderBrush" Value="#997ce87c" />
|
||||
</Style>
|
||||
</Window.Styles>
|
||||
|
||||
<Grid RowDefinitions="Auto,*" Margin="5" RowSpacing="10">
|
||||
<Border Grid.Row="0" CornerRadius="5" Background="Black" Opacity="0.8" PointerPressed="OnPointerPressed">
|
||||
<Grid ColumnDefinitions="*,Auto" Margin="15 10">
|
||||
<TextBlock Grid.Column="0" VerticalAlignment="Center" Margin="5">High Minded</TextBlock>
|
||||
<TextBlock Grid.Column="0" VerticalAlignment="Center" Margin="5" Text="{Binding AppName}" />
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center">
|
||||
<Border Background="Black" BorderBrush="#19ffffff" BorderThickness="2" CornerRadius="5"
|
||||
@@ -29,7 +41,7 @@
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Spacing="5" Margin="10 0">
|
||||
<TextBlock FontSize="12" Text="Hide:" />
|
||||
<TextBlock FontSize="12" Text="SHIFT + \" />
|
||||
<TextBlock FontSize="12" Text="{Binding HideShortcutKey}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Border Background="Black" BorderBrush="#19ffffff" BorderThickness="2" CornerRadius="5"
|
||||
@@ -37,16 +49,32 @@
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Spacing="5" Margin="10 0">
|
||||
<TextBlock FontSize="12" Text="Screen:" />
|
||||
<TextBlock FontSize="12" Text="SHIFT + S" />
|
||||
<TextBlock FontSize="12" Text="{Binding ScreenshotShortcutKey}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Border
|
||||
IsVisible="{Binding !IsRecording}"
|
||||
BorderBrush="#19ffffff"
|
||||
Background="Black"
|
||||
BorderThickness="2" CornerRadius="5"
|
||||
Margin="0 0 10 0">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Spacing="5" Margin="10 0">
|
||||
<TextBlock FontSize="12" Text="Audio:" />
|
||||
<TextBlock FontSize="12" Text="{Binding AudioShortcutKey}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Border
|
||||
IsVisible="{Binding IsRecording}"
|
||||
BorderBrush="#997ce87c"
|
||||
Background="Black"
|
||||
BorderThickness="2" CornerRadius="5"
|
||||
Margin="0 0 10 0">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Spacing="5" Margin="10 0">
|
||||
<TextBlock FontSize="12" Text="Audio:" />
|
||||
<TextBlock FontSize="12" Text="{Binding AudioShortcutKey}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Border Background="Black" BorderBrush="#19ffffff" BorderThickness="2" CornerRadius="5"
|
||||
Margin="0 0 10 0">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Spacing="5" Margin="10 0">
|
||||
<TextBlock FontSize="12" Text="Audio:" />
|
||||
<TextBlock FontSize="12" Text="SHIFT + A" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Button Name="ChatBtn" Background="Transparent" Click="ChatBtnClick">
|
||||
<iconPacks:PackIconLucide Grid.Column="1" Kind="Brain" Height="16" Width="16" />
|
||||
@@ -55,7 +83,7 @@
|
||||
<iconPacks:PackIconLucide Grid.Column="1" Kind="Settings" Height="16" Width="16" />
|
||||
</Button>
|
||||
<Button Name="HideBtn" Background="Transparent" Click="HideBtnClick">
|
||||
<iconPacks:PackIconLucide Grid.Column="1" Kind="X" Height="13" Width="13"/>
|
||||
<iconPacks:PackIconLucide Grid.Column="1" Kind="X" Height="13" Width="13" />
|
||||
</Button>
|
||||
|
||||
</StackPanel>
|
||||
|
@@ -6,6 +6,7 @@ using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using highminded.ui.controls;
|
||||
using highminded.utils;
|
||||
using SharpHook;
|
||||
using SharpHook.Data;
|
||||
|
||||
@@ -36,13 +37,14 @@ public partial class MainWindow : Window
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = InMemoryDb.Obj.MainViewModel;
|
||||
|
||||
UControl.Content = _chatUserControl;
|
||||
ChatBtnActive();
|
||||
HideOverlay();
|
||||
// Global Hotkey
|
||||
_hook.KeyPressed += OnKeyPressed;
|
||||
_hook.RunAsync();
|
||||
_chatUserControl.SendAudio();
|
||||
}
|
||||
|
||||
private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
@@ -74,56 +76,6 @@ public partial class MainWindow : Window
|
||||
SettingsBtn.Background = new SolidColorBrush(Color.FromArgb(25, 255, 255, 255));
|
||||
}
|
||||
|
||||
private void OnKeyPressed(object? sender, KeyboardHookEventArgs e)
|
||||
{
|
||||
bool hasCtrl = (e.RawEvent.Mask & EventMask.Ctrl) != EventMask.None;
|
||||
bool hasAlt = (e.RawEvent.Mask & EventMask.Alt) != EventMask.None;
|
||||
bool hasShift = (e.RawEvent.Mask & EventMask.Shift) != EventMask.None;
|
||||
bool hasH = e.Data.KeyCode == KeyCode.VcH;
|
||||
bool hasBackslash = e.Data.KeyCode == KeyCode.VcBackslash;
|
||||
bool hasA = e.Data.KeyCode == KeyCode.VcA;
|
||||
bool hasS = e.Data.KeyCode == KeyCode.VcS;
|
||||
bool hasQ = e.Data.KeyCode == KeyCode.VcQ;
|
||||
|
||||
if (hasCtrl && hasShift && hasAlt && hasH)
|
||||
{
|
||||
ShowOverlay();
|
||||
}
|
||||
|
||||
if (hasShift && hasS)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => { _chatUserControl.SendScreenshot(); });
|
||||
}
|
||||
|
||||
if (hasShift && hasA)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => { _chatUserControl.StartRecord(); });
|
||||
}
|
||||
|
||||
if (hasAlt && hasShift && hasQ)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => { Environment.Exit(0); });
|
||||
}
|
||||
|
||||
if (hasShift && hasBackslash)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (WindowState == WindowState.Minimized || !IsVisible)
|
||||
{
|
||||
Show();
|
||||
WindowState = WindowState.Normal;
|
||||
Activate();
|
||||
Topmost = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowOverlay()
|
||||
{
|
||||
var handle = TryGetPlatformHandle();
|
||||
@@ -188,4 +140,54 @@ public partial class MainWindow : Window
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void OnKeyPressed(object? sender, KeyboardHookEventArgs e)
|
||||
{
|
||||
bool hasCtrl = (e.RawEvent.Mask & EventMask.Ctrl) != EventMask.None;
|
||||
bool hasAlt = (e.RawEvent.Mask & EventMask.Alt) != EventMask.None;
|
||||
bool hasShift = (e.RawEvent.Mask & EventMask.Shift) != EventMask.None;
|
||||
bool hasH = e.Data.KeyCode == KeyCode.VcH;
|
||||
bool hasBackslash = e.Data.KeyCode == KeyCode.VcBackslash;
|
||||
bool hasA = e.Data.KeyCode == KeyCode.VcA;
|
||||
bool hasS = e.Data.KeyCode == KeyCode.VcS;
|
||||
bool hasQ = e.Data.KeyCode == KeyCode.VcQ;
|
||||
|
||||
if (hasCtrl && hasShift && hasAlt && hasH)
|
||||
{
|
||||
ShowOverlay();
|
||||
}
|
||||
|
||||
if (hasShift && hasS)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => { _chatUserControl.SendScreenshot(); });
|
||||
}
|
||||
|
||||
if (hasShift && hasA)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => { _chatUserControl.StartRecord(); });
|
||||
}
|
||||
|
||||
if (hasAlt && hasShift && hasQ)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => { Environment.Exit(0); });
|
||||
}
|
||||
|
||||
if (hasShift && hasBackslash)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (WindowState == WindowState.Minimized || !IsVisible)
|
||||
{
|
||||
Show();
|
||||
WindowState = WindowState.Normal;
|
||||
Activate();
|
||||
Topmost = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user