Linux compatability
This commit is contained in:
parent
fe6cfc899b
commit
683c221ca8
@ -11,11 +11,15 @@ using System.Threading.Tasks;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
|
using Dinah.Core;
|
||||||
|
|
||||||
namespace LibationAvalonia
|
namespace LibationAvalonia
|
||||||
{
|
{
|
||||||
public class App : Application
|
public class App : Application
|
||||||
{
|
{
|
||||||
|
public static bool IsWindows => PlatformID is PlatformID.Win32NT;
|
||||||
|
public static bool IsUnix => PlatformID is PlatformID.Unix;
|
||||||
|
|
||||||
public static readonly PlatformID PlatformID = Environment.OSVersion.Platform;
|
public static readonly PlatformID PlatformID = Environment.OSVersion.Platform;
|
||||||
public static IBrush ProcessQueueBookFailedBrush { get; private set; }
|
public static IBrush ProcessQueueBookFailedBrush { get; private set; }
|
||||||
public static IBrush ProcessQueueBookCompletedBrush { get; private set; }
|
public static IBrush ProcessQueueBookCompletedBrush { get; private set; }
|
||||||
@ -30,6 +34,30 @@ namespace LibationAvalonia
|
|||||||
=> AssetLoader.Open(new Uri(AssetUriBase, assetRelativePath));
|
=> AssetLoader.Open(new Uri(AssetUriBase, assetRelativePath));
|
||||||
|
|
||||||
|
|
||||||
|
public static bool GoToFile(string path)
|
||||||
|
=> PlatformID is PlatformID.Win32NT ? Go.To.File(path)
|
||||||
|
: GoToFolder(path is null ? string.Empty : Path.GetDirectoryName(path));
|
||||||
|
|
||||||
|
public static bool GoToFolder(string path)
|
||||||
|
{
|
||||||
|
if (PlatformID is PlatformID.Win32NT)
|
||||||
|
return Go.To.Folder(path);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var startInfo = new System.Diagnostics.ProcessStartInfo()
|
||||||
|
{
|
||||||
|
FileName = "/bin/xdg-open",
|
||||||
|
Arguments = path is null ? string.Empty : $"\"{System.IO.Path.GetDirectoryName(path)}\"",
|
||||||
|
UseShellExecute = false, //Import in Linux environments
|
||||||
|
CreateNoWindow = false,
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
RedirectStandardError = true
|
||||||
|
};
|
||||||
|
System.Diagnostics.Process.Start(startInfo);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
AvaloniaXamlLoader.Load(this);
|
AvaloniaXamlLoader.Load(this);
|
||||||
@ -162,6 +190,7 @@ namespace LibationAvalonia
|
|||||||
// if 'new user' was clicked, or if 'returning user' chose new install: show basic settings dialog
|
// if 'new user' was clicked, or if 'returning user' chose new install: show basic settings dialog
|
||||||
config.Books ??= Path.Combine(Configuration.UserProfile, "Books");
|
config.Books ??= Path.Combine(Configuration.UserProfile, "Books");
|
||||||
|
|
||||||
|
AppScaffolding.LibationScaffolding.PopulateMissingConfigValues(config);
|
||||||
return new SettingsDialog().ShowDialogSynchronously<DialogResult>(setupDialog) == DialogResult.OK
|
return new SettingsDialog().ShowDialogSynchronously<DialogResult>(setupDialog) == DialogResult.OK
|
||||||
&& config.LibationSettingsAreValid;
|
&& config.LibationSettingsAreValid;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,8 +49,11 @@ namespace LibationAvalonia.Dialogs
|
|||||||
|
|
||||||
SaveFileDialog saveFileDialog = new();
|
SaveFileDialog saveFileDialog = new();
|
||||||
saveFileDialog.Filters.Add(new FileDialogFilter { Name = "Jpeg", Extensions = new System.Collections.Generic.List<string>() { "jpg" } });
|
saveFileDialog.Filters.Add(new FileDialogFilter { Name = "Jpeg", Extensions = new System.Collections.Generic.List<string>() { "jpg" } });
|
||||||
saveFileDialog.Directory = Directory.Exists(BookSaveDirectory) ? BookSaveDirectory : Path.GetDirectoryName(BookSaveDirectory);
|
|
||||||
saveFileDialog.InitialFileName = PictureFileName;
|
saveFileDialog.InitialFileName = PictureFileName;
|
||||||
|
saveFileDialog.Directory
|
||||||
|
= App.IsUnix ? null
|
||||||
|
: Directory.Exists(BookSaveDirectory) ? BookSaveDirectory
|
||||||
|
: Path.GetDirectoryName(BookSaveDirectory);
|
||||||
|
|
||||||
var fileName = await saveFileDialog.ShowAsync(this);
|
var fileName = await saveFileDialog.ShowAsync(this);
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,7 @@ namespace LibationAvalonia.Dialogs
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Go.To.Folder(dir.ShortPathName);
|
App.GoToFolder(dir.ShortPathName);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@ -45,7 +45,7 @@ namespace LibationAvalonia.Dialogs
|
|||||||
|
|
||||||
public void OpenLogFolderButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
public void OpenLogFolderButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Go.To.Folder(((LongPath)Configuration.Instance.LibationFiles).ShortPathName);
|
App.GoToFolder(((LongPath)Configuration.Instance.LibationFiles).ShortPathName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void EditFolderTemplateButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
public async void EditFolderTemplateButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
|||||||
@ -150,6 +150,8 @@ Libation.
|
|||||||
|
|
||||||
private static DialogResult ShowCoreAsync(Window owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool saveAndRestorePosition = true)
|
private static DialogResult ShowCoreAsync(Window owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool saveAndRestorePosition = true)
|
||||||
{
|
{
|
||||||
|
owner ??= (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime).MainWindow;
|
||||||
|
|
||||||
var dialog = new MessageBoxWindow(saveAndRestorePosition);
|
var dialog = new MessageBoxWindow(saveAndRestorePosition);
|
||||||
|
|
||||||
dialog.HideMinMaxBtns();
|
dialog.HideMinMaxBtns();
|
||||||
@ -164,7 +166,7 @@ Libation.
|
|||||||
tbx.MinWidth = vm.TextBlockMinWidth;
|
tbx.MinWidth = vm.TextBlockMinWidth;
|
||||||
tbx.Text = message;
|
tbx.Text = message;
|
||||||
|
|
||||||
var thisScreen = (owner ?? dialog).Screens.ScreenFromVisual(owner ?? dialog);
|
var thisScreen = owner.Screens.ScreenFromVisual(owner);
|
||||||
|
|
||||||
var maxSize = new Size(0.20 * thisScreen.Bounds.Width, 0.9 * thisScreen.Bounds.Height - 55);
|
var maxSize = new Size(0.20 * thisScreen.Bounds.Width, 0.9 * thisScreen.Bounds.Height - 55);
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,8 @@ namespace LibationAvalonia.Views
|
|||||||
{
|
{
|
||||||
// liberated: open explorer to file
|
// liberated: open explorer to file
|
||||||
var filePath = AudibleFileStorage.Audio.GetPath(libraryBook.Book.AudibleProductId);
|
var filePath = AudibleFileStorage.Audio.GetPath(libraryBook.Book.AudibleProductId);
|
||||||
if (!Go.To.File(filePath?.ShortPathName))
|
|
||||||
|
if (!App.GoToFile(filePath?.ShortPathName))
|
||||||
{
|
{
|
||||||
var suffix = string.IsNullOrWhiteSpace(filePath) ? "" : $":\r\n{filePath}";
|
var suffix = string.IsNullOrWhiteSpace(filePath) ? "" : $":\r\n{filePath}";
|
||||||
MessageBox.Show($"File not found" + suffix);
|
MessageBox.Show($"File not found" + suffix);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user