diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo index d7fc550..0c1a964 100644 Binary files a/.vs/AIProofread/v17/.suo and b/.vs/AIProofread/v17/.suo differ diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs index 47c2b20..ac9fd43 100644 --- a/AIProofread/Bridge.cs +++ b/AIProofread/Bridge.cs @@ -43,6 +43,11 @@ namespace AIProofread private static int selectProofreadId = -1; + public string GetAppVersion() + { + return Config.APP_VERSION; + } + public void showDialog(string message) { System.Windows.Forms.MessageBox.Show(message); @@ -129,6 +134,16 @@ namespace AIProofread return Tools.GetJSONString(data); } + public void ShowUpgrade(string data) + { + var upgradeData = JsonConvert.DeserializeObject(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) { if (targetWebName != null) diff --git a/AIProofread/Config.cs b/AIProofread/Config.cs index cc1dcf7..3b4762a 100644 --- a/AIProofread/Config.cs +++ b/AIProofread/Config.cs @@ -6,11 +6,12 @@ namespace AIProofread public class Config { public static readonly string APP_NAME = "AI校对王"; + public static readonly string APP_VERSION = "1.0.0"; #if DEBUG /// /// 网页访问地址 /// - public static readonly string WEB_PATH = "https://gm-plugin.gachafun.com/"; + public static readonly string WEB_PATH = "http://192.168.10.100:5173/"; #else public static readonly string WEB_PATH = "https://gm-plugin.gachafun.com/"; #endif diff --git a/AIProofread/Controls/ProofreadMainControl.cs b/AIProofread/Controls/ProofreadMainControl.cs index 6ebf582..74f27ac 100644 --- a/AIProofread/Controls/ProofreadMainControl.cs +++ b/AIProofread/Controls/ProofreadMainControl.cs @@ -22,7 +22,7 @@ namespace AIProofread.Controls 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)); } } diff --git a/AIProofread/Ribbon1.Designer.cs b/AIProofread/Ribbon1.Designer.cs index 3705b9d..03edd2b 100644 --- a/AIProofread/Ribbon1.Designer.cs +++ b/AIProofread/Ribbon1.Designer.cs @@ -63,7 +63,6 @@ // // tabAIProofread // - this.tabAIProofread.ControlId.ControlIdType = Microsoft.Office.Tools.Ribbon.RibbonControlIdType.Office; this.tabAIProofread.Groups.Add(this.group1); this.tabAIProofread.Groups.Add(this.group3); this.tabAIProofread.Groups.Add(this.group2); @@ -72,6 +71,7 @@ this.tabAIProofread.Groups.Add(this.gpLogout); this.tabAIProofread.Label = "AI校对王"; this.tabAIProofread.Name = "tabAIProofread"; + this.tabAIProofread.Position = this.Factory.RibbonPosition.AfterOfficeId("TabHelp"); // // group1 // diff --git a/AIProofread/Ribbon1.cs b/AIProofread/Ribbon1.cs index 5b462fb..67777e0 100644 --- a/AIProofread/Ribbon1.cs +++ b/AIProofread/Ribbon1.cs @@ -82,7 +82,8 @@ namespace AIProofread 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) diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs index 7d6dd4b..fb225da 100644 --- a/AIProofread/ThisAddIn.cs +++ b/AIProofread/ThisAddIn.cs @@ -8,6 +8,7 @@ using Newtonsoft.Json; using UtilLib; using System.Threading; using Microsoft.Office.Interop.Word; +using System.Linq; namespace AIProofread { @@ -31,7 +32,6 @@ namespace AIProofread /// 校对面板 /// public ProofreadMainControl proofreadPanel; - public CustomTaskPane customTaskPane; /// /// 工具栏 /// @@ -41,20 +41,99 @@ namespace AIProofread public List LoginFormList = new List(); + public Dictionary taskPanels = new Dictionary(); + 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; + } + } /// /// word创建面板 /// - private void CreateCustomTaskPane() + private CustomTaskPane ShowPanel(Word.Document doc) { - proofreadPanel = new ProofreadMainControl(); - customTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(proofreadPanel, AddinName); - customTaskPane.Width = MinWidth; - customTaskPane.Visible = false; - //proofreadPanel.SizeChanged += ProofreadPanel_SizeChanged; - //customTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight; + //if (!IsWPS) + //{ + // if (Application.ActiveDocument == null) return; + // if (doc == null) doc = Application.ActiveDocument; + //} + 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); } @@ -71,25 +150,33 @@ namespace AIProofread private void ThisAddIn_Startup(object sender, System.EventArgs e) { FmainThreadContext = SynchronizationContext.Current; - //Module1.CreateCTP(); // 启动地址 applicationStartupPath = System.Windows.Forms.Application.StartupPath; if (applicationStartupPath.Contains("WPS")) { 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; } + + + 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; - if(s.Bookmarks.Count == 1) // 只有这一个 + if (s.Bookmarks.Count == 1) // 只有这一个 { foreach (Microsoft.Office.Interop.Word.Bookmark item in s.Bookmarks) { @@ -106,19 +193,14 @@ namespace AIProofread Bridge.bridge.SelectMarkById(-1); } - private void ThisAddIn_Shutdown(object sender, System.EventArgs e) - { - // PanelModule.DisposeCTP(); - this.proofreadPanel.Dispose(); - this.customTaskPane.Dispose(); - this.customTaskPane = null; - } + public int MyProperty { get; set; } - public void SendMessageToWeb(string msg,object data) + public void SendMessageToWeb(string msg, object data) { - this.ShowPanel(); - var json = JsonConvert.SerializeObject(new WebMessage(msg,data)); - this.proofreadPanel.web.CoreWebView2.PostWebMessageAsJson(json); + var panel = this.ShowPanel(Application.ActiveDocument); + var json = JsonConvert.SerializeObject(new WebMessage(msg, data)); + var control = (ProofreadMainControl)panel.Control; + control.web.CoreWebView2.PostWebMessageAsJson(json); } // 显示面板 @@ -138,11 +220,35 @@ namespace AIProofread public void ShowLoginForm(string action) { FormLogin frm = new FormLogin(action); - + LoginFormList.Add(frm); 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 /// diff --git a/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache b/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache index 8a2ed3c..34d6b8c 100644 Binary files a/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache and b/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache differ diff --git a/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache b/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache index bd20f29..70129a1 100644 Binary files a/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache and b/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache differ diff --git a/AIProofread/obj/Debug/AIProofread.dll b/AIProofread/obj/Debug/AIProofread.dll index dba262f..699dbc8 100644 Binary files a/AIProofread/obj/Debug/AIProofread.dll and b/AIProofread/obj/Debug/AIProofread.dll differ diff --git a/AIProofread/obj/Debug/AIProofread.pdb b/AIProofread/obj/Debug/AIProofread.pdb index 4300800..1e034dd 100644 Binary files a/AIProofread/obj/Debug/AIProofread.pdb and b/AIProofread/obj/Debug/AIProofread.pdb differ diff --git a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferences.cache index fc7c96e..1dddad4 100644 Binary files a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/util-lib/UpgradeData.cs b/util-lib/UpgradeData.cs new file mode 100644 index 0000000..92c8ffd --- /dev/null +++ b/util-lib/UpgradeData.cs @@ -0,0 +1,47 @@ +using System; + +namespace UtilLib +{ + public class UpgradeData + { + public int Id { get; set; } + /// + /// APP名称 + /// + public string AppName { get; set; } + /// + /// 客户端类型 1ios 2安卓 3window插件 4 5 + /// + public int ClientType { get; set; } + /// + /// 发布类型 + /// + public int PublishType { get; set; } + /// + /// 发布的版本号 + /// + public string Version { get; set; } + /// + /// 升级类型(1强制升级 2强制提示 3弱提示) + /// + public int UpgradeType { get; set; } + public string DownloadUrl { get; set; } + /// + /// 发布时间 + /// + public int PublishTime { get; set; } + /// + /// 发布的信息 + /// + 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; + } + } +} diff --git a/util-lib/util-lib.csproj b/util-lib/util-lib.csproj index 5c5c213..d14cdc6 100644 --- a/util-lib/util-lib.csproj +++ b/util-lib/util-lib.csproj @@ -47,6 +47,7 @@ +