Updated App
Since we can't rely on Process.GetProcessByName() to work from within a sandboxed environment such as Flatpak, we instead rely on the SingletonCookie/SingletonLock/SingletonSocket to determine if the FreeTube Process is still running.
This commit is contained in:
parent
f66d672eb7
commit
b40786c02c
1 changed files with 21 additions and 18 deletions
|
|
@ -41,6 +41,7 @@ public partial class App : Application
|
|||
private static readonly SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(1, 1);
|
||||
private TimeSpan _checkInterval;
|
||||
private DateTime _lastUpdated;
|
||||
private string _freeTubeDataPath;
|
||||
|
||||
private WindowIcon? _normalTrayIcon;
|
||||
private WindowIcon? _waitingTrayIcon;
|
||||
|
|
@ -66,18 +67,18 @@ public partial class App : Application
|
|||
SetupLogger();
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var path = "";
|
||||
_freeTubeDataPath = "";
|
||||
if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
|
||||
path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FreeTube");
|
||||
_freeTubeDataPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FreeTube");
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config",
|
||||
_freeTubeDataPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config",
|
||||
"FreeTube");
|
||||
if (!Path.Exists(path))
|
||||
if (!Path.Exists(_freeTubeDataPath))
|
||||
{
|
||||
path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".var", "app", "io.freetubeapp.FreeTube", "config",
|
||||
_freeTubeDataPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".var", "app", "io.freetubeapp.FreeTube", "config",
|
||||
"FreeTube");
|
||||
if (!Path.Exists(path))
|
||||
if (!Path.Exists(_freeTubeDataPath))
|
||||
Log.Error("Failed to find Path for FreeTube!");
|
||||
}
|
||||
}
|
||||
|
|
@ -85,16 +86,16 @@ public partial class App : Application
|
|||
LoadSettings();
|
||||
_checkInterval = TimeSpan.FromSeconds(_settings!.CheckInterval);
|
||||
|
||||
_watcher = new DBSyncWatcher(path);
|
||||
_historySyncer = new Syncer<History>(_watcher, Path.Join(path, "history.db"), "history.db", _settings.RestBaseUrl, "/history");
|
||||
_watcher = new DBSyncWatcher(_freeTubeDataPath);
|
||||
_historySyncer = new Syncer<History>(_watcher, Path.Join(_freeTubeDataPath, "history.db"), "history.db", _settings.RestBaseUrl, "/history");
|
||||
_historySyncer.SetEnabled(_settings.SyncHistory);
|
||||
_playlistSyncer = new Syncer<Playlist>(_watcher, Path.Join(path, "playlists.db"), "playlists.db", _settings.RestBaseUrl, "/playlist");
|
||||
_playlistSyncer = new Syncer<Playlist>(_watcher, Path.Join(_freeTubeDataPath, "playlists.db"), "playlists.db", _settings.RestBaseUrl, "/playlist");
|
||||
_playlistSyncer.SetEnabled(_settings.SyncPlaylist);
|
||||
_profileSyncer = new Syncer<Profile>(_watcher, Path.Join(path, "profiles.db"), "profiles.db", _settings.RestBaseUrl, "/profile");
|
||||
_profileSyncer = new Syncer<Profile>(_watcher, Path.Join(_freeTubeDataPath, "profiles.db"), "profiles.db", _settings.RestBaseUrl, "/profile");
|
||||
_profileSyncer.SetEnabled(_settings.SyncProfile);
|
||||
_searchHistorySyncer = new Syncer<SearchHistory>(_watcher, Path.Join(path, "search-history.db"), "search-history.db", _settings.RestBaseUrl, "/searchHistory");
|
||||
_searchHistorySyncer = new Syncer<SearchHistory>(_watcher, Path.Join(_freeTubeDataPath, "search-history.db"), "search-history.db", _settings.RestBaseUrl, "/searchHistory");
|
||||
_searchHistorySyncer.SetEnabled(_settings.SyncSearchHistory);
|
||||
_settingSyncer = new Syncer<Setting>(_watcher, Path.Join(path, "settings.db"), "settings.db", _settings.RestBaseUrl, "/settings");
|
||||
_settingSyncer = new Syncer<Setting>(_watcher, Path.Join(_freeTubeDataPath, "settings.db"), "settings.db", _settings.RestBaseUrl, "/settings");
|
||||
_settingSyncer.SetEnabled(_settings.SyncSettings);
|
||||
_syncers =
|
||||
[
|
||||
|
|
@ -244,11 +245,13 @@ public partial class App : Application
|
|||
}
|
||||
|
||||
if (!_syncers.Any(x => x.IsDirty())) continue;
|
||||
|
||||
if (File.Exists(Path.Join(_freeTubeDataPath, "SingletonCookie")) ||
|
||||
File.Exists(Path.Join(_freeTubeDataPath, "SingletonLock")) ||
|
||||
File.Exists(Path.Join(_freeTubeDataPath, "SingletonSocket"))) continue;
|
||||
|
||||
var procs = Process.GetProcessesByName("FreeTube");
|
||||
if (procs.Length > 0) continue;
|
||||
Log.Information("FreeTube instance closed, and we have writes to make...");
|
||||
await Task.Delay(1500);
|
||||
await Task.Delay(2000);
|
||||
await UpdateSTIconHint(_waitingTrayIcon, "FreeTube Syncer - Syncing data...");
|
||||
|
||||
await _semaphoreSlim.WaitAsync();
|
||||
|
|
@ -339,13 +342,13 @@ public partial class App : Application
|
|||
desktop.MainWindow!.Show();
|
||||
}
|
||||
|
||||
private void Quit_OnClick(object? sender, EventArgs e)
|
||||
private async void Quit_OnClick(object? sender, EventArgs e)
|
||||
{
|
||||
if (App.Current!.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return;
|
||||
_semaphoreSlim.Wait();
|
||||
await _semaphoreSlim.WaitAsync();
|
||||
_isRunning = false;
|
||||
_semaphoreSlim.Release();
|
||||
_watcherTask?.Wait();
|
||||
await _watcherTask!;
|
||||
desktop.Shutdown();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue