Skip to content

Commit 12aa391

Browse files
committed
feat(Avalonia): add Database viewer
1 parent fc9efe9 commit 12aa391

File tree

4 files changed

+387
-16
lines changed

4 files changed

+387
-16
lines changed

SnapX.Avalonia/App.axaml.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using CommunityToolkit.Mvvm.Messaging;
1818
using FluentAvalonia.UI.Controls;
1919
using FluentAvalonia.UI.Windowing;
20+
using Microsoft.Data.Sqlite;
2021
using Microsoft.Extensions.DependencyInjection;
2122
using Serilog;
2223
using SnapX.Avalonia.ViewModels;
@@ -239,9 +240,9 @@ private async void OnReportErrorClicked(Button button, Exception ex)
239240

240241
try
241242
{
242-
if (!FeatureFlags.DisableTelemetry && Core.SnapX.TelemetryHandler is null)
243+
if (!FeatureFlags.DisableTelemetry && Core.SnapXL.TelemetryHandler is null)
243244
{
244-
Core.SnapX.InitTelemetryServices();
245+
Core.SnapXL.InitTelemetryServices();
245246
SentrySdk.CaptureException(ex);
246247

247248
DebugHelper.WriteLine("Error reported to Sentry successfully.");
@@ -312,8 +313,8 @@ private void Shutdown()
312313

313314
public void ListenForEvents()
314315
{
315-
Core.SnapX.EventAggregator.Subscribe<NeedClipboardCopyEvent>(HandleClipboardCopyEvent);
316-
Core.SnapX.EventAggregator.Subscribe<ErrorMessageEvent>(HandleErrorMessageEvent);
316+
Core.SnapXL.EventAggregator.Subscribe<NeedClipboardCopyEvent>(HandleClipboardCopyEvent);
317+
Core.SnapXL.EventAggregator.Subscribe<ErrorMessageEvent>(HandleErrorMessageEvent);
317318
}
318319

319320
private async void HandleClipboardCopyEvent(NeedClipboardCopyEvent @event)
@@ -489,7 +490,7 @@ private static async Task<IClipboard> GetOrCreateClipboardWindowAsync()
489490
CancellationTokenSource? _pollingCts = null;
490491

491492
// ReSharper disable once AsyncVoidMethod
492-
public override async void OnFrameworkInitializationCompleted()
493+
public override void OnFrameworkInitializationCompleted()
493494
{
494495
// Crashes must be contained, AT ALL COSTS!
495496
Dispatcher.UIThread.UnhandledException += (s, e) =>
@@ -562,7 +563,7 @@ public override async void OnFrameworkInitializationCompleted()
562563
{
563564
SnapX.start(desktop.Args ?? []);
564565
var CLIManager = SnapX.GetCLIManager();
565-
await CLIManager.UseCommandLineArgs();
566+
CLIManager.UseCommandLineArgs().GetAwaiter().GetResult();
566567
}
567568
catch (Exception ex)
568569
{
@@ -584,7 +585,7 @@ public override async void OnFrameworkInitializationCompleted()
584585
var trayIcon = new TrayIcon
585586
{
586587
Icon = new WindowIcon(logoBitmap),
587-
ToolTipText = Core.SnapX.AppName,
588+
ToolTipText = Core.SnapXL.AppName,
588589
Command = OpenSnapXCommand
589590
};
590591

@@ -777,7 +778,7 @@ void PopulateMonitorMenu(NativeMenu menu)
777778
var uploadFile = new NativeMenuItem("Upload File...");
778779
uploadFile.Click += (_, _) =>
779780
{
780-
Core.SnapX.EventAggregator.Publish(
781+
Core.SnapXL.EventAggregator.Publish(
781782
new NeedFileOpenerEvent
782783
{
783784
Title = "SnapX | Upload File",
@@ -788,7 +789,7 @@ void PopulateMonitorMenu(NativeMenu menu)
788789
var uploadFolder = new NativeMenuItem("Upload Folder...");
789790
uploadFolder.Click += (_, _) =>
790791
{
791-
Core.SnapX.EventAggregator.Publish(
792+
Core.SnapXL.EventAggregator.Publish(
792793
new NeedFileOpenerEvent
793794
{
794795
Title = "SnapX | Upload Folder",
@@ -990,7 +991,11 @@ public static void ConfigureServices(IServiceCollection services)
990991
services.AddTransient<ImportExportView>();
991992
// services.AddSingleton<ScreenRecordOptionsVM>();
992993
// services.AddTransient<ScreenRecordOptionsView>();
993-
994+
services.AddSingleton<CoreUploaderVM>();
995+
services.AddTransient<BuiltInUploaderSettingsView>();
996+
services.AddSingleton<DatabaseVM>();
997+
services.AddSingleton<SqliteConnection>(sp => SnapX.GetDB());
998+
services.AddTransient<DatabaseView>();
994999
services.AddTransient<SettingsHomePageView>();
9951000
services.AddSingleton<SettingsHomePageViewVM>();
9961001

SnapX.Avalonia/SnapX.Avalonia.csproj

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
1111
<BuiltInComInteropSupport>false</BuiltInComInteropSupport>
1212
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
13-
<AvaloniaVersion>11.3.11</AvaloniaVersion>
13+
<InterceptorsNamespaces>$(InterceptorsNamespaces);Dapper.AOT</InterceptorsNamespaces>
14+
<AvaloniaVersion>11.3.12</AvaloniaVersion>
1415
<SkiaSharpVersion>3.119.1</SkiaSharpVersion>
1516
<HarfBuzzSharpVersion>8.3.1.2</HarfBuzzSharpVersion>
1617
<ApplicationManifest>app.manifest</ApplicationManifest>
@@ -52,7 +53,7 @@
5253
<PackageReference Condition="!$(RuntimeIdentifier.Contains('browser'))" Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
5354
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="$(AvaloniaVersion)" />
5455
<PackageReference Include="FluentAvaloniaUI" Version="2.5.0" />
55-
<PackageReference Include="FluentIcons.Avalonia.Fluent" Version="2.0.317" />
56+
<PackageReference Include="FluentIcons.Avalonia.Fluent" Version="2.0.318" />
5657
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
5758
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
5859
<PackageReference Include="HarfBuzzSharp" Version="$(HarfBuzzSharpVersion)" />
@@ -85,8 +86,4 @@
8586
<PackageReference Remove="HarfBuzzSharp.NativeAssets.Win32" />
8687
<PackageReference Remove="HarfBuzzSharp.NativeAssets.WebAssembly" />
8788
</ItemGroup>
88-
<ItemGroup>
89-
<Folder Include="Controls\" />
90-
<Folder Include="Services\" />
91-
</ItemGroup>
9289
</Project>
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
<UserControl
2+
Initialized="StyledElement_OnInitialized"
3+
d:DesignHeight="450"
4+
d:DesignWidth="800"
5+
mc:Ignorable="d"
6+
x:Class="SnapX.Avalonia.Views.Settings.Views.DatabaseView"
7+
x:DataType="viewModels:DatabaseVM"
8+
xmlns="https://github.com/avaloniaui"
9+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
10+
xmlns:fluent="clr-namespace:FluentIcons.Avalonia.Fluent;assembly=FluentIcons.Avalonia.Fluent"
11+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
12+
xmlns:viewModels="clr-namespace:SnapX.Avalonia.ViewModels"
13+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
14+
<Design.DataContext>
15+
<viewModels:DatabaseVM />
16+
</Design.DataContext>
17+
<Grid RowDefinitions="Auto, *">
18+
<Border
19+
Background="{DynamicResource SolidBackgroundFillColorBaseBrush}"
20+
BorderBrush="{DynamicResource CardStrokeColorDefaultBrush}"
21+
BorderThickness="0,0,0,1"
22+
Grid.Row="0"
23+
Padding="12">
24+
<Grid ColumnDefinitions="*, Auto">
25+
<StackPanel Orientation="Horizontal" Spacing="8">
26+
<TextBox
27+
Text="{Binding SearchText, Mode=TwoWay}"
28+
Watermark="Search database..."
29+
Width="300">
30+
<TextBox.InnerLeftContent>
31+
<fluent:SymbolIcon
32+
FontSize="16"
33+
Margin="8,0,0,0"
34+
Symbol="Search" />
35+
</TextBox.InnerLeftContent>
36+
</TextBox>
37+
<Separator Classes="Vertical" />
38+
<TextBlock Text="{Binding TotalCount, StringFormat='{}{0} Records'}" VerticalAlignment="Center" />
39+
</StackPanel>
40+
41+
<StackPanel
42+
Grid.Column="1"
43+
Orientation="Horizontal"
44+
Spacing="8">
45+
<Button Classes="accent" Command="{Binding RefreshCommand}">
46+
<StackPanel Orientation="Horizontal" Spacing="8">
47+
<fluent:SymbolIcon Symbol="ArrowCounterclockwise" />
48+
<TextBlock Text="Refresh" />
49+
</StackPanel>
50+
</Button>
51+
<ComboBox
52+
ItemsSource="{Binding Tables}"
53+
SelectedItem="{Binding SelectedTable}"
54+
VerticalAlignment="Center"
55+
Width="150">
56+
<ComboBox.SelectionBoxItemTemplate>
57+
<DataTemplate>
58+
<StackPanel Orientation="Horizontal" Spacing="8">
59+
<fluent:SymbolIcon FontSize="16" Symbol="Table" />
60+
<TextBlock Text="{Binding}" VerticalAlignment="Center" />
61+
</StackPanel>
62+
</DataTemplate>
63+
</ComboBox.SelectionBoxItemTemplate>
64+
<ComboBox.ItemTemplate>
65+
<DataTemplate>
66+
<StackPanel Orientation="Horizontal" Spacing="8">
67+
<fluent:SymbolIcon FontSize="16" Symbol="Table" />
68+
<TextBlock Text="{Binding}" VerticalAlignment="Center" />
69+
</StackPanel>
70+
</DataTemplate>
71+
</ComboBox.ItemTemplate>
72+
</ComboBox>
73+
<DropDownButton Content="Quick Actions">
74+
<DropDownButton.Flyout>
75+
<MenuFlyout Placement="BottomEdgeAlignedRight">
76+
<MenuItem Command="{Binding ChangePathCommand}" Header="Mass Change Screenshots Path">
77+
<MenuItem.Icon>
78+
<fluent:SymbolIcon Symbol="FolderLink" />
79+
</MenuItem.Icon>
80+
</MenuItem>
81+
<!-- <MenuItem Command="{Binding RebuildIndexCommand}" Header="Rebuild Index"> -->
82+
<!-- <MenuItem.Icon> -->
83+
<!-- <fluent:SymbolIcon Symbol="DatabaseLightning" /> -->
84+
<!-- </MenuItem.Icon> -->
85+
<!-- </MenuItem> -->
86+
<!-- <MenuItem Command="{Binding RebuildIndexCommand}" Header="Rebuild file paths"> -->
87+
<!-- <ToolTip.Tip> -->
88+
<!-- <StackPanel MaxWidth="300" Spacing="5"> -->
89+
<!-- <TextBlock FontWeight="Bold" Text="Repair Broken Links" /> -->
90+
<!-- <TextBlock Text="Scans your disks for missing or 0-byte files to restore database integrity." TextWrapping="Wrap" /> -->
91+
<!-- <Separator Margin="0,2" /> -->
92+
<!-- <TextBlock -->
93+
<!-- FontSize="11" -->
94+
<!-- Opacity="0.8" -->
95+
<!-- Text="• Defaults to searching your Home directory." /> -->
96+
<!-- <TextBlock -->
97+
<!-- FontSize="11" -->
98+
<!-- Opacity="0.8" -->
99+
<!-- Text="• You can select other disks or external drives." /> -->
100+
<!-- <TextBlock -->
101+
<!-- FontSize="11" -->
102+
<!-- FontWeight="SemiBold" -->
103+
<!-- Foreground="OrangeRed" -->
104+
<!-- Text="⚠️ Note: No backups are created during this process." /> -->
105+
<!-- </StackPanel> -->
106+
<!-- </ToolTip.Tip> -->
107+
<!-- <MenuItem.Icon> -->
108+
<!-- <fluent:SymbolIcon Symbol="DatabaseLink" /> -->
109+
<!-- </MenuItem.Icon> -->
110+
<!-- </MenuItem> -->
111+
<MenuItem
112+
Command="{Binding ExecuteRawSqlCommand}"
113+
CommandParameter="VACUUM;"
114+
Header="Vacuum Database">
115+
<MenuItem.Icon>
116+
<fluent:SymbolIcon Symbol="BroomSparkle" />
117+
</MenuItem.Icon>
118+
</MenuItem>
119+
<!-- <Separator /> -->
120+
<!-- <MenuItem Command="{Binding ExportCommand}" Header="Export to JSON"> -->
121+
<!-- <MenuItem.Icon> -->
122+
<!-- <fluent:SymbolIcon Symbol="ArrowExport" /> -->
123+
<!-- </MenuItem.Icon> -->
124+
<!-- </MenuItem> -->
125+
<!-- <MenuItem -->
126+
<!-- Command="{Binding PurgeCommand}" -->
127+
<!-- Foreground="{DynamicResource SystemFillColorCriticalBrush}" -->
128+
<!-- Header="Purge Missing Files"> -->
129+
<!-- <MenuItem.Icon> -->
130+
<!-- <fluent:SymbolIcon Symbol="Delete" /> -->
131+
<!-- </MenuItem.Icon> -->
132+
<!-- </MenuItem> -->
133+
</MenuFlyout>
134+
</DropDownButton.Flyout>
135+
</DropDownButton>
136+
</StackPanel>
137+
</Grid>
138+
</Border>
139+
<Grid Grid.Row="1">
140+
<DataGrid
141+
AutoGenerateColumns="False"
142+
GridLinesVisibility="All"
143+
ItemsSource="{Binding Items}"
144+
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
145+
x:Name="MainDataGrid" />
146+
147+
<StackPanel
148+
HorizontalAlignment="Right"
149+
Margin="24"
150+
VerticalAlignment="Bottom">
151+
152+
<Button
153+
Height="48"
154+
Padding="0"
155+
ToolTip.Tip="Open SQL Editor"
156+
Width="48">
157+
<Button.Flyout>
158+
<Flyout Placement="TopEdgeAlignedRight">
159+
<Border Padding="4" Width="500">
160+
<Grid ColumnDefinitions="*, Auto">
161+
<TextBox
162+
AcceptsReturn="True"
163+
FontFamily="Cascadia Code,Consolas,Monospace"
164+
Height="100"
165+
Text="{Binding RawSqlQuery}"
166+
Watermark="Enter SQL Query..." />
167+
<Button
168+
Command="{Binding ExecuteRawSqlCommand}"
169+
Grid.Column="1"
170+
Margin="10,0,0,0"
171+
VerticalAlignment="Stretch">
172+
<StackPanel Spacing="4">
173+
<fluent:SymbolIcon Symbol="Play" />
174+
<TextBlock Text="Run" />
175+
</StackPanel>
176+
</Button>
177+
</Grid>
178+
</Border>
179+
</Flyout>
180+
</Button.Flyout>
181+
182+
<fluent:SymbolIcon FontSize="24" Symbol="DatabaseSearch" />
183+
</Button>
184+
</StackPanel>
185+
</Grid>
186+
</Grid>
187+
</UserControl>

0 commit comments

Comments
 (0)