Browse Source

远程广告-需求变动和总流程bug修复

lvle 1 year ago
parent
commit
4aa494313c

+ 28 - 19
PDF Office/App.xaml.cs

@@ -135,16 +135,13 @@ namespace PDF_Master
         public static bool IsFirstOpen = true;
 
        /// <summary>
-       /// 是否是带参数激活窗体
+       /// 激活窗体的原因
        /// </summary>
-        public static bool  IswithparametersOpen = false;
+        public static string  WebOpencase = "";
 
         public static bool IsBookMode = false;
 
-        /// <summary>
-        /// 是否从前端购买后激活APP
-        /// </summary>
-        public static bool IsSubscriptionOK = false;
+
         /// <summary>
         /// 是否使用过高级功能
         /// </summary>
@@ -170,6 +167,11 @@ namespace PDF_Master
         /// </summary>
         public static uint WakeId;
 
+        /// <summary>
+        /// 网页查看账单信息token失效唤起
+        /// </summary>
+        public static uint WebopenexpiredId;
+
         /// <summary>
         /// 文案资源管理器  首页
         /// </summary>
@@ -262,24 +264,32 @@ namespace PDF_Master
 
         protected override void OnStartup(StartupEventArgs e)
         {
-            MsgId = Win32Helper.RegisterWindowMessage("msgNotify_PDFMaster");
+               MsgId = Win32Helper.RegisterWindowMessage("msgNotify_PDFMaster");
             WakeId = Win32Helper.RegisterWindowMessage("msgWake_PDFMaster");
             Process[] pros = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
-            
             //禁止多开程序
             if (pros.Length > 1)
             {
                 if (e != null && e.Args != null && e.Args.Length > 0)
                 {
-                    if(Webgoapp(e.Args)==true)
+                    if (Webgoapp(e.Args)==true)
                     {
-                        IswithparametersOpen = true;
-                        MessageBox.Show(IswithparametersOpen.ToString());
-                        Win32Helper.PostMessage((IntPtr)0xffff, WakeId, IntPtr.Zero, IntPtr.Zero);
-                        IntPtr waitPtr = Win32Helper.CreateEvent(IntPtr.Zero, true, false, "Global\\shareWaitNotify" + Guid.NewGuid());
-                        Win32Helper.WaitForSingleObject(waitPtr, 5000);
-                        Win32Helper.CloseHandle(waitPtr);
-                        ServiceHelper.GetUser();
+                        if(WebOpencase=="expired")
+                        {
+                            Win32Helper.PostMessage((IntPtr)0xffff,WebopenexpiredId, IntPtr.Zero, IntPtr.Zero);
+                            IntPtr waitPtr = Win32Helper.CreateEvent(IntPtr.Zero, true, false, "Global\\shareWaitNotify" + Guid.NewGuid());
+                            Win32Helper.WaitForSingleObject(waitPtr, 5000);
+                            Win32Helper.CloseHandle(waitPtr);
+                        }
+                        else
+                        {
+                            Win32Helper.PostMessage((IntPtr)0xffff, WakeId, IntPtr.Zero, IntPtr.Zero);
+                            IntPtr waitPtr = Win32Helper.CreateEvent(IntPtr.Zero, true, false, "Global\\shareWaitNotify" + Guid.NewGuid());
+                            Win32Helper.WaitForSingleObject(waitPtr, 5000);
+                            Win32Helper.CloseHandle(waitPtr);
+                        }
+
+                      
                     }
                     else
                     {
@@ -447,20 +457,19 @@ namespace PDF_Master
             if (args.Length > 0)
             {
                 string url = args[0];
-                MessageBox.Show("Url:"+url);
                 string[] urlParts = url.Split(new char[] { '?', '&' });
                 Dictionary<string, string> parameters = new Dictionary<string, string>();
 
                 foreach (string part in urlParts.Skip(1))
                 {
                     string[] keyValue = part.Split('=');
-                    if (keyValue.Length == 2)
+                    if (keyValue.Length > 0)
                     {
                         flg = true;
                         string key = keyValue[0];
                         string value = Uri.UnescapeDataString(keyValue[1]); // 对参数值进行URL解码
+                        WebOpencase = value;
                     }
-                    MessageBox.Show("flg:" + flg);
                 }
             }
             return flg;

+ 0 - 2
PDF Office/Helper/ConverterHelper.cs

@@ -621,8 +621,6 @@ namespace PDF_Master.Helper
         /// </summary>
         public static void convertUnlock()
         {      
-                //开始监听数据
-                ServiceHelper.ServerBoot();
                 Process.Start(new ProcessStartInfo("http://test-pdf-pro.kdan.cn:3021/windows/store/master-subscription?email=" + Settings.Default.UserDate.Email));
         }
 

+ 57 - 58
PDF Office/Helper/ServiceHelper.cs

@@ -1205,69 +1205,68 @@ namespace PDF_Master.Helper
             catch { }
         }
 
+        //监听代码,暂时用不到,注释
         //监听订阅行为
-        public static HttpListener httpListener;
-        public static bool isListening = false;
-
-        public async static void ServerBoot()
-        {
-            if (!isListening)
-            {
-                httpListener = new HttpListener();
-            httpListener.Prefixes.Add("http://127.0.0.1:5544/");
-
-            // 启动监听器
-            httpListener.Start();
-            Console.WriteLine($"开始喽");
-                isListening = true;
-                // 在后台线程中等待请求并处理
-                await Task.Run(() => ListenForRequests());
+        //public static HttpListener httpListener;
+        //public static bool isListening = false;
+
+        //public async static void ServerBoot()
+        //{
+        //    if (!isListening)
+        //    {
+        //        httpListener = new HttpListener();
+        //    httpListener.Prefixes.Add("http://127.0.0.1:5544/");
+
+        //    // 启动监听器
+        //    httpListener.Start();
+        //    Console.WriteLine($"开始喽");
+        //        isListening = true;
+        //        // 在后台线程中等待请求并处理
+        //        await Task.Run(() => ListenForRequests());
                 
-            }
+        //    }
 
-        }
+        //}
 
-        private static async Task ListenForRequests()
-        {
-            WakeId = Win32Helper.RegisterWindowMessage("msgWake_PDFMaster");
-            Console.WriteLine("等待请求...");
-            App.IsSubscriptionOK = false;
-            // 持续监听请求
-            while (true)
-            {
+        //private static async Task ListenForRequests()
+        //{
+        //    WakeId = Win32Helper.RegisterWindowMessage("msgWake_PDFMaster");
+        //    Console.WriteLine("等待请求...");
+        //    // 持续监听请求
+        //    while (true)
+        //    {
              
-                   // 等待接收请求
-                 HttpListenerContext context = await httpListener.GetContextAsync();
-
-              // 允许跨域请求
-                    context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
-                    context.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
-                    context.Response.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
-
-
-                // 处理请求
-                if (context.Request.HttpMethod == "GET")
-                {
-                    //返回 true 并结束监听
-                    if (App.IsLogin == true)
-                    {
-                        App.IsSubscriptionOK = true;
-                        Win32Helper.PostMessage((IntPtr)0xffff, WakeId, IntPtr.Zero, IntPtr.Zero);
-                        IntPtr waitPtr = Win32Helper.CreateEvent(IntPtr.Zero, true, false, "Global\\shareWaitNotify" + Guid.NewGuid());
-                        Win32Helper.WaitForSingleObject(waitPtr, 5000);
-                        Win32Helper.CloseHandle(waitPtr);
-                    }
-                    byte[] responseBytes = System.Text.Encoding.UTF8.GetBytes("true");
-                    context.Response.StatusCode = (int)HttpStatusCode.OK;
-                    context.Response.ContentLength64 = responseBytes.Length;
-                    context.Response.OutputStream.Write(responseBytes, 0, responseBytes.Length);
-                    context.Response.OutputStream.Close();
-                    httpListener.Stop();
-                    isListening = false;
-                    break;
-                }
-            }
-        }
+        //           // 等待接收请求
+        //         HttpListenerContext context = await httpListener.GetContextAsync();
+
+        //      // 允许跨域请求
+        //            context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
+        //            context.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
+        //            context.Response.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
+
+
+        //        // 处理请求
+        //        if (context.Request.HttpMethod == "GET")
+        //        {
+        //            //返回 true 并结束监听
+        //            if (App.IsLogin == true)
+        //            {
+        //                Win32Helper.PostMessage((IntPtr)0xffff, WakeId, IntPtr.Zero, IntPtr.Zero);
+        //                IntPtr waitPtr = Win32Helper.CreateEvent(IntPtr.Zero, true, false, "Global\\shareWaitNotify" + Guid.NewGuid());
+        //                Win32Helper.WaitForSingleObject(waitPtr, 5000);
+        //                Win32Helper.CloseHandle(waitPtr);
+        //            }
+        //            byte[] responseBytes = System.Text.Encoding.UTF8.GetBytes("true");
+        //            context.Response.StatusCode = (int)HttpStatusCode.OK;
+        //            context.Response.ContentLength64 = responseBytes.Length;
+        //            context.Response.OutputStream.Write(responseBytes, 0, responseBytes.Length);
+        //            context.Response.OutputStream.Close();
+        //            httpListener.Stop();
+        //            isListening = false;
+        //            break;
+        //        }
+        //    }
+        //}
     }
 
 

+ 0 - 2
PDF Office/ViewModels/Dialog/NoviceGuidDialogViewModel.cs

@@ -196,8 +196,6 @@ namespace PDF_Master.ViewModels.Dialog
             //忽略,下次再看
             //2023.7.17 策略调整,因配图较多,不显示再提示字样 
             //this.RequestClose(new DialogResult(ButtonResult.Ignore));
-            //开始监听数据
-            ServiceHelper.ServerBoot();
             Process.Start(new ProcessStartInfo("http://test-pdf-pro.kdan.cn:3021/windows/store/master?email=" + Settings.Default.UserDate.Email));     
         }
 

+ 0 - 1
PDF Office/ViewModels/Dialog/ServiceDialog/RegisterOKRegionViewModel.cs

@@ -132,7 +132,6 @@ namespace PDF_Master.ViewModels.Dialog.ServiceDialog
 
         private void Linkstore()
         {
-            ServiceHelper.ServerBoot();
             Process.Start(new ProcessStartInfo("http://test-pdf-pro.kdan.cn:3021/windows/store/master?email=" + Settings.Default.UserDate.Email));
 
         }

+ 0 - 1
PDF Office/ViewModels/Dialog/ServiceDialog/SubscriptionDialogViewModel.cs

@@ -219,7 +219,6 @@ namespace PDF_Master.ViewModels.Dialog.ServiceDialog
         }
         private void Linkstore()
         {
-            ServiceHelper.ServerBoot();
             DataTrackingHelper.AddThirdPath();
             DataTrackingHelper.SendPurchaseEvent();
             DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.PUW, "Sub_PUW", "PUW_Sub_Subscribe");

+ 0 - 2
PDF Office/ViewModels/Dialog/ServiceDialog/UserDialogViewModel.cs

@@ -387,8 +387,6 @@ namespace PDF_Master.ViewModels.Dialog.ServiceDialog
         }
         private void Linkstore()
         {
-            //开始监听数据
-            ServiceHelper.ServerBoot();
             Process.Start(new ProcessStartInfo(Uristore));
         }
         private void Linkuserdata()

+ 0 - 2
PDF Office/ViewModels/MainWindowViewModel.cs

@@ -418,8 +418,6 @@ namespace PDF_Master.ViewModels
 
         private void Upgradelink()
         {
-            //开始监听数据
-            ServiceHelper.ServerBoot();
             DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Upgrade");
             Process.Start(new ProcessStartInfo("http://test-pdf-pro.kdan.cn:3021/windows/store/master?email=" + Settings.Default.UserDate.Email));
         }

+ 10 - 1
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -836,9 +836,10 @@ namespace PDF_Master.ViewModels
         public DelegateCommand OpenFileCommand { get; set; }
 
         public DelegateCommand<string> HelpCommand { get; set; }
-
         public DelegateCommand CreateBlankFileCommand { get; set; }
 
+        public DelegateCommand RefreshCommand { get; set; }
+
         public DelegateCommand CreateFromFile { get; set; }
 
         public DelegateCommand ClosePropertyCommand { get; set; }
@@ -914,6 +915,7 @@ namespace PDF_Master.ViewModels
             OpenFileCommand = new DelegateCommand(openfile);
             HelpCommand = new DelegateCommand<string>(help);
             CreateBlankFileCommand = new DelegateCommand(createBlankFile);
+            RefreshCommand = new DelegateCommand(Refresh);
             CreateFromFile = new DelegateCommand(createfromFile);
             OpenPropertyCommand = new DelegateCommand<object>(openProperty);
             AboutDialogCommmand = new DelegateCommand(about);
@@ -3583,6 +3585,13 @@ namespace PDF_Master.ViewModels
             }
         }
 
+        /// <summary>
+        /// 刷新账号信息
+        /// </summary>
+        public void Refresh()
+        {
+            ServiceHelper.GetUser();
+        }
         #endregion 方法
 
         #region Navigate

+ 29 - 20
PDF Office/Views/MainWindow.xaml.cs

@@ -43,7 +43,6 @@ namespace PDF_Master.Views
             InitializeComponent();
 
             this.SourceInitialized += MainWindow_SourceInitialized;
-
             System.Windows.Forms.Application.EnableVisualStyles();
         }
 
@@ -113,6 +112,7 @@ namespace PDF_Master.Views
             }
             if (msg == App.WakeId)
             {
+              
                 //将现有窗口激活 并前置
                 try
                 {
@@ -121,18 +121,7 @@ namespace PDF_Master.Views
                         WindowState = WindowState.Normal;
                     }
                     Activate();
-                if (App.IswithparametersOpen == true)
-                    {
-                        if (App.IsLogin == true)
-                        {
-                            App.mainWindowViewModel.OpenUser();
-                        }
-                        else
-                        {
-                            App.mainWindowViewModel.OpenLogin();
-                            App.IswithparametersOpen = false;
-                        }
-                    }
+                    ServiceHelper.GetUser();
                     handled = true;
                 }
                 catch
@@ -142,6 +131,33 @@ namespace PDF_Master.Views
 
                 return (IntPtr)(1);
             }
+            if(msg==App.WebopenexpiredId)
+            { //将现有窗口激活 并前置
+                try
+                {
+                    if (WindowState == WindowState.Minimized)
+                    {
+                        WindowState = WindowState.Normal;
+                    }
+                    Activate();
+                    ServiceHelper.GetUser();
+                    if (App.IsLogin == true)
+                    {
+                        App.mainWindowViewModel.OpenUser();
+                        App.WebOpencase = "";
+                    }
+                    else
+                    {
+                        App.mainWindowViewModel.OpenLogin();
+                        App.WebOpencase = "";
+                    }
+                    handled = true;
+                }
+                catch
+                {
+
+                }
+            }
             return IntPtr.Zero;
         }
 
@@ -211,13 +227,6 @@ namespace PDF_Master.Views
                 App.mainWindowViewModel.UpgradeVis = Visibility.Visible;
             }
 
-            //是否从前端购买后激活APP
-            if (App.IsSubscriptionOK == true)
-            {
-                ServiceHelper.GetUser();
-                App.mainWindowViewModel.OpenSubSubscriptionOK();
-                App.IsSubscriptionOK = false;
-            }
             //设为默认浏览器后,外部点击文档打开
             if (App.NeedOpenFilePathList.Count != 0)
             {

+ 2 - 0
PDF Office/Views/ViewContent.xaml

@@ -388,6 +388,8 @@
                                     CommandParameter="FeedBack"
                                     Header="Feedback" />
                             </MenuItem>
+                            <MenuItem Command="{Binding RefreshCommand}" Header="Account Refresh" />
+
                             <MenuItem Click="MenuItem_Click" Header="Check Update" />
                             <MenuItem Command="{Binding AboutDialogCommmand}" Header="About" />
                         </ContextMenu>