protected override void OnStartup(StartupEventArgs e) { const string appName = "KakaoStroy Notification"; _mutex = new Mutex(true, appName, out bool createdNew); try { DesktopNotificationManagerCompat.RegisterAumidAndComServer <KSPNotificationActivator>(KSP_WPF.MainWindow.APP_ID); DesktopNotificationManagerCompat.RegisterActivator <KSPNotificationActivator>(); } catch (Exception) {} if (Environment.OSVersion.Version.Major != 10) { if (KSP_WPF.Properties.Settings.Default.W10Warn == false) { KSP_WPF.Properties.Settings.Default.Upgrade(); KSP_WPF.Properties.Settings.Default.W10Warn = true; KSP_WPF.Properties.Settings.Default.Save(); MessageBox.Show("현재 버전은 윈도우 7,8 호환모드로 작동하고있습니다.\n윈도우 10을 사용중이시라면 마이크로소프트 스토어에 KakaoStory Manager를 검색하여 스토어 버전을 받아주세요.", "경고"); } } else { if (KSP_WPF.Properties.Settings.Default.Upgraded == false) { KSP_WPF.Properties.Settings.Default.Upgrade(); KSP_WPF.Properties.Settings.Default.Upgraded = true; KSP_WPF.Properties.Settings.Default.Save(); if (MessageBox.Show("프로그램이 업데이트되었습니다.\n변경 내역을 확인하시겠습니까?", "안내", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { System.Diagnostics.Process.Start("https://kagamine-rin.com/?p=186"); } } } if (!createdNew) { if (!KSP_WPF.Properties.Settings.Default.Disable_Message) { GlobalHelper.ShowNotification("안내", "프로그램이 이미 실행중이므로 자동 종료되었습니다.", null); } Current.Shutdown(); } else { new MainWindow().Show(); } base.OnStartup(e); }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!IsClose) { e.Cancel = true; if (Properties.Settings.Default.DefaultMinimize) { WindowState = WindowState.Minimized; } else { Hide(); } if (!Properties.Settings.Default.Disable_Message && Environment.OSVersion.Version.Major == 10) { GlobalHelper.ShowNotification("안내", "프로그램이 최소화됐습니다.\r\n시스템 트레이의 프로그램 아이콘을 더블클릭하여 창을 복구할 수 있습니다.", null); } } }
public static async Task <List <CSNotification> > RequestNotification(bool isReturn) { if (MainWindow.IsLoggedIn) { string requestURI = "https://story.kakao.com/a/notifications"; HttpWebRequest webRequest = GenerateDefaultProfile(requestURI); webRequest.Timeout = NotificationRefreshTime; DateTime?lastTime = null; try { string response = await GetResponseFromRequest(webRequest); List <CSNotification> obj = JsonConvert.DeserializeObject <List <CSNotification> >(response); if (isReturn) { return(obj); } int countTemp = 0; if (obj.Count > 0) { lastTime = obj[0].created_at; } for (int count = 0; count < obj.Count; count++) { countTemp = count; DateTime CurrentMessage = obj[count].created_at; if (LastMessageTime != null && GlobalHelper.ToUnixTime(CurrentMessage) > GlobalHelper.ToUnixTime((DateTime)LastMessageTime)) { string Message = obj[count].message; string Content = obj[count].content ?? "내용 없음"; string Profile = null; string Identity = null; string Uri = "https://story.kakao.com/"; if (obj[count].scheme != null && (obj[count].scheme.Contains("?profile_id="))) { var ObjStr = obj[count].scheme?.Split(new string[] { "?profile_id=" }, StringSplitOptions.None); Profile = ObjStr[1]; Identity = ObjStr[0].Split('.')[1]; Uri += Profile + "/" + Identity + "!" + ObjStr[0]; } if (obj[count].scheme != null && (obj[count].scheme.Contains("kakaostory://profiles/"))) { Uri += obj[count].scheme.Replace("kakaostory://profiles/", ""); } bool willShow = true; if (Properties.Settings.Default.Disable_Like && obj[count].emotion != null) { willShow = false; } else if (Properties.Settings.Default.Disable_VIP && obj[count].decorators != null && obj[count].decorators[0] != null && obj[count].decorators[0].text != null && obj[count].decorators[0].text.StartsWith("관심친구")) { willShow = false; } if (willShow && obj[count].is_new) { if (Environment.OSVersion.Version.Major == 10) { GlobalHelper.ShowNotification(Message, Content, Uri, obj[count].comment_id, obj[count].actor?.id, obj[count].actor?.display_name, Profile, Identity, obj[count].thumbnail_url ?? obj[count].actor?.profile_thumbnail_url); } else { GlobalHelper.ShowNotification(Message, Content, Uri); } } try { string activityID = Uri.Split(new string[] { "activities/" }, StringSplitOptions.None)[1]; if (MainWindow.Posts.ContainsKey(activityID)) { MainWindow.Posts[activityID].Refresh(); MainWindow.Posts[activityID].SV_Comment.ScrollToEnd(); } } catch (Exception) {} } else { break; } } if (MainWindow.IsOffline) { if (!Properties.Settings.Default.Disable_Message) { GlobalHelper.ShowNotification("안내", "인터넷 연결이 복구됐습니다.", null); } MainWindow.Instance.Title = MainWindow.Instance.Title.Replace(OfflineStr, ""); MainWindow.IsOffline = false; } } catch (WebException) { if (!MainWindow.IsOffline && Environment.OSVersion.Version.Major == 10) { MainWindow.Instance.Title = MainWindow.Instance.Title.Replace(OfflineStr, "") + OfflineStr; MainWindow.IsOffline = true; if (!Properties.Settings.Default.Disable_Message) { GlobalHelper.ShowNotification("일반 오류", "인터넷 연결에 문제가 발생했습니다. 자동으로 복구를 시도합니다.", null); } } } catch (Exception) { } finally { if (lastTime != null) { LastMessageTime = lastTime; } } } if (isReturn == false) { await Task.Delay(NotificationRefreshTime); await RequestNotification(isReturn); } return(null); }