Skip to content

Commit

Permalink
Implemented Inplace Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
berrnd committed Dec 7, 2024
1 parent 56f8067 commit 099e64c
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 34 deletions.
Binary file removed .github/publication_assets/actions.gif
Binary file not shown.
Binary file modified .github/publication_assets/edit-item.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/publication_assets/live-example.mp4
Binary file not shown.
Binary file modified .github/publication_assets/main-window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/publication_assets/tray-menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions Data/ActionItem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Xml.Serialization;
Expand All @@ -6,6 +7,11 @@ namespace Traything.Data
{
public class ActionItem
{
[Category("Common"), Display(Order = 0)]
[ReadOnly(true)]
[Description("The id of this action (read-only), maybe used for references elsewhere")]
public Guid Id { get; set; } = Guid.NewGuid();

[Category("Common"), Display(Order = 10)]
[Description("The name of the menu item")]
public string Name { get; set; }
Expand Down Expand Up @@ -66,6 +72,10 @@ public class ActionItem
[Description("When Type = ShowTrayBrowser or ShowTrayMediaPlayer, whether to start in fullscreen mode")]
public bool StartFullscreen { get; set; } = false;

[Category("TrayWindow"), Display(Order = 350)]
[Description("When Type = ShowTrayBrowser or ShowTrayMediaPlayer, id's of actions to be displayed in the window context menu")]
public BindingList<string> InplaceActions { get; set; } = new BindingList<string>();

[Category("TrayMediaPlayer"), Display(Order = 400)]
[Description("When Type = ShowTrayMediaPlayer, whether to mute audio on start")]
public bool StartMuted { get; set; } = false;
Expand Down
9 changes: 9 additions & 0 deletions Data/ActionItemReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Traything.Data
{
public class ActionItemReference
{
public Guid Id { get; set; }
}
}
22 changes: 14 additions & 8 deletions Data/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
Expand All @@ -22,6 +23,11 @@ public static Settings Load()
settings = (Settings)serializer.Deserialize(reader);
reader.Close();
}

if (new Version(settings.Version).CompareTo(new Version(Program.RunningVersion)) != 0)
{
settings.Save(); // Migrations (may) have been applied => save the file immediately
}
}
else
{
Expand All @@ -47,19 +53,19 @@ public static Settings Example()
{
Settings s = new Settings();
s.Actions.Add(new ActionItem { Name = "Example/demo configuration", Type = ActionType.Headline });
s.Actions.Add(new ActionItem { Name = "Notepad", Type = ActionType.StartApplication, Commandline = "notepad.exe" });
s.Actions.Add(new ActionItem { Name = "Calculator", Type = ActionType.StartApplication, Commandline = "calc.exe" });
s.Actions.Add(new ActionItem { Name = "Open Notepad", Type = ActionType.StartApplication, Commandline = "notepad.exe" });
s.Actions.Add(new ActionItem { Name = "Open Calculator", Type = ActionType.StartApplication, Commandline = "calc.exe" });
s.Actions.Add(new ActionItem { Name = "----Separator1----", Type = ActionType.Separator });
s.Actions.Add(new ActionItem { Name = "HTTP GET request", Type = ActionType.HttpGetRequest, Url = "https://demo.grocy.info/api/system/info" });
ActionItem item = new ActionItem { Name = "HTTP POST request", Type = ActionType.HttpPostRequest, Url = "https://demo.grocy.info/api/objects/locations", PostData = "{ \"name\": \"Test1\" }" };
s.Actions.Add(new ActionItem { Name = "HTTP GET Request", Type = ActionType.HttpGetRequest, Url = "https://traything-demo.berrnd.xyz/httprequest" });
ActionItem item = new ActionItem { Name = "HTTP POST Request", Type = ActionType.HttpPostRequest, Url = "https://traything-demo.berrnd.xyz/httprequest", PostData = "{ \"name\": \"Test1\" }" };
item.Headers.Add("Content-Type: application/json");
s.Actions.Add(item);
s.Actions.Add(new ActionItem { Name = "----Separator2----", Type = ActionType.Separator });
s.Actions.Add(new ActionItem { Name = "Tray browser (stay open)", Type = ActionType.ShowTrayBrowser, PathOrUrl = "https://grocy.info", StayOpen = true });
s.Actions.Add(new ActionItem { Name = "Tray browser (auto hide when focus lost)", Type = ActionType.ShowTrayBrowser, PathOrUrl = "https://grocy.info", StayOpen = false });
s.Actions.Add(new ActionItem { Name = "TrayBrowser (stay open)", Type = ActionType.ShowTrayBrowser, PathOrUrl = "https://traything-demo.berrnd.xyz", StayOpen = true });
s.Actions.Add(new ActionItem { Name = "TrayBrowser (auto hide when focus lost)", Type = ActionType.ShowTrayBrowser, PathOrUrl = "https://traything-demo.berrnd.xyz", StayOpen = false });
s.Actions.Add(new ActionItem { Name = "----Separator3----", Type = ActionType.Separator });
s.Actions.Add(new ActionItem { Name = "Tray stream player (stay open)", Type = ActionType.ShowTrayMediaPlayer, PathOrUrl = "https://mcdn.daserste.de/daserste/de/master.m3u8", StayOpen = true });
s.Actions.Add(new ActionItem { Name = "Tray stream player (auto hide when focus lost)", Type = ActionType.ShowTrayMediaPlayer, PathOrUrl = "https://mcdn.daserste.de/daserste/de/master.m3u8", StayOpen = false });
s.Actions.Add(new ActionItem { Name = "TrayMediaPlayer (stay open)", Type = ActionType.ShowTrayMediaPlayer, PathOrUrl = "https://traything-demo.berrnd.xyz/stream", StayOpen = true });
s.Actions.Add(new ActionItem { Name = "TrayMediaPlayer (auto hide when focus lost)", Type = ActionType.ShowTrayMediaPlayer, PathOrUrl = "https://traything-demo.berrnd.xyz/stream", StayOpen = false });
s.Actions.Add(new ActionItem { Name = "----Separator4----", Type = ActionType.Separator });
s.Actions.Add(new ActionItem { Name = "Close", Type = ActionType.CloseTraything });
return s;
Expand Down
5 changes: 4 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ internal static class Program
internal static readonly string RunningVersion = Regex.Replace(Assembly.GetExecutingAssembly().GetName().Version.ToString(), @"^(.+?)(\.0+)$", "$1");
internal static readonly string BaseExecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.TrimEnd('\\'));
internal static readonly string ExeName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
internal static FrmMain MainForm;

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain());

MainForm = new FrmMain();
Application.Run(MainForm);
}
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.0.0")]
[assembly: AssemblyFileVersion("1.7.0.0")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ There is none. The progress of a specific bug/enhancement is always tracked in t

![edit-item](https://github.com/berrnd/Traything/raw/main/.github/publication_assets/edit-item.png "edit-item")

![actions](https://github.com/berrnd/Traything/raw/main/.github/publication_assets/actions.gif "actions")
https://github.com/berrnd/Traything/raw/main/.github/publication_assets/live-example.mp4

## How to build

Expand Down
1 change: 1 addition & 0 deletions Traything.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Data\ActionItem.cs" />
<Compile Include="Data\ActionItemReference.cs" />
<Compile Include="UI\FrmAbout.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
3 changes: 2 additions & 1 deletion UI/BaseTrayForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Traything.Data;
Expand Down Expand Up @@ -110,7 +111,7 @@ private void BaseTrayForm_Shown(object sender, EventArgs e)
this.Ready = true;
}

public virtual void ShowTrayForm(ActionItem item)
public virtual void ShowTrayForm(ActionItem item, List<ActionItem> inplaceActions)
{
this.ActionItem = item;
this.Text = item.Name;
Expand Down
61 changes: 53 additions & 8 deletions UI/FrmBrowser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
Expand All @@ -19,6 +20,7 @@ public FrmBrowser(FrmMain parent)
}

private ChromiumWebBrowser Browser;
internal Dictionary<int, ActionItem> InplaceActions = new Dictionary<int, ActionItem>();

private void SetupCef()
{
Expand Down Expand Up @@ -56,20 +58,36 @@ private void FrmBrowser_Shown(object sender, EventArgs e)
this.SetupCef();
}

public override void ShowTrayForm(ActionItem item)
public override void ShowTrayForm(ActionItem item, List<ActionItem> inplaceActions)
{
while (!this.Ready)
{
Application.DoEvents();
}

this.Browser.Load(item.PathOrUrlReplaced);
base.ShowTrayForm(item);
base.ShowTrayForm(item, inplaceActions);

if (item.StartFullscreen)
{
this.ToggleFullscreen();
}

if (inplaceActions != null && inplaceActions.Count > 0)
{
// Max. 98 items (26601 to 26699)
int commandId = 26601;
foreach (ActionItem action in inplaceActions)
{
this.InplaceActions.Add(commandId, action);
commandId++;

if (commandId >= 26699)
{
break;
}
}
}
}

private void FrmBrowser_FormClosing(object sender, FormClosingEventArgs e)
Expand All @@ -87,6 +105,7 @@ private void FrmBrowser_FormClosing(object sender, FormClosingEventArgs e)
}

this.Browser.Load("about:blank");
this.InplaceActions.Clear();

if (this.Fullscreen_On)
{
Expand Down Expand Up @@ -117,23 +136,41 @@ internal void ToggleFullscreen()

this.Fullscreen_On = !this.Fullscreen_On;
}

private void InplaceActionMenuItem_Click(object sender, EventArgs e)
{
Program.MainForm.ExecuteAction((ActionItem)((ToolStripMenuItem)sender).Tag);
}
}

public class BrowserContextMenuHandler : IContextMenuHandler
{
public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
{
ChromiumWebBrowser chromiumBrowser = browserControl as ChromiumWebBrowser;
FrmBrowser parentForm = chromiumBrowser.Tag as FrmBrowser;

model.Clear();

model.AddItem((CefMenuCommand)26501, browser.MainFrame.Url);
model.AddSeparator();
model.AddItem((CefMenuCommand)26511, "Toggle fullscreen mode");
model.AddSeparator();
model.AddItem((CefMenuCommand)26521, "Zoom In");
model.AddItem((CefMenuCommand)26522, "Zoom Out");
model.AddItem((CefMenuCommand)26523, "Zoom Reset");

if (parentForm.InplaceActions.Count > 0)
{
model.AddSeparator();
foreach (KeyValuePair<int, ActionItem> item in parentForm.InplaceActions)
{
model.AddItem((CefMenuCommand)item.Key, item.Value.Name);
}
}

model.AddSeparator();
model.AddItem((CefMenuCommand)26531, "Toggle fullscreen mode");
model.AddSeparator();
model.AddItem((CefMenuCommand)26541, "Close");
model.AddItem((CefMenuCommand)26531, "Close");

}

Expand All @@ -150,7 +187,6 @@ public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, I
return true;
}


// Zoom In
if (commandId == (CefMenuCommand)26521)
{
Expand Down Expand Up @@ -181,7 +217,7 @@ public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, I
}

// Toggle fullscreen mode
if (commandId == (CefMenuCommand)26531)
if (commandId == (CefMenuCommand)26511)
{
parentForm.BeginInvoke(new Action(() =>
{
Expand All @@ -192,7 +228,7 @@ public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, I
}

// Close
if (commandId == (CefMenuCommand)26541)
if (commandId == (CefMenuCommand)26531)
{
parentForm.BeginInvoke(new Action(() =>
{
Expand All @@ -202,6 +238,15 @@ public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, I
return true;
}

// Inplace action
if (commandId >= (CefMenuCommand)26601 && commandId <= (CefMenuCommand)26699)
{
parentForm.BeginInvoke(new Action(() =>
{
Program.MainForm.ExecuteAction(parentForm.InplaceActions[(int)commandId]);
}));
}

return false;
}

Expand Down
6 changes: 3 additions & 3 deletions UI/FrmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private void TrayMenuItem_Click(object sender, EventArgs e)
this.ExecuteAction((ActionItem)((ToolStripMenuItem)sender).Tag);
}

private void ExecuteAction(ActionItem item)
internal void ExecuteAction(ActionItem item)
{
try
{
Expand Down Expand Up @@ -275,11 +275,11 @@ private void ExecuteAction(ActionItem item)
}
else if (item.Type == ActionType.ShowTrayBrowser)
{
this.GetAvailableBrowser().ShowTrayForm(item);
this.GetAvailableBrowser().ShowTrayForm(item, this.Settings.Actions.FindAll(x => item.InplaceActions.Contains(x.Id.ToString())));
}
else if (item.Type == ActionType.ShowTrayMediaPlayer)
{
this.GetAvailableVlcPlayer().ShowTrayForm(item);
this.GetAvailableVlcPlayer().ShowTrayForm(item, this.Settings.Actions.FindAll(x => item.InplaceActions.Contains(x.Id.ToString())));
}
}
catch (Exception ex)
Expand Down
25 changes: 17 additions & 8 deletions UI/FrmVlcPlayer.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 099e64c

Please sign in to comment.