Skip to content

Commit

Permalink
Add analytics and reporting functionality
Browse files Browse the repository at this point in the history
Introduced `AnalyticsService` for sending OS and activity data and `ReportService` for user feedback submissions. Added `ReportForm` UI to capture and send user reports. Updated necessary components and configurations to integrate these features.
  • Loading branch information
ivandrofly committed Feb 17, 2025
1 parent e3e84ea commit 2302c21
Show file tree
Hide file tree
Showing 9 changed files with 508 additions and 6 deletions.
10 changes: 10 additions & 0 deletions source/HI2UC/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Nikse.SubtitleEdit.PluginLogic.Services;

namespace Nikse.SubtitleEdit.PluginLogic;

Expand Down Expand Up @@ -58,6 +59,15 @@ public string DoAction(Form parentForm, string srtText, double frame, string uiL
// Load raws subtitle lines into Subtitle object
srt.LoadSubtitle(sub, list, file);

// analytics

var analyticsService = new AnalyticsService();
_ = analyticsService.SendAsync(new Data()
{
OsVersion = Environment.OSVersion.ToString(),
LastActive = DateTimeOffset.Now
}).ConfigureAwait(false);

IPlugin hi2Uc = this;
using (var form = new PluginForm(sub, hi2Uc.Name, hi2Uc.Description))
{
Expand Down
6 changes: 6 additions & 0 deletions source/HI2UC/HI2UC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="ReportForm.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
34 changes: 28 additions & 6 deletions source/HI2UC/PluginForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Nikse.SubtitleEdit.PluginLogic.Converters.Strategies;
using Nikse.SubtitleEdit.PluginLogic.Extensions;
using Nikse.SubtitleEdit.PluginLogic.Models;
using Nikse.SubtitleEdit.PluginLogic.Services;

namespace Nikse.SubtitleEdit.PluginLogic;

Expand Down Expand Up @@ -55,7 +56,7 @@ public PluginForm(Subtitle subtitle, string name, string description)
uncheckAllToolStripMenuItem.Click += (_, _) => listViewFixes.UncheckAll();
invertCheckToolStripMenuItem.Click += (_, _) => listViewFixes.InvertCheck();

linkLabel1.DoubleClick += LinkLabel1_DoubleClick;
linkLabel1.Click += LaunchReportWindow;

// force layout
// ReSharper disable once VirtualMemberCallInConstructor
Expand All @@ -71,9 +72,29 @@ public PluginForm(Subtitle subtitle, string name, string description)
pictureBoxDonate.Click += (_, _) => { Process.Start(StringUtils.DonateUrl); };
}

private void LinkLabel1_DoubleClick(object sender, EventArgs e)
private readonly ReportService _reportService = new();

private async void LaunchReportWindow(object sender, EventArgs e)
{
Process.Start("https://github.com/SubtitleEdit/plugins/issues/new");
using (var reportForm = new ReportForm(_reportService))
{
if (reportForm.ShowDialog() == DialogResult.OK)
{
try
{
var report = new Report(reportForm.ReportMessage, _subtitle.ToText());
if (await _reportService.ReportAsync(report).ConfigureAwait(false))
{
MessageBox.Show("Thank you for your report!");
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
}
// Process.Start("https://github.com/SubtitleEdit/plugins/issues/new");
}

private void UpdateUiFromConfigs(HiConfigs configs)
Expand Down Expand Up @@ -123,7 +144,7 @@ private void ApplyChanges()
listViewFixes.BeginUpdate();
foreach (var listViewItem in listViewFixes.Items.CheckItems())
{
var record = (Record) listViewItem.Tag;
var record = (Record)listViewItem.Tag;
record.Paragraph.Text = record.After;
}

Expand Down Expand Up @@ -208,7 +229,7 @@ private ICollection<ICasingConverter> GetConverters()
return commands;
}

private IConverterStrategy GetStrategy() => (IConverterStrategy) comboBoxStyle.SelectedItem;
private IConverterStrategy GetStrategy() => (IConverterStrategy)comboBoxStyle.SelectedItem;

public void LoadConfigurations()
{
Expand All @@ -232,7 +253,7 @@ public void LoadConfigurations()

private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
var text = ((Paragraph) listViewFixes.FocusedItem.Tag).ToString();
var text = ((Paragraph)listViewFixes.FocusedItem.Tag).ToString();
Clipboard.SetText(text, TextDataFormat.UnicodeText);
}

Expand All @@ -249,6 +270,7 @@ private void deleteLineToolStripMenuItem_Click(object sender, EventArgs e)

listViewFixes.Items.RemoveAt(index);
}

listViewFixes.EndUpdate();

_subtitle.Renumber();
Expand Down
73 changes: 73 additions & 0 deletions source/HI2UC/ReportForm.Designer.cs

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

22 changes: 22 additions & 0 deletions source/HI2UC/ReportForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Windows.Forms;
using Nikse.SubtitleEdit.PluginLogic.Services;

namespace Nikse.SubtitleEdit.PluginLogic;

public partial class ReportForm : Form
{
private readonly ReportService _reportService;

public string ReportMessage { get; set; }

public ReportForm(ReportService reportService)
{
InitializeComponent();
StartPosition = FormStartPosition.CenterParent;

_reportService = reportService;
buttonSubmit.DialogResult = DialogResult.OK;

Closing += (sender, args) => ReportMessage = textBox1.Text;
}
}
120 changes: 120 additions & 0 deletions source/HI2UC/ReportForm.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Loading

0 comments on commit 2302c21

Please sign in to comment.