Compare commits
8 commits
61c98f459b
...
7cf24025b6
| Author | SHA1 | Date | |
|---|---|---|---|
| 7cf24025b6 | |||
| 7ad03d2c17 | |||
| 480474c343 | |||
| 358539bfd5 | |||
| 14fae4b246 | |||
| 4c400c03b8 | |||
| c9c88358c3 | |||
| b63f32dd06 |
10 changed files with 58 additions and 9 deletions
|
|
@ -1,7 +1,9 @@
|
|||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sukiUi="clr-namespace:SukiUI;assembly=SukiUI"
|
||||
xmlns:vm="clr-namespace:FreeTubeSyncer.Models"
|
||||
x:Class="FreeTubeSyncer.App"
|
||||
x:DataType="vm:AppViewModel"
|
||||
RequestedThemeVariant="Dark">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
|
||||
|
|
@ -11,8 +13,8 @@
|
|||
|
||||
<TrayIcon.Icons>
|
||||
<TrayIcons>
|
||||
<TrayIcon Icon="/Assets/freetube.png"
|
||||
ToolTipText="FreeTube Syncer"
|
||||
<TrayIcon Icon="{Binding AppIcon}"
|
||||
ToolTipText="{Binding HintTooltip, Mode=TwoWay}"
|
||||
Clicked="TrayIcon_OnClicked">
|
||||
<TrayIcon.Menu>
|
||||
<NativeMenu>
|
||||
|
|
|
|||
|
|
@ -8,8 +8,11 @@ using System.Text.Json;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.Threading;
|
||||
using FreeTubeSyncer.Library;
|
||||
using FreeTubeSyncer.Models;
|
||||
using FreeTubeSyncer.Models.DatabaseModels;
|
||||
|
|
@ -39,13 +42,23 @@ public partial class App : Application
|
|||
private TimeSpan _checkInterval;
|
||||
private DateTime _lastUpdated;
|
||||
|
||||
private WindowIcon? _normalTrayIcon;
|
||||
private WindowIcon? _waitingTrayIcon;
|
||||
private WindowIcon? _completeTrayIcon;
|
||||
|
||||
public event EventHandler? SettingsChanged;
|
||||
|
||||
public static App GetApp() => (App)App.Current!;
|
||||
public static ClassicDesktopStyleApplicationLifetime GetDesktop() => (ClassicDesktopStyleApplicationLifetime)App.Current!.ApplicationLifetime!;
|
||||
public override void Initialize()
|
||||
{
|
||||
_normalTrayIcon = new WindowIcon(AssetLoader.Open(new Uri("avares://FreeTubeSyncer/Assets/freetubesyncer.64.png")));
|
||||
_waitingTrayIcon = new WindowIcon(AssetLoader.Open(new Uri("avares://FreeTubeSyncer/Assets/awaiting_sync.png")));
|
||||
_completeTrayIcon = new WindowIcon(AssetLoader.Open(new Uri("avares://FreeTubeSyncer/Assets/sync_complete.png")));
|
||||
var vm = new AppViewModel();
|
||||
vm.AppIcon = _normalTrayIcon;
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
DataContext = vm;
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
|
|
@ -159,6 +172,18 @@ public partial class App : Application
|
|||
Log.Information("Log Started.");
|
||||
}
|
||||
|
||||
private async Task UpdateSTIconHint(WindowIcon icon, string? hint = null)
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(async () =>
|
||||
{
|
||||
await _semaphoreSlim.WaitAsync();
|
||||
((AppViewModel)DataContext!).AppIcon = icon;
|
||||
if (hint != null) ((AppViewModel)DataContext).HintTooltip = hint;
|
||||
_semaphoreSlim.Release();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private async Task SyncMonitor()
|
||||
{
|
||||
Log.Information("Sync Monitor Starting Up.");
|
||||
|
|
@ -191,6 +216,11 @@ public partial class App : Application
|
|||
while (_isRunning)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
|
||||
if (_syncers.Any(x => x.IsDirty()))
|
||||
{
|
||||
await UpdateSTIconHint(_waitingTrayIcon!, "FreeTube Syncer - Changes waiting to be written...");
|
||||
}
|
||||
|
||||
var sinceLastCheck = DateTime.Now - lastCheck;
|
||||
if (sinceLastCheck.TotalSeconds > _checkInterval.TotalSeconds)
|
||||
|
|
@ -219,6 +249,7 @@ public partial class App : Application
|
|||
if (procs.Length > 0) continue;
|
||||
Log.Information("FreeTube instance closed, and we have writes to make...");
|
||||
await Task.Delay(1500);
|
||||
await UpdateSTIconHint(_waitingTrayIcon, "FreeTube Syncer - Syncing data...");
|
||||
|
||||
await _semaphoreSlim.WaitAsync();
|
||||
var syncStart = DateTime.Now;
|
||||
|
|
@ -227,6 +258,12 @@ public partial class App : Application
|
|||
var syncEnd = DateTime.Now - syncStart;
|
||||
_semaphoreSlim.Release();
|
||||
Log.Information("Sync Completed. Total Time: {EndTime}", syncEnd);
|
||||
await UpdateSTIconHint(_completeTrayIcon, "FreeTube Syncer - Sync completed.");
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(3000);
|
||||
await UpdateSTIconHint(_normalTrayIcon, "FreeTube Syncer - Watching files...");
|
||||
});
|
||||
}
|
||||
|
||||
Log.Information("Filesystem Sync Monitor shutdown.");
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.7 KiB |
BIN
FreeTubeSyncer/Assets/freetubesyncer.64.png
Normal file
BIN
FreeTubeSyncer/Assets/freetubesyncer.64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.7 KiB |
|
|
@ -34,7 +34,8 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\freetube.png" />
|
||||
<AvaloniaXaml Include="Assets\freetube.png" />
|
||||
<AvaloniaResource Include="Assets\freetubesyncer.64.png"/>
|
||||
<AvaloniaResource Include="Assets\awaiting_sync.png"/>
|
||||
<AvaloniaResource Include="Assets\sync_complete.png"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -36,10 +36,7 @@ public class DBSyncWatcher
|
|||
{
|
||||
if (e.ChangeType != WatcherChangeTypes.Changed) return;
|
||||
|
||||
while (Locked)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
if (Locked) return;
|
||||
|
||||
var dbName = Path.GetFileName(e.FullPath);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
Width="400" Height="345"
|
||||
x:Class="FreeTubeSyncer.MainWindow"
|
||||
x:DataType="vm:AppSettings"
|
||||
Icon="/Assets/freetubesyncer.64.png"
|
||||
BackgroundStyle="GradientDarker"
|
||||
CanResize="False"
|
||||
CanMaximize="False"
|
||||
|
|
|
|||
10
FreeTubeSyncer/Models/AppViewModel.cs
Normal file
10
FreeTubeSyncer/Models/AppViewModel.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using Avalonia.Controls;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace FreeTubeSyncer.Models;
|
||||
|
||||
public partial class AppViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private WindowIcon? _appIcon;
|
||||
[ObservableProperty] private string _hintTooltip = "FreeTube Syncer";
|
||||
}
|
||||
|
|
@ -218,8 +218,9 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
|||
foreach (var line in json)
|
||||
fh.Write(Encoding.UTF8.GetBytes(line + "\n"));
|
||||
fh.Flush();
|
||||
fh.Close();
|
||||
}
|
||||
|
||||
Task.Delay(100).Wait();
|
||||
_watcher.Locked = false;
|
||||
Log.Information("Updated {DbName}, completed in {TimeSpan}", _dbName, DateTime.Now - start);
|
||||
_isDirty = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue