Implement queue management UI and app upload for eto

This commit is contained in:
JFronny 2021-02-14 16:29:09 +01:00
parent 531a1c1e34
commit 2fe4fa4592
11 changed files with 159 additions and 24 deletions

View File

@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Eto.Drawing;
using Eto.Forms;
using UpToolEto.Forms;
using UpToolLib.DataStructures;
using UpToolLib.v2;
using UpToolLib.v2.TaskQueue;
@ -9,9 +12,12 @@ namespace UpToolEto.Controls
{
public class AppControls : StackLayout
{
private readonly IList<AppTask> _tasks;
private readonly List<AppControlButton> _buttons;
public AppControls(TaskFactory factory, IList<AppTask> tasks)
private readonly Button _applyButton;
public AppControls(TaskFactory factory, IList<AppTask> tasks, IExternalFunctionality platform, Action update)
{
_tasks = tasks;
_buttons = new List<AppControlButton>
{
new AppControlButton<InstallTask>("Install", factory.CreateInstall, tasks, ReloadState,
@ -21,7 +27,37 @@ namespace UpToolEto.Controls
new AppControlButton<RemoveTask>("Remove", factory.CreateRemove, tasks, ReloadState,
app => app.Status.Contains(Status.Installed))
};
_applyButton = new Button((_, _) =>
{
try
{
QueueOverview overview = new(tasks);
overview.ShowModal();
if (!overview.Cancelled)
{
foreach (AppTask task in overview.TasksResulting)
{
task.Run();
_tasks.RemoveAt(0);
}
}
}
catch (Exception e)
{
platform.OkDialog("Failed to complete queue:\r\n" + e);
}
finally
{
ReloadState();
update();
}
})
{
Text = "Apply",
Enabled = false
};
foreach (AppControlButton button in _buttons) Items.Add(button);
Items.Add(new StackLayoutItem(_applyButton, HorizontalAlignment.Right));
if (Main.DebugColors)
BackgroundColor = Colors.Yellow;
Orientation = Orientation.Horizontal;
@ -29,20 +65,19 @@ namespace UpToolEto.Controls
public void SetApp(App app)
{
Visible = true;
foreach (AppControlButton button in _buttons) button.SetApp(app);
ReloadState();
}
public void Clear()
{
Visible = false;
foreach (AppControlButton button in _buttons) button.Clear();
}
private void ReloadState()
{
foreach (AppControlButton button in _buttons) button.ReloadState();
_applyButton.Enabled = _tasks.Any();
}
}
}

View File

@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Eto.Drawing;
using Eto.Forms;
using UpToolEto.Forms;
using UpToolLib.v1.Tool;
using UpToolLib.v2;
using UpToolLib.v2.TaskQueue;
namespace UpToolEto.Controls
{
@ -14,7 +17,7 @@ namespace UpToolEto.Controls
private readonly StackLayout _layout;
private readonly AppListSearchProvider _searchProvider;
public AppList(AppExtras extras, Action<Guid, App> itemClickEvent, bool online)
public AppList(AppExtras extras, Action<Guid, App> itemClickEvent, bool online, TaskFactory factory, IList<AppTask> tasks)
{
_extras = extras;
_itemClickEvent = itemClickEvent;

View File

@ -3,7 +3,6 @@ using Eto.Forms;
using UpToolLib.DataStructures;
using UpToolLib.v2;
//TODO implement
namespace UpToolEto.Controls
{
public class AppListSearchProvider : StackLayout
@ -11,6 +10,7 @@ namespace UpToolEto.Controls
private readonly bool _online;
private readonly TextBox _search;
private readonly EnumDropDown<Status> _state;
public AppListSearchProvider(bool online, Action refresh)
{
_online = online;

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Eto.Drawing;
using Eto.Forms;
@ -14,12 +15,26 @@ namespace UpToolEto.Controls
private readonly Label _appDescriptionLabel;
private readonly AppControls _appControls;
private App _app;
public AppPanel(TaskFactory factory, AppExtras extras, IList<AppTask> tasks)
public AppPanel(TaskFactory factory, AppExtras extras, IList<AppTask> tasks, IExternalFunctionality platform, Action updateAppList)
{
_appDescriptionLabel = new Label();
_appNameLabel = new Button((_, _) => extras.RunApp(_app));
_appNameLabel = new Button((_, _) =>
{
try
{
extras.RunApp(_app);
}
catch (Exception e)
{
platform.OkDialog("Failed to start\r\n" + e);
}
});
_appNameLabel.Font = new Font(_appNameLabel.Font.Family, _appNameLabel.Font.Size * 2);
_appControls = new AppControls(factory, tasks);
_appControls = new AppControls(factory, tasks, platform, () =>
{
updateAppList();
SetApp(_app);
});
Content = new StackLayout
{
Items =

View File

@ -1,13 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using Eto.Forms;
using UpToolEto.Forms;
using UpToolLib.DataStructures;
using UpToolLib.v2;
using UpToolLib.v2.TaskQueue;
namespace UpToolEto.Controls
{
public class UTMenuBar : MenuBar
{
public UTMenuBar(MainForm mainForm, RepoManagement repoManagement, AppList appList, IExternalFunctionality platform)
public UTMenuBar(MainForm mainForm, RepoManagement repoManagement, TaskFactory factory, IList<AppTask> tasks, AppList appList, IExternalFunctionality platform)
{
Command reloadRepos = new() {MenuText = "Reload", ToolBarText = "Reload"};
reloadRepos.Executed += (_, _) =>
@ -20,8 +23,23 @@ namespace UpToolEto.Controls
}
};
Command openSettings = new() {MenuText = "Sources", ToolBarText = "Sources"};
openSettings.Executed += (_, _) => new RepoForm(repoManagement).Show();
Command editSources = new() {MenuText = "Sources", ToolBarText = "Sources"};
editSources.Executed += (_, _) => new RepoForm(repoManagement).ShowModal();
Command addPackage = new() {MenuText = "Add Package", ToolBarText = "Add Package"};
addPackage.Executed += (_, _) =>
{
OpenFileDialog dialog = new() {MultiSelect = false, CheckFileExists = true, Filters = { new FileFilter("App package", ".zip")}};
if (dialog.ShowDialog(mainForm) == DialogResult.Ok)
{
if (!tasks.Any(s => s is UploadTask t && t.ZipFile == dialog.FileName))
{
StringDialog sd = new("Package name") {Text = "New package"};
sd.ShowModal();
tasks.Add(factory.CreateUpload(dialog.FileName, sd.Text));
}
}
};
Command quitCommand = new() {MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q};
quitCommand.Executed += (_, _) => Application.Instance.Quit();
@ -34,7 +52,8 @@ namespace UpToolEto.Controls
Text = "&File", Items =
{
reloadRepos,
openSettings
editSources,
addPackage
}
});
// File submenu

View File

@ -7,7 +7,7 @@ using UpToolLib.DataStructures;
namespace UpToolEto.Forms
{
public class DownloadDialog : Form
public class DownloadDialog : Dialog
{
private readonly Uri _url;
private readonly Application _application;
@ -47,12 +47,11 @@ namespace UpToolEto.Forms
try
{
WebClient client = new();
client.DownloadProgressChanged += (_, args) =>
client.DownloadProgressChanged += (_, args) => _application.Invoke(() =>
{
_platform.Log($"{args.BytesReceived}/{args.TotalBytesToReceive}");
_application.Invoke(() => _bar.Value = args.ProgressPercentage);
_bar.Value = args.ProgressPercentage;
_application.RunIteration();
};
});
client.DownloadDataCompleted += (_, args) =>
{
CurrentState = State.Success;

View File

@ -6,8 +6,6 @@ using UpToolLib;
using UpToolLib.DataStructures;
using UpToolLib.v2.TaskQueue;
//TODO implement tasks queue UI and add control to execute queue, also needs to clear AppPanel and reload AppList
//TODO add control_upload
namespace UpToolEto.Forms
{
public partial class MainForm : Form
@ -19,8 +17,8 @@ namespace UpToolEto.Forms
_tasks = new List<AppTask>();
Title = "UpTool2";
MinimumSize = new Size(600, 100);
AppList appList = new(lib.V1.AppExtras, (_, app) => _appPanel.SetApp(app), online);
_appPanel = new AppPanel(lib.V2.TaskFactory, lib.V1.AppExtras, _tasks);
AppList appList = new(lib.V1.AppExtras, (_, app) => _appPanel.SetApp(app), online, lib.V2.TaskFactory, _tasks);
_appPanel = new AppPanel(lib.V2.TaskFactory, lib.V1.AppExtras, _tasks, platform, appList.Update);
Content = new StackLayout
{
@ -32,7 +30,7 @@ namespace UpToolEto.Forms
},
Orientation = Orientation.Horizontal
};
Menu = new UTMenuBar(this, lib.V2.RepoManagement, appList, platform);
Menu = new UTMenuBar(this, lib.V2.RepoManagement, lib.V2.TaskFactory, _tasks, appList, platform);
Shown += (_, _) => init.Close();
}
}

View File

@ -0,0 +1,46 @@
using System.Collections.Generic;
using System.Linq;
using Eto.Forms;
using UpToolLib.v2.TaskQueue;
namespace UpToolEto.Forms
{
public class QueueOverview : Dialog
{
private readonly IList<AppTask> _tasks;
public bool Cancelled;
CheckBoxList cbl;
public List<AppTask> TasksResulting => cbl.SelectedValues.Select(s => (AppTask) s).ToList();
public QueueOverview(IList<AppTask> tasks)
{
_tasks = tasks;
StackLayout layout = new();
layout.Items.Add(new StackLayoutItem(new StackLayout()
{
Items =
{
new StackLayoutItem(new Button((_, _) =>
{
Cancelled = true;
Close();
})
{
Text = "Cancel"
}, HorizontalAlignment.Stretch),
new StackLayoutItem(new Button((_, _) =>
{
Close();
})
{
Text = "OK"
}, HorizontalAlignment.Stretch)
},
Orientation = Orientation.Horizontal
}, HorizontalAlignment.Stretch));
cbl = new CheckBoxList {DataStore = tasks, SelectedValues = tasks};
layout.Items.Add(cbl);
Content = layout;
}
}
}

View File

@ -7,7 +7,7 @@ using UpToolLib.v2;
namespace UpToolEto.Forms
{
public class RepoForm : Form
public class RepoForm : Dialog
{
private readonly RepoManagement _management;
private List<Repo> _repos = new();

View File

@ -0,0 +1,20 @@
using Eto.Forms;
namespace UpToolEto.Forms
{
public class StringDialog : Dialog
{
private readonly TextBox _tb;
public string Text
{
get => _tb.Text;
set => _tb.Text = value;
}
public StringDialog(string title)
{
_tb = new TextBox();
Content = _tb;
Title = title;
}
}
}

View File

@ -17,7 +17,7 @@ namespace UpToolEto
public Tuple<bool, byte[]> Download(Uri link)
{
DownloadDialog dlg = new(link, _application, this);
_application.AsyncInvoke(() => dlg.Show());
_application.AsyncInvoke(() => dlg.ShowModal());
dlg.StartDownload();
Log("Downloading " + link);
while (dlg.CurrentState == DownloadDialog.State.Downloading) Thread.Sleep(20);