插件升级信息

This commit is contained in:
LittleBoy 2024-04-09 23:13:45 +08:00
parent 79d9e215b6
commit 7a48856b1b
14 changed files with 201 additions and 30 deletions

Binary file not shown.

View File

@ -43,6 +43,11 @@ namespace AIProofread
private static int selectProofreadId = -1; private static int selectProofreadId = -1;
public string GetAppVersion()
{
return Config.APP_VERSION;
}
public void showDialog(string message) public void showDialog(string message)
{ {
System.Windows.Forms.MessageBox.Show(message); System.Windows.Forms.MessageBox.Show(message);
@ -129,6 +134,16 @@ namespace AIProofread
return Tools.GetJSONString(data); return Tools.GetJSONString(data);
} }
public void ShowUpgrade(string data)
{
var upgradeData = JsonConvert.DeserializeObject<UpgradeData>(data);
var ret = System.Windows.Forms.MessageBox.Show(upgradeData.Message,"更新提示",System.Windows.Forms.MessageBoxButtons.YesNo,System.Windows.Forms.MessageBoxIcon.Question);
if(ret == System.Windows.Forms.DialogResult.Yes)
{
OpenUrlWithOsBrowser(upgradeData.DownloadUrl);
}
}
public void noticeOtherWeb(string json, string targetWebName) public void noticeOtherWeb(string json, string targetWebName)
{ {
if (targetWebName != null) if (targetWebName != null)

View File

@ -6,11 +6,12 @@ namespace AIProofread
public class Config public class Config
{ {
public static readonly string APP_NAME = "AI校对王"; public static readonly string APP_NAME = "AI校对王";
public static readonly string APP_VERSION = "1.0.0";
#if DEBUG #if DEBUG
/// <summary> /// <summary>
/// 网页访问地址 /// 网页访问地址
/// </summary> /// </summary>
public static readonly string WEB_PATH = "https://gm-plugin.gachafun.com/"; public static readonly string WEB_PATH = "http://192.168.10.100:5173/";
#else #else
public static readonly string WEB_PATH = "https://gm-plugin.gachafun.com/"; public static readonly string WEB_PATH = "https://gm-plugin.gachafun.com/";
#endif #endif

View File

@ -22,7 +22,7 @@ namespace AIProofread.Controls
private void ProofreadMainControl_Load(object sender, EventArgs e) private void ProofreadMainControl_Load(object sender, EventArgs e)
{ {
this.web.Source = new Uri(Config.WebPath("#home")); this.web.Source = new Uri(Config.WebPath("#home?version=" + Config.APP_VERSION));
} }
} }

View File

@ -63,7 +63,6 @@
// //
// tabAIProofread // tabAIProofread
// //
this.tabAIProofread.ControlId.ControlIdType = Microsoft.Office.Tools.Ribbon.RibbonControlIdType.Office;
this.tabAIProofread.Groups.Add(this.group1); this.tabAIProofread.Groups.Add(this.group1);
this.tabAIProofread.Groups.Add(this.group3); this.tabAIProofread.Groups.Add(this.group3);
this.tabAIProofread.Groups.Add(this.group2); this.tabAIProofread.Groups.Add(this.group2);
@ -72,6 +71,7 @@
this.tabAIProofread.Groups.Add(this.gpLogout); this.tabAIProofread.Groups.Add(this.gpLogout);
this.tabAIProofread.Label = "AI校对王"; this.tabAIProofread.Label = "AI校对王";
this.tabAIProofread.Name = "tabAIProofread"; this.tabAIProofread.Name = "tabAIProofread";
this.tabAIProofread.Position = this.Factory.RibbonPosition.AfterOfficeId("TabHelp");
// //
// group1 // group1
// //

View File

@ -82,7 +82,8 @@ namespace AIProofread
private void BtnUpdate_Click(object sender, RibbonControlEventArgs e) private void BtnUpdate_Click(object sender, RibbonControlEventArgs e)
{ {
System.Windows.Forms.MessageBox.Show("当前插件是最新版本"); //System.Windows.Forms.MessageBox.Show("当前插件是最新版本");
Globals.ThisAddIn.SendMessageToWeb("upgrade",Config.APP_VERSION);
} }
private void BtnProofreadAll_Click(object sender, RibbonControlEventArgs e) private void BtnProofreadAll_Click(object sender, RibbonControlEventArgs e)

View File

@ -8,6 +8,7 @@ using Newtonsoft.Json;
using UtilLib; using UtilLib;
using System.Threading; using System.Threading;
using Microsoft.Office.Interop.Word; using Microsoft.Office.Interop.Word;
using System.Linq;
namespace AIProofread namespace AIProofread
{ {
@ -31,7 +32,6 @@ namespace AIProofread
/// 校对面板 /// 校对面板
/// </summary> /// </summary>
public ProofreadMainControl proofreadPanel; public ProofreadMainControl proofreadPanel;
public CustomTaskPane customTaskPane;
/// <summary> /// <summary>
/// 工具栏 /// 工具栏
/// </summary> /// </summary>
@ -41,20 +41,99 @@ namespace AIProofread
public List<FormLogin> LoginFormList = new List<FormLogin>(); public List<FormLogin> LoginFormList = new List<FormLogin>();
public Dictionary<Word.Document, CustomTaskPane> taskPanels = new Dictionary<Word.Document, CustomTaskPane>();
private CustomTaskPane customTaskPane;
private void Application_WindowDeactivate(Word.Document Doc, Window Wn)
{
//HidePanel(Doc);
}
private void Application_WindowActivate(Word.Document Doc, Window Wn)
{
//ShowPanel(Doc);
if (!taskPanels.ContainsKey(Doc))
{
ShowPanel(Doc);
}
HideOtherPanel(Doc);
}
private void Application_DocumentBeforeClose(Word.Document Doc, ref bool Cancel)
{
DisposePanel(Doc);
}
private void Application_NewDocument(Word.Document Doc)
{
ShowPanel(Doc);
}
private void Application_DocumentOpen(Word.Document Doc)
{
ShowPanel(Doc);
}
void DisposePanel(Word.Document doc)
{
if (taskPanels.ContainsKey(doc))
{
taskPanels[doc].Visible = false;
taskPanels[doc].Dispose();
taskPanels.Remove(doc);
}
}
void HideOtherPanel(Word.Document doc)
{
if (taskPanels.ContainsKey(doc) && taskPanels[doc].Visible)
{
return;
}
foreach (var key in taskPanels.Keys)
{
taskPanels[key].Visible = doc == key;
}
}
void HidePanel(Word.Document doc)
{
if (taskPanels.ContainsKey(doc))
{
taskPanels[doc].Visible = false;
}
}
/// <summary> /// <summary>
/// word创建面板 /// word创建面板
/// </summary> /// </summary>
private void CreateCustomTaskPane() private CustomTaskPane ShowPanel(Word.Document doc)
{ {
proofreadPanel = new ProofreadMainControl(); //if (!IsWPS)
customTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(proofreadPanel, AddinName); //{
customTaskPane.Width = MinWidth; // if (Application.ActiveDocument == null) return;
customTaskPane.Visible = false; // if (doc == null) doc = Application.ActiveDocument;
//proofreadPanel.SizeChanged += ProofreadPanel_SizeChanged; //}
//customTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight; if (Application.ActiveDocument == null) return null;
if (doc == null) doc = Application.ActiveDocument;
if (taskPanels.ContainsKey(doc))
{
taskPanels[doc].Visible = true;
return taskPanels[doc];
}
//proofreadPanel = new ProofreadMainControl();
var panel = Globals.ThisAddIn.CustomTaskPanes.Add(new ProofreadMainControl(), AddinName);
this.customTaskPane = panel;
taskPanels.Add(doc, panel);
panel.Width = MinWidth;
panel.Visible = !IsWPS;
return panel;
} }
public void Send(SendOrPostCallback d) { public void Send(SendOrPostCallback d)
{
FmainThreadContext.Send(d, null); FmainThreadContext.Send(d, null);
} }
@ -71,25 +150,33 @@ namespace AIProofread
private void ThisAddIn_Startup(object sender, System.EventArgs e) private void ThisAddIn_Startup(object sender, System.EventArgs e)
{ {
FmainThreadContext = SynchronizationContext.Current; FmainThreadContext = SynchronizationContext.Current;
//Module1.CreateCTP();
// 启动地址 // 启动地址
applicationStartupPath = System.Windows.Forms.Application.StartupPath; applicationStartupPath = System.Windows.Forms.Application.StartupPath;
if (applicationStartupPath.Contains("WPS")) if (applicationStartupPath.Contains("WPS"))
{ {
IsWPS = true; IsWPS = true;
} }
CreateCustomTaskPane(); // 处理文档事件
Application.DocumentOpen += Application_DocumentOpen;
Application.DocumentBeforeClose += Application_DocumentBeforeClose;
Application.WindowActivate += Application_WindowActivate;
Application.WindowDeactivate += Application_WindowDeactivate;
(Application as ApplicationEvents4_Event).NewDocument += Application_NewDocument;
// 选区发生变化事件
this.Application.WindowSelectionChange += Application_WindowSelectionChange; this.Application.WindowSelectionChange += Application_WindowSelectionChange;
} }
private void Application_WindowSelectionChange(Word.Selection s) private void Application_WindowSelectionChange(Word.Selection s)
{ {
if(s.Bookmarks != null) if (s.Bookmarks != null)
{ {
if(s.Range.Start == s.Range.End) // 说明是点击呀 if (s.Range.Start == s.Range.End) // 说明是点击呀
{ {
var count = s.Bookmarks.Count; var count = s.Bookmarks.Count;
if(s.Bookmarks.Count == 1) // 只有这一个 if (s.Bookmarks.Count == 1) // 只有这一个
{ {
foreach (Microsoft.Office.Interop.Word.Bookmark item in s.Bookmarks) foreach (Microsoft.Office.Interop.Word.Bookmark item in s.Bookmarks)
{ {
@ -106,19 +193,14 @@ namespace AIProofread
Bridge.bridge.SelectMarkById(-1); Bridge.bridge.SelectMarkById(-1);
} }
private void ThisAddIn_Shutdown(object sender, System.EventArgs e) public int MyProperty { get; set; }
{
// PanelModule.DisposeCTP();
this.proofreadPanel.Dispose();
this.customTaskPane.Dispose();
this.customTaskPane = null;
}
public void SendMessageToWeb(string msg,object data) public void SendMessageToWeb(string msg, object data)
{ {
this.ShowPanel(); var panel = this.ShowPanel(Application.ActiveDocument);
var json = JsonConvert.SerializeObject(new WebMessage(msg,data)); var json = JsonConvert.SerializeObject(new WebMessage(msg, data));
this.proofreadPanel.web.CoreWebView2.PostWebMessageAsJson(json); var control = (ProofreadMainControl)panel.Control;
control.web.CoreWebView2.PostWebMessageAsJson(json);
} }
// 显示面板 // 显示面板
@ -143,6 +225,30 @@ namespace AIProofread
frm.Show(); frm.Show();
} }
void ClearPanels()
{
taskPanels.Values.ToList().ForEach(p =>
{
try
{
p.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
Logger.Log(ex.Message + "\n" + ex.StackTrace);
}
});
taskPanels.Clear();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// PanelModule.DisposeCTP();
//this.proofreadPanel.Dispose();
ClearPanels();
}
#region VSTO generated code #region VSTO generated code
/// <summary> /// <summary>

47
util-lib/UpgradeData.cs Normal file
View File

@ -0,0 +1,47 @@
using System;
namespace UtilLib
{
public class UpgradeData
{
public int Id { get; set; }
/// <summary>
/// APP名称
/// </summary>
public string AppName { get; set; }
/// <summary>
/// 客户端类型 1ios 2安卓 3window插件 4 5
/// </summary>
public int ClientType { get; set; }
/// <summary>
/// 发布类型
/// </summary>
public int PublishType { get; set; }
/// <summary>
/// 发布的版本号
/// </summary>
public string Version { get; set; }
/// <summary>
/// 升级类型1强制升级 2强制提示 3弱提示
/// </summary>
public int UpgradeType { get; set; }
public string DownloadUrl { get; set; }
/// <summary>
/// 发布时间
/// </summary>
public int PublishTime { get; set; }
/// <summary>
/// 发布的信息
/// </summary>
public string Message { get; set; }
public int CompatibleVersionId { get; set; }
public int IsShowPop { get; set; }
public bool NeedUpgrade(string currentVersion)
{
var remoteVer = new Version(Version);
var currentVer = new Version(currentVersion);
return remoteVer > currentVer;
}
}
}

View File

@ -47,6 +47,7 @@
<Compile Include="CorrectedContent.cs" /> <Compile Include="CorrectedContent.cs" />
<Compile Include="DocumentCorrectItem.cs" /> <Compile Include="DocumentCorrectItem.cs" />
<Compile Include="ProofreadType.cs" /> <Compile Include="ProofreadType.cs" />
<Compile Include="UpgradeData.cs" />
<Compile Include="Userinfo.cs" /> <Compile Include="Userinfo.cs" />
<Compile Include="UtilLib.cs" /> <Compile Include="UtilLib.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />