From 65a313fb4e4126db0dcedeb967cbc0fca5c696c0 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Mon, 3 Jun 2024 15:07:45 +0300 Subject: [PATCH 01/30] Test version --- .github/ISSUE_TEMPLATE/bug_report.yml | 3 +- .../SettingsXAML/Views/GeneralPage.xaml | 2 +- .../SettingsXAML/Views/GeneralPage.xaml.cs | 2 + .../ViewModels/GeneralViewModel.cs | 43 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 78affbb16f13..4230a2b198d7 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -7,7 +7,8 @@ body: - type: markdown attributes: value: Please make sure to [search for existing issues](https://github.com/microsoft/PowerToys/issues) before filing a new one! -- type: input +- id: version + type: input attributes: label: Microsoft PowerToys version placeholder: 0.70.0 diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml index 4ffa0bf4a999..65a0d12b6b0d 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml @@ -367,7 +367,7 @@ - + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml.cs index ed29e2e9f6d7..c01a1da87c16 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml.cs @@ -84,6 +84,8 @@ public GeneralPage() DataContext = ViewModel; doRefreshBackupRestoreStatus(100); + + ViewModel.InitializeReportBugLink(); } private void OpenColorsSettings_Click(object sender, RoutedEventArgs e) diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 8d55056f64d4..9079d3c58ee1 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; @@ -11,6 +12,8 @@ using System.Runtime.CompilerServices; using System.Text.Json; using System.Threading.Tasks; +using System.Web; +using CommunityToolkit.WinUI.Helpers; using global::PowerToys.GPOWrapper; using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Library; @@ -18,6 +21,7 @@ using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using Windows.System; namespace Microsoft.PowerToys.Settings.UI.ViewModels { @@ -177,7 +181,46 @@ public GeneralViewModel(ISettingsRepository settingsRepository, private string _settingsBackupMessage; private string _backupRestoreMessageSeverity; + private string reportBugLink; + // Gets or sets a value indicating whether run powertoys on start-up. + public string ReportBugLink + { + get => reportBugLink; + set + { + reportBugLink = value; + OnPropertyChanged(nameof(ReportBugLink)); + } + } + + public void InitializeReportBugLink() + { + var version = HttpUtility.UrlEncode(GetPowerToysVersion()); + + var gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CTriage-Needed&template=bug_report.yml" + + "&version=" + version; + + ReportBugLink = gitHubURL; + } + + private string GetPowerToysVersion() + { + return "0.88.0"; // Replace with the actual method to get the version. + } + + private string GetOSVersion() + { + // Implement a method to get the OS version + return "OS_VERSION_PLACEHOLDER"; + } + + private string GetDotNetVersion() + { + // Implement a method to get the .NET version + return "DOT_NET_VERSION_PLACEHOLDER"; + } + public bool Startup { get From 96c09532fadb992dfe20523f8eb28247ab300827 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Mon, 3 Jun 2024 15:09:23 +0300 Subject: [PATCH 02/30] Github URL --- src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 9079d3c58ee1..a2ce031a7eb1 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -198,7 +198,7 @@ public void InitializeReportBugLink() { var version = HttpUtility.UrlEncode(GetPowerToysVersion()); - var gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CTriage-Needed&template=bug_report.yml" + + var gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CTriage-Needed&template=bug_report.yml" + "&version=" + version; ReportBugLink = gitHubURL; From f2ed58f3296ce2917f02ca584e7b83c33a1b741c Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Tue, 4 Jun 2024 17:02:31 +0300 Subject: [PATCH 03/30] repro --- .github/ISSUE_TEMPLATE/bug_report.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 4230a2b198d7..92e8f8c440fd 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -81,7 +81,8 @@ body: validations: required: true -- type: textarea +- id: repro + type: textarea attributes: label: Steps to reproduce description: We highly suggest including screenshots and a bug report log (System tray > Report bug). From 9c0ef91fd9e90d29a1b424115c59d785f84da4e7 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Wed, 5 Jun 2024 16:58:31 +0300 Subject: [PATCH 04/30] os version --- .github/ISSUE_TEMPLATE/bug_report.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 92e8f8c440fd..38a266ff438f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -104,7 +104,8 @@ body: validations: required: false -- type: textarea +- id: othersoftware + type: textarea attributes: label: Other Software description: If you're reporting a bug about our interaction with other software, what software? What versions? From e7cc3a04f7fb0b5b7924ea7d0fb7ee0fc762982b Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Wed, 5 Jun 2024 17:27:18 +0300 Subject: [PATCH 05/30] isadmin --- .github/ISSUE_TEMPLATE/bug_report.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 38a266ff438f..4c5887644d81 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -33,7 +33,8 @@ body: validations: required: true -- type: dropdown +- id: isadmin + type: dropdown attributes: label: Running as admin description: Are you running PowerToys as Admin? @@ -81,8 +82,7 @@ body: validations: required: true -- id: repro - type: textarea +- type: textarea attributes: label: Steps to reproduce description: We highly suggest including screenshots and a bug report log (System tray > Report bug). From f97cc86f673b3c3738aae9546a4618cc25427505 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Thu, 6 Jun 2024 15:55:47 +0300 Subject: [PATCH 06/30] report --- .github/ISSUE_TEMPLATE/bug_report.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 4c5887644d81..bcb15f1e001f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -10,6 +10,16 @@ body: - id: version type: input attributes: + value: | + label: Microsoft PowerToys version placeholder: 0.70.0 description: Hover over system tray icon or look at Settings From c87a344007c10308fe38ee7889c5cf572877265b Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Thu, 6 Jun 2024 15:56:55 +0300 Subject: [PATCH 07/30] report --- .github/ISSUE_TEMPLATE/bug_report.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index bcb15f1e001f..e96897117655 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -5,10 +5,6 @@ labels: - Needs-Triage body: - type: markdown - attributes: - value: Please make sure to [search for existing issues](https://github.com/microsoft/PowerToys/issues) before filing a new one! -- id: version - type: input attributes: value: | + value: Please make sure to [search for existing issues](https://github.com/microsoft/PowerToys/issues) before filing a new one! +- id: version + type: input + attributes: label: Microsoft PowerToys version placeholder: 0.70.0 description: Hover over system tray icon or look at Settings From 3c6d882e91ec0161ba1f2f62096594a95e87e396 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Thu, 6 Jun 2024 15:58:52 +0300 Subject: [PATCH 08/30] report --- .github/ISSUE_TEMPLATE/bug_report.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index e96897117655..4c5887644d81 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -6,16 +6,6 @@ labels: body: - type: markdown attributes: - value: | - value: Please make sure to [search for existing issues](https://github.com/microsoft/PowerToys/issues) before filing a new one! - id: version type: input From c716aa65aee3c532916ea25324e33f5b4c0f7df5 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 7 Jun 2024 13:51:58 +0300 Subject: [PATCH 09/30] Revert "report" This reverts commit 3c6d882e91ec0161ba1f2f62096594a95e87e396. --- .github/ISSUE_TEMPLATE/bug_report.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 4c5887644d81..e96897117655 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -6,6 +6,16 @@ labels: body: - type: markdown attributes: + value: | + value: Please make sure to [search for existing issues](https://github.com/microsoft/PowerToys/issues) before filing a new one! - id: version type: input From 27b234e38ec05fd3f6a7871f630e821830ea839d Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 7 Jun 2024 13:52:02 +0300 Subject: [PATCH 10/30] Revert "report" This reverts commit c87a344007c10308fe38ee7889c5cf572877265b. --- .github/ISSUE_TEMPLATE/bug_report.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index e96897117655..bcb15f1e001f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -5,6 +5,10 @@ labels: - Needs-Triage body: - type: markdown + attributes: + value: Please make sure to [search for existing issues](https://github.com/microsoft/PowerToys/issues) before filing a new one! +- id: version + type: input attributes: value: | - value: Please make sure to [search for existing issues](https://github.com/microsoft/PowerToys/issues) before filing a new one! -- id: version - type: input - attributes: label: Microsoft PowerToys version placeholder: 0.70.0 description: Hover over system tray icon or look at Settings From ce010f5f7af6d8bfd937b55e71a30fb2064ebc66 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 7 Jun 2024 13:52:05 +0300 Subject: [PATCH 11/30] Revert "report" This reverts commit f97cc86f673b3c3738aae9546a4618cc25427505. --- .github/ISSUE_TEMPLATE/bug_report.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index bcb15f1e001f..4c5887644d81 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -10,16 +10,6 @@ body: - id: version type: input attributes: - value: | - label: Microsoft PowerToys version placeholder: 0.70.0 description: Hover over system tray icon or look at Settings From 51a33afbdbfb3e407833449b75e6ded37ead24a3 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 7 Jun 2024 13:52:10 +0300 Subject: [PATCH 12/30] Revert "isadmin" This reverts commit e7cc3a04f7fb0b5b7924ea7d0fb7ee0fc762982b. --- .github/ISSUE_TEMPLATE/bug_report.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 4c5887644d81..38a266ff438f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -33,8 +33,7 @@ body: validations: required: true -- id: isadmin - type: dropdown +- type: dropdown attributes: label: Running as admin description: Are you running PowerToys as Admin? @@ -82,7 +81,8 @@ body: validations: required: true -- type: textarea +- id: repro + type: textarea attributes: label: Steps to reproduce description: We highly suggest including screenshots and a bug report log (System tray > Report bug). From 5596a32e3d4e5090cce95e56cf6a03a126410d5a Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 7 Jun 2024 13:52:13 +0300 Subject: [PATCH 13/30] Revert "os version" This reverts commit 9c0ef91fd9e90d29a1b424115c59d785f84da4e7. --- .github/ISSUE_TEMPLATE/bug_report.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 38a266ff438f..92e8f8c440fd 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -104,8 +104,7 @@ body: validations: required: false -- id: othersoftware - type: textarea +- type: textarea attributes: label: Other Software description: If you're reporting a bug about our interaction with other software, what software? What versions? From f9b1588375645cdf686e2e8342014c96b6ef7a64 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 7 Jun 2024 13:52:16 +0300 Subject: [PATCH 14/30] Revert "repro" This reverts commit f2ed58f3296ce2917f02ca584e7b83c33a1b741c. --- .github/ISSUE_TEMPLATE/bug_report.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 92e8f8c440fd..4230a2b198d7 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -81,8 +81,7 @@ body: validations: required: true -- id: repro - type: textarea +- type: textarea attributes: label: Steps to reproduce description: We highly suggest including screenshots and a bug report log (System tray > Report bug). From 5c0e14656e997f66e4f09cc757b4aaac99636d3e Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 7 Jun 2024 13:52:19 +0300 Subject: [PATCH 15/30] Revert "Github URL" This reverts commit 96c09532fadb992dfe20523f8eb28247ab300827. --- src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index a2ce031a7eb1..9079d3c58ee1 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -198,7 +198,7 @@ public void InitializeReportBugLink() { var version = HttpUtility.UrlEncode(GetPowerToysVersion()); - var gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CTriage-Needed&template=bug_report.yml" + + var gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CTriage-Needed&template=bug_report.yml" + "&version=" + version; ReportBugLink = gitHubURL; From d45ae2c1978ef6a614a5bc8ca858f7adbce404b8 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 7 Jun 2024 13:52:24 +0300 Subject: [PATCH 16/30] Revert "Test version" This reverts commit 65a313fb4e4126db0dcedeb967cbc0fca5c696c0. --- .github/ISSUE_TEMPLATE/bug_report.yml | 3 +- .../SettingsXAML/Views/GeneralPage.xaml | 2 +- .../SettingsXAML/Views/GeneralPage.xaml.cs | 2 - .../ViewModels/GeneralViewModel.cs | 43 ------------------- 4 files changed, 2 insertions(+), 48 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 4230a2b198d7..78affbb16f13 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -7,8 +7,7 @@ body: - type: markdown attributes: value: Please make sure to [search for existing issues](https://github.com/microsoft/PowerToys/issues) before filing a new one! -- id: version - type: input +- type: input attributes: label: Microsoft PowerToys version placeholder: 0.70.0 diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml index 65a0d12b6b0d..4ffa0bf4a999 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml @@ -367,7 +367,7 @@ - + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml.cs index c01a1da87c16..ed29e2e9f6d7 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml.cs @@ -84,8 +84,6 @@ public GeneralPage() DataContext = ViewModel; doRefreshBackupRestoreStatus(100); - - ViewModel.InitializeReportBugLink(); } private void OpenColorsSettings_Click(object sender, RoutedEventArgs e) diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 9079d3c58ee1..8d55056f64d4 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; @@ -12,8 +11,6 @@ using System.Runtime.CompilerServices; using System.Text.Json; using System.Threading.Tasks; -using System.Web; -using CommunityToolkit.WinUI.Helpers; using global::PowerToys.GPOWrapper; using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Library; @@ -21,7 +18,6 @@ using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; -using Windows.System; namespace Microsoft.PowerToys.Settings.UI.ViewModels { @@ -181,46 +177,7 @@ public GeneralViewModel(ISettingsRepository settingsRepository, private string _settingsBackupMessage; private string _backupRestoreMessageSeverity; - private string reportBugLink; - // Gets or sets a value indicating whether run powertoys on start-up. - public string ReportBugLink - { - get => reportBugLink; - set - { - reportBugLink = value; - OnPropertyChanged(nameof(ReportBugLink)); - } - } - - public void InitializeReportBugLink() - { - var version = HttpUtility.UrlEncode(GetPowerToysVersion()); - - var gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CTriage-Needed&template=bug_report.yml" + - "&version=" + version; - - ReportBugLink = gitHubURL; - } - - private string GetPowerToysVersion() - { - return "0.88.0"; // Replace with the actual method to get the version. - } - - private string GetOSVersion() - { - // Implement a method to get the OS version - return "OS_VERSION_PLACEHOLDER"; - } - - private string GetDotNetVersion() - { - // Implement a method to get the .NET version - return "DOT_NET_VERSION_PLACEHOLDER"; - } - public bool Startup { get From 24bc41a7e52a4eb8450852984300922b49c9f783 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 7 Jun 2024 15:43:07 +0300 Subject: [PATCH 17/30] [BugReport] Autofill PT version and other software, create a bug report when Report a Bug Clicked. --- .github/ISSUE_TEMPLATE/bug_report.yml | 9 +- .../Settings.UI/PowerToys.Settings.csproj | 5 + .../Controls/SettingsPageControl/PageLink.cs | 15 -- .../SettingsPageControl/PageLink.xaml | 14 ++ .../SettingsPageControl/PageLink.xaml.cs | 60 ++++++++ .../SettingsXAML/Views/GeneralPage.xaml | 11 +- .../ViewModels/GeneralViewModel.cs | 138 ++++++++++++++++++ 7 files changed, 230 insertions(+), 22 deletions(-) delete mode 100644 src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.cs create mode 100644 src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml create mode 100644 src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml.cs diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 78affbb16f13..38a266ff438f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -7,7 +7,8 @@ body: - type: markdown attributes: value: Please make sure to [search for existing issues](https://github.com/microsoft/PowerToys/issues) before filing a new one! -- type: input +- id: version + type: input attributes: label: Microsoft PowerToys version placeholder: 0.70.0 @@ -80,7 +81,8 @@ body: validations: required: true -- type: textarea +- id: repro + type: textarea attributes: label: Steps to reproduce description: We highly suggest including screenshots and a bug report log (System tray > Report bug). @@ -102,7 +104,8 @@ body: validations: required: false -- type: textarea +- id: othersoftware + type: textarea attributes: label: Other Software description: If you're reporting a bug about our interaction with other software, what software? What versions? diff --git a/src/settings-ui/Settings.UI/PowerToys.Settings.csproj b/src/settings-ui/Settings.UI/PowerToys.Settings.csproj index b1bcbcfb109e..ad65cf25c6bb 100644 --- a/src/settings-ui/Settings.UI/PowerToys.Settings.csproj +++ b/src/settings-ui/Settings.UI/PowerToys.Settings.csproj @@ -24,6 +24,7 @@ + @@ -76,6 +77,7 @@ + @@ -140,6 +142,9 @@ Always + + MSBuild:Compile + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.cs b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.cs deleted file mode 100644 index a1cc6b078ce4..000000000000 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; - -namespace Microsoft.PowerToys.Settings.UI.Controls -{ - public class PageLink - { - public string Text { get; set; } - - public Uri Link { get; set; } - } -} diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml new file mode 100644 index 000000000000..13b626ede95c --- /dev/null +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml @@ -0,0 +1,14 @@ + + + + + + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml.cs new file mode 100644 index 000000000000..6ff63928e54e --- /dev/null +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Threading.Tasks; +using System.Windows.Input; +using CommunityToolkit.Mvvm.Input; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Windows.System; + +namespace Microsoft.PowerToys.Settings.UI.Controls +{ + public sealed partial class PageLink : UserControl + { + public PageLink() + { + this.InitializeComponent(); + } + + public string Text { get; set; } + + public Uri Link { get; set; } + + public ICommand Command { get; set; } + + public object CommandParameter { get; set; } + + private async void OnClick(object sender, RoutedEventArgs e) + { + if (Command != null && Command.CanExecute(CommandParameter)) + { + if (Command is AsyncRelayCommand asyncCommand) + { + await asyncCommand.ExecuteAsync(CommandParameter); + } + else + { + Command.Execute(CommandParameter); + } + + // Check if CommandParameter has been updated + if (CommandParameter is string uriString && !string.IsNullOrEmpty(uriString)) + { + _ = Launcher.LaunchUriAsync(new Uri(uriString)); + } + else if (Link != null) + { + _ = Launcher.LaunchUriAsync(Link); + } + } + else if (Link != null) + { + var uri = CommandParameter as string ?? Link.ToString(); + _ = Launcher.LaunchUriAsync(new Uri(uri)); + } + } + } +} diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml index 4ffa0bf4a999..becee6fc985d 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml @@ -365,10 +365,13 @@ - - - - + + + + diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 8d55056f64d4..5b7d02930e7d 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -3,14 +3,25 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Abstractions; +using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Text.Json; +using System.Threading; using System.Threading.Tasks; +using System.Web; +using System.Windows; +using System.Windows.Input; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.WinUI.Helpers; using global::PowerToys.GPOWrapper; using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Library; @@ -18,11 +29,16 @@ using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using Windows.System; +using Windows.System.Profile; namespace Microsoft.PowerToys.Settings.UI.ViewModels { public class GeneralViewModel : Observable { + private static readonly object LockObject = new object(); + private static bool isBugReportThreadRunning; + private GeneralSettings GeneralSettingsConfig { get; set; } private UpdatingSettings UpdatingSettingsConfig { get; set; } @@ -57,6 +73,8 @@ public class GeneralViewModel : Observable public string RunningAsAdminDefaultText { get; set; } + public AsyncRelayCommand InitializeReportBugLinkCommand { get; } + private string _settingsConfigFileFolder = string.Empty; private IFileSystemWatcher _fileWatcher; @@ -74,6 +92,7 @@ public GeneralViewModel(ISettingsRepository settingsRepository, SelectSettingBackupDirEventHandler = new ButtonClickCommand(SelectSettingBackupDir); RestoreConfigsEventHandler = new ButtonClickCommand(RestoreConfigsClick); RefreshBackupStatusEventHandler = new ButtonClickCommand(RefreshBackupStatusEventHandlerClick); + InitializeReportBugLinkCommand = new AsyncRelayCommand(InitializeReportBugLinkAsync); HideBackupAndRestoreMessageAreaAction = hideBackupAndRestoreMessageAreaAction; DoBackupAndRestoreDryRun = doBackupAndRestoreDryRun; PickSingleFolderDialog = pickSingleFolderDialog; @@ -177,7 +196,126 @@ public GeneralViewModel(ISettingsRepository settingsRepository, private string _settingsBackupMessage; private string _backupRestoreMessageSeverity; + private string reportBugLink = "https://aka.ms/powerToysReportBug"; + // Gets or sets a value indicating whether run powertoys on start-up. + public string ReportBugLink + { + get => reportBugLink; + set + { + reportBugLink = value; + OnPropertyChanged(nameof(ReportBugLink)); + } + } + + public async Task InitializeReportBugLinkAsync() + { + var version = HttpUtility.UrlEncode(Helper.GetProductVersion().TrimStart('v')); + var otherSoftwareText = "OS Build Version: " + GetOSVersion() + "\n.NET Version: " + GetDotNetVersion(); + var otherSoftware = HttpUtility.UrlEncode(otherSoftwareText); + string reportResult = LaunchBugReport(); + + // DONT FORGET gokcekantarci TO ms + var gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + + "&version=" + version + + "&othersoftware=" + otherSoftware; + + if (string.IsNullOrEmpty(reportResult)) + { + MessageBox.Show($"Bug report generated on your desktop. Please attach the file to the GitHub issue."); + } + else + { + MessageBox.Show($"Failed to generate bug report."); + } + + if (!string.IsNullOrEmpty(gitHubURL)) + { + ReportBugLink = gitHubURL; + } + else + { + ReportBugLink = "https://aka.ms/powerToysReportBug"; + } + + await Task.Delay(100); + } + + public static string LaunchBugReport() + { + string bugReportPath = GetModuleFolderPath() + "\\..\\Tools\\PowerToys.BugReportTool.exe"; + string errorOutput = string.Empty; + lock (LockObject) + { + if (!isBugReportThreadRunning) + { + isBugReportThreadRunning = true; + Thread bugReportThread = new Thread(() => + { + ProcessStartInfo startInfo = new ProcessStartInfo + { + FileName = bugReportPath, + CreateNoWindow = true, + UseShellExecute = false, + WindowStyle = ProcessWindowStyle.Hidden, + RedirectStandardOutput = true, + RedirectStandardError = true, + }; + + try + { + using (Process process = Process.Start(startInfo)) + { + process.WaitForExit(); + + errorOutput = process.StandardError.ReadToEnd().Trim(); + } + } + catch (Exception ex) + { + // Log or handle the exception + MessageBox.Show("Failed to start bug report tool: " + ex.Message, "Error"); + } + finally + { + isBugReportThreadRunning = false; + } + }); + bugReportThread.IsBackground = true; + bugReportThread.Start(); + bugReportThread.Join(); + } + } + + return errorOutput; + } + + private static string GetModuleFolderPath() + { + // You would implement this method to get the path to your module folder in C# + return Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); + } + + private string GetDotNetVersion() + { + var dotNetVersion = RuntimeInformation.FrameworkDescription; + return dotNetVersion.ToString(); + } + + private string GetOSVersion() + { + var attrNames = new List { "OSVersionFull" }; + var attrData = AnalyticsInfo.GetSystemPropertiesAsync(attrNames).AsTask().GetAwaiter().GetResult(); + var osVersion = string.Empty; + if (attrData.ContainsKey("OSVersionFull")) + { + osVersion = attrData["OSVersionFull"]; + } + + return osVersion.ToString(); + } + public bool Startup { get From aff0f3689eb691308d84fb06950453048e4a003c Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Mon, 10 Jun 2024 14:22:27 +0300 Subject: [PATCH 18/30] "iselevated" id added and changed type dopdown to input. --- .github/ISSUE_TEMPLATE/bug_report.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 38a266ff438f..691a96f960c5 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -33,13 +33,14 @@ body: validations: required: true -- type: dropdown +- id: iselevated + type: input attributes: label: Running as admin description: Are you running PowerToys as Admin? - options: - - "Yes" - - "No" + placeholder: Yes + validations: + required: true - type: dropdown attributes: From 4cc7fff3d986506425c4a8b8112cd54dff32061a Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Tue, 11 Jun 2024 16:32:55 +0300 Subject: [PATCH 19/30] [BugReport] Isadmin changed to input type. Loading dialog is added for creating bug report. --- .../Settings.UI/PowerToys.Settings.csproj | 4 + .../SettingsPageControl/LoadingMessage.xaml | 18 +++ .../LoadingMessage.xaml.cs | 16 +++ .../ViewModels/GeneralViewModel.cs | 125 +++++++++++++----- 4 files changed, 133 insertions(+), 30 deletions(-) create mode 100644 src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml create mode 100644 src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml.cs diff --git a/src/settings-ui/Settings.UI/PowerToys.Settings.csproj b/src/settings-ui/Settings.UI/PowerToys.Settings.csproj index ad65cf25c6bb..1b53456efe92 100644 --- a/src/settings-ui/Settings.UI/PowerToys.Settings.csproj +++ b/src/settings-ui/Settings.UI/PowerToys.Settings.csproj @@ -24,6 +24,7 @@ + @@ -142,6 +143,9 @@ Always + + MSBuild:Compile + MSBuild:Compile diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml new file mode 100644 index 000000000000..936ee84a309d --- /dev/null +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml @@ -0,0 +1,18 @@ + + + + + + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml.cs new file mode 100644 index 000000000000..757ceb91f418 --- /dev/null +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.UI.Xaml.Controls; + +namespace Microsoft.PowerToys.Settings.UI.Controls +{ + public sealed partial class LoadingMessage : ContentDialog + { + public LoadingMessage() + { + InitializeComponent(); + } + } +} diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 5b7d02930e7d..f9ae0bb6e7df 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; @@ -18,19 +17,21 @@ using System.Threading.Tasks; using System.Web; using System.Windows; -using System.Windows.Input; -using CommunityToolkit.Mvvm.ComponentModel; +using System.Windows.Interop; +using System.Windows.Threading; +using CommunityToolkit.Common; using CommunityToolkit.Mvvm.Input; -using CommunityToolkit.WinUI.Helpers; using global::PowerToys.GPOWrapper; using ManagedCommon; +using Microsoft.PowerToys.Settings.UI.Controls; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; -using Windows.System; +using Microsoft.UI.Xaml.Controls; using Windows.System.Profile; +using Windows.UI.Core; namespace Microsoft.PowerToys.Settings.UI.ViewModels { @@ -211,41 +212,78 @@ public string ReportBugLink public async Task InitializeReportBugLinkAsync() { + string gitHubURL = string.Empty; var version = HttpUtility.UrlEncode(Helper.GetProductVersion().TrimStart('v')); var otherSoftwareText = "OS Build Version: " + GetOSVersion() + "\n.NET Version: " + GetDotNetVersion(); var otherSoftware = HttpUtility.UrlEncode(otherSoftwareText); - string reportResult = LaunchBugReport(); + var isElevatedRun = IsElevated ? "Yes" : "No"; - // DONT FORGET gokcekantarci TO ms - var gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + - "&version=" + version + - "&othersoftware=" + otherSoftware; + var loadingMessage = new LoadingMessage(); + loadingMessage.XamlRoot = App.GetSettingsWindow().Content.XamlRoot; - if (string.IsNullOrEmpty(reportResult)) - { - MessageBox.Show($"Bug report generated on your desktop. Please attach the file to the GitHub issue."); - } - else + var cts = new CancellationTokenSource(); + + try { - MessageBox.Show($"Failed to generate bug report."); - } + var showDialogTask = loadingMessage.ShowAsync().AsTask(); + var bugReportTask = Task.Run(() => LaunchBugReport(cts.Token), cts.Token); + + // Wait for either the dialog to be closed or the bug report to be generated + var completedTask = await Task.WhenAny(showDialogTask, bugReportTask); - if (!string.IsNullOrEmpty(gitHubURL)) + if (completedTask == showDialogTask && showDialogTask.GetResultOrDefault() == ContentDialogResult.Primary) + { + // Cancel the bug report task if the dialog was closed with Cancel + await cts.CancelAsync(); + } + else if (completedTask == bugReportTask) + { + loadingMessage.Hide(); + + // Bug report task completed + string reportResult = await bugReportTask; + + gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + + "&version=" + version + + "&othersoftware=" + otherSoftware + + "&iselevated=" + HttpUtility.UrlEncode(isElevatedRun); + + var dialog = new ContentDialog + { + Title = string.IsNullOrEmpty(reportResult) ? string.Empty : reportResult, + Content = string.IsNullOrEmpty(reportResult) ? "Failed to generate bug report." : "Bug report generated on your desktop. Please attach the file to the GitHub issue.", + CloseButtonText = "OK", + XamlRoot = loadingMessage.XamlRoot, + }; + + await dialog.ShowAsync(); + } + } + catch (Exception ex) { - ReportBugLink = gitHubURL; + await cts.CancelAsync(); + loadingMessage.Hide(); + var errorDialog = new ContentDialog + { + Title = "Error", + Content = $"An error occurred: {ex.Message}", + CloseButtonText = "OK", + XamlRoot = loadingMessage.XamlRoot, + }; + await errorDialog.ShowAsync(); } - else + finally { - ReportBugLink = "https://aka.ms/powerToysReportBug"; + ReportBugLink = !string.IsNullOrEmpty(gitHubURL) ? gitHubURL : "https://aka.ms/powerToysReportBug"; } - - await Task.Delay(100); } - public static string LaunchBugReport() + // Updated LaunchBugReport method to support cancellation + public string LaunchBugReport(CancellationToken token) { string bugReportPath = GetModuleFolderPath() + "\\..\\Tools\\PowerToys.BugReportTool.exe"; - string errorOutput = string.Empty; + string bugReportFileName = string.Empty; + lock (LockObject) { if (!isBugReportThreadRunning) @@ -267,14 +305,23 @@ public static string LaunchBugReport() { using (Process process = Process.Start(startInfo)) { - process.WaitForExit(); - - errorOutput = process.StandardError.ReadToEnd().Trim(); + while (!process.HasExited) + { + if (token.IsCancellationRequested) + { + process.Kill(); + return; + } + + Thread.Sleep(100); + } } + + // Find the newest bug report file on the desktop + bugReportFileName = FindNewestBugReportFile(); } catch (Exception ex) { - // Log or handle the exception MessageBox.Show("Failed to start bug report tool: " + ex.Message, "Error"); } finally @@ -288,7 +335,7 @@ public static string LaunchBugReport() } } - return errorOutput; + return bugReportFileName; } private static string GetModuleFolderPath() @@ -297,6 +344,24 @@ private static string GetModuleFolderPath() return Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); } + private string FindNewestBugReportFile() + { + string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + DirectoryInfo directoryInfo = new DirectoryInfo(desktopPath); + + // Get all files starting with "PowerToysReport_" + FileInfo[] files = directoryInfo.GetFiles("PowerToysReport_*"); + + if (files.Length == 0) + { + return string.Empty; + } + + // Find the newest file + FileInfo newestFile = files.OrderByDescending(f => f.LastWriteTime).FirstOrDefault(); + return newestFile?.Name; + } + private string GetDotNetVersion() { var dotNetVersion = RuntimeInformation.FrameworkDescription; From a6192a1d5b95d21a0bb1bdab1376718892a4e988 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Thu, 13 Jun 2024 19:16:19 +0300 Subject: [PATCH 20/30] [BugReport] New enhancements to tray icon 'Report Bug' --- src/runner/bug_report.cpp | 336 +++++++++++++++++- src/runner/bug_report.h | 18 +- src/runner/settings_window.cpp | 2 +- src/runner/tray_icon.cpp | 2 +- .../ViewModels/GeneralViewModel.cs | 58 ++- 5 files changed, 397 insertions(+), 19 deletions(-) diff --git a/src/runner/bug_report.cpp b/src/runner/bug_report.cpp index 9abfe6fa1802..ed42bd8d4eee 100644 --- a/src/runner/bug_report.cpp +++ b/src/runner/bug_report.cpp @@ -1,33 +1,343 @@ #include "pch.h" #include "bug_report.h" #include "Generated files/resource.h" +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +namespace fs = std::filesystem; std::atomic_bool isBugReportThreadRunning = false; +std::mutex LockObject; +std::promise cancelPromise; +static std::atomic canceled{ false }; +static HWND hwndMessageBox = nullptr; -void launch_bug_report() noexcept +std::string LaunchBugReport() { + std::string bugReportFileName; std::wstring bug_report_path = get_module_folderpath(); bug_report_path += L"\\Tools\\PowerToys.BugReportTool.exe"; bool expected_isBugReportThreadRunning = false; if (isBugReportThreadRunning.compare_exchange_strong(expected_isBugReportThreadRunning, true)) { - std::thread([bug_report_path]() { - SHELLEXECUTEINFOW sei{ sizeof(sei) }; - sei.fMask = { SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE }; - sei.lpFile = bug_report_path.c_str(); - sei.nShow = SW_HIDE; - if (ShellExecuteExW(&sei)) + SHELLEXECUTEINFOW sei{ sizeof(sei) }; + sei.fMask = { SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE }; + sei.lpFile = bug_report_path.c_str(); + sei.nShow = SW_HIDE; + if (ShellExecuteExW(&sei)) + { + while (WaitForSingleObject(sei.hProcess, 100) == WAIT_TIMEOUT) { - WaitForSingleObject(sei.hProcess, INFINITE); - CloseHandle(sei.hProcess); - static const std::wstring bugreport_success = GET_RESOURCE_STRING(IDS_BUGREPORT_SUCCESS); - MessageBoxW(nullptr, bugreport_success.c_str(), L"PowerToys", MB_OK); + if (canceled.load()) + { + TerminateProcess(sei.hProcess, 0); + CloseHandle(sei.hProcess); + isBugReportThreadRunning.store(false); + return ""; + } } + CloseHandle(sei.hProcess); + + // Find the newest bug report file on the desktop + bugReportFileName = FindNewestBugReportFile(); + } + else + { + std::cerr << "Failed to start bug report tool." << std::endl; + } + + isBugReportThreadRunning.store(false); + } + return bugReportFileName; +} + +BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM /*lParam*/) +{ + DWORD pid; + GetWindowThreadProcessId(hwnd, &pid); + if (pid == GetCurrentProcessId()) + { + wchar_t className[256]; + GetClassName(hwnd, className, 256); + if (wcscmp(className, L"#32770") == 0) // #32770 is the class name for MessageBox + { + wchar_t title[256]; + GetWindowText(hwnd, title, 256); + if (wcscmp(title, L"BugReport") == 0) + { + hwndMessageBox = hwnd; + return FALSE; // Stop enumerating windows + } + } + } + return TRUE; // Continue enumerating windows +} + +HWND GetMessageBoxHandle() +{ + hwndMessageBox = nullptr; + EnumWindows(EnumWindowsProc, 0); + return hwndMessageBox; +} + +DWORD WINAPI ShowCancelableMessageBox(LPVOID /*lpParam*/) +{ + int msgboxID = MessageBox(nullptr, L"Generating bug report, please wait...", L"BugReport", MB_OKCANCEL | MB_ICONINFORMATION); + + if (msgboxID == IDCANCEL) + { + cancelPromise.set_value(); + canceled.store(true); + } + + return 0; +} + +void InitializeReportBugLinkAsync() +{ + std::string gitHubURL; + + canceled.store(false); + cancelPromise = std::promise(); + auto cancelFuture = cancelPromise.get_future(); - isBugReportThreadRunning.store(false); - }).detach(); + std::atomic bugReportCompleted{ false }; + std::string bugReportResult; + + // Launch the bug report task + auto bugReportTask = std::async(std::launch::async, [&bugReportCompleted, &bugReportResult] { + bugReportResult = LaunchBugReport(); + bugReportCompleted.store(true); + + HWND hwnd = GetMessageBoxHandle(); + if (hwnd != nullptr) + { + SendMessage(hwnd, WM_CLOSE, 0, 0); + } + }); + + // Show the message box in a separate thread + HANDLE hThread = CreateThread(nullptr, 0, ShowCancelableMessageBox, nullptr, 0, nullptr); + + // Wait for either the bug report to finish or the user to take action + while (!bugReportCompleted.load()) + { + if (cancelFuture.wait_for(std::chrono::milliseconds(100)) == std::future_status::ready) + { + break; + } + } + + // Ensure bug report task completion + if (!bugReportCompleted.load()) + { + bugReportTask.wait(); + } + + if (!bugReportResult.empty()) + { + std::wstring wversion = get_product_version(); + std::string version; + std::transform(wversion.begin() + 1, wversion.end(), std::back_inserter(version), [](wchar_t c) { + return static_cast(c); + }); + + std::string otherSoftware = "OS Build Version: " + GetOSVersion() + "\n.NET Version: " + GetDotNetVersion(); + GeneralSettings generalSettings = get_general_settings(); + std::string isElevatedRun = generalSettings.isElevated ? "Yes" : "No"; + + gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + + std::string("&version=") + version + + std::string("&othersoftware=") + otherSoftware + + std::string("&iselevated=") + isElevatedRun; + + std::wstring wideBugReportResult = stringToWideString(bugReportResult); + MessageBox(nullptr, L"Bug report generated on your desktop. Please attach the file to the GitHub issue.", wideBugReportResult.c_str(), MB_OKCANCEL | MB_ICONINFORMATION); + } + else + { + gitHubURL = "https://aka.ms/powerToysReportBug"; } + + // Wait for the message box thread to complete + if (hThread != nullptr) + { + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + } + + // Open the URL + std::wstring wgitHubURL(gitHubURL.begin(), gitHubURL.end()); + ShellExecuteW(nullptr, L"open", wgitHubURL.c_str(), nullptr, nullptr, SW_SHOWNORMAL); +} + +std::string FindNewestBugReportFile() +{ + char* desktopPathC; + size_t len; + _dupenv_s(&desktopPathC, &len, "USERPROFILE"); + std::string desktopPath(desktopPathC); + free(desktopPathC); + + desktopPath += "\\Desktop"; + fs::path desktopDir(desktopPath); + + if (!fs::exists(desktopDir) || !fs::is_directory(desktopDir)) + { + return ""; + } + + std::string newestFile; + std::time_t newestTime = 0; + + for (const auto& entry : fs::directory_iterator(desktopDir)) + { + if (entry.is_regular_file() && entry.path().filename().string().find("PowerToysReport_") == 0) + { + std::time_t fileTime = fs::last_write_time(entry).time_since_epoch().count(); + if (fileTime > newestTime) + { + newestTime = fileTime; + newestFile = entry.path().string(); + } + } + } + + return newestFile; +} + +std::wstring ReadRegistryString(HKEY hKeyRoot, const std::wstring& subKey, const std::wstring& valueName) +{ + HKEY hKey; + if (RegOpenKeyEx(hKeyRoot, subKey.c_str(), 0, KEY_READ, &hKey) != ERROR_SUCCESS) + { + return L""; + } + + wchar_t value[256]; + DWORD bufferSize = sizeof(value); + DWORD type; + if (RegQueryValueEx(hKey, valueName.c_str(), 0, &type, (LPBYTE)value, &bufferSize) != ERROR_SUCCESS || type != REG_SZ) + { + RegCloseKey(hKey); + return L""; + } + + RegCloseKey(hKey); + return std::wstring(value); +} + +// Helper function to convert std::wstring to std::string +std::string WideStringToString(const std::wstring& wstr) +{ + if (wstr.empty()) + return std::string(); + int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast(wstr.size()), NULL, 0, NULL, NULL); + std::string str(size_needed, 0); + WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast(wstr.size()), &str[0], size_needed, NULL, NULL); + return str; +} + +std::wstring stringToWideString(const std::string& str) +{ + if (str.empty()) + return std::wstring(); + int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast(str.size()), NULL, 0); + std::wstring wstr(size_needed, 0); + MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast(str.size()), &wstr[0], size_needed); + return wstr; +} + +// Function to get the .NET version +std::string GetDotNetVersion() +{ + try + { + std::string dotnetInfo = (exec_and_read_output(L"dotnet --list-runtimes")).value(); + if (dotnetInfo.empty()) + { + return "Unknown .NET Version"; + } + + std::regex versionRegex(R"((\d+\.\d+\.\d+))"); + std::sregex_iterator begin(dotnetInfo.begin(), dotnetInfo.end(), versionRegex), end; + + std::string latestVersion; + for (std::sregex_iterator i = begin; i != end; ++i) + { + std::string version = (*i).str(); + if (version > latestVersion) + { + latestVersion = version; + } + } + + return latestVersion.empty() ? "Unknown .NET Version" : ".NET " + latestVersion; + } + catch (const std::exception& e) + { + return "Failed to get .NET Version: " + std::string(e.what()); + } +} + + +std::string GetOSVersion() +{ + OSVERSIONINFOEXW osInfo = { 0 }; + try + { + NTSTATUS(WINAPI * RtlGetVersion) + (LPOSVERSIONINFOEXW) = nullptr; + *reinterpret_cast(&RtlGetVersion) = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion"); + if (RtlGetVersion) + { + osInfo.dwOSVersionInfoSize = sizeof(osInfo); + RtlGetVersion(&osInfo); + } + } + catch (...) + { + std::cerr << "Failed to get Windows version info\n"; + return "Unknown Windows Version"; + } + + try + { + std::ostringstream osVersion; + osVersion << osInfo.dwMajorVersion << "." << osInfo.dwMinorVersion << "." << osInfo.dwBuildNumber; + return osVersion.str(); + } + catch (...) + { + std::cerr << "Failed to format Windows version info\n"; + return "Unknown Windows Version"; + } +} + + +std::string GetModuleFolderPath() +{ + char buffer[MAX_PATH]; + GetModuleFileNameA(NULL, buffer, MAX_PATH); + std::string::size_type pos = std::string(buffer).find_last_of("\\/"); + return std::string(buffer).substr(0, pos); } diff --git a/src/runner/bug_report.h b/src/runner/bug_report.h index 2d7084ea2134..2028dae88a0d 100644 --- a/src/runner/bug_report.h +++ b/src/runner/bug_report.h @@ -1,3 +1,19 @@ #pragma once +#include +#include +#include +#include +#include -void launch_bug_report() noexcept; \ No newline at end of file +void InitializeReportBugLinkAsync(); +std::string LaunchBugReport(); +std::string FindNewestBugReportFile(); +std::string GetDotNetVersion(); +std::string GetOSVersion(); +std::string GetModuleFolderPath(); +std::string WideStringToString(const std::wstring& wstr); +std::wstring stringToWideString(const std::string& str); +void ShowLoadingMessage(); +void CancelBugReport(std::promise& cancelPromise); + +extern std::atomic_bool isBugReportThreadRunning; diff --git a/src/runner/settings_window.cpp b/src/runner/settings_window.cpp index 8a99290f2d98..c39e995534b2 100644 --- a/src/runner/settings_window.cpp +++ b/src/runner/settings_window.cpp @@ -223,7 +223,7 @@ void dispatch_received_json(const std::wstring& json_to_parse) } else if (name == L"bugreport") { - launch_bug_report(); + InitializeReportBugLinkAsync(); } else if (name == L"killrunner") { diff --git a/src/runner/tray_icon.cpp b/src/runner/tray_icon.cpp index 015fb158b8d3..962a5b98c067 100644 --- a/src/runner/tray_icon.cpp +++ b/src/runner/tray_icon.cpp @@ -101,7 +101,7 @@ void handle_tray_command(HWND window, const WPARAM command_id, LPARAM lparam) break; case ID_REPORT_BUG_COMMAND: { - launch_bug_report(); + InitializeReportBugLinkAsync(); break; } diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index f9ae0bb6e7df..ac2c3f9e4ae4 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -362,10 +362,57 @@ private string FindNewestBugReportFile() return newestFile?.Name; } - private string GetDotNetVersion() + public static string GetDotNetVersion() { - var dotNetVersion = RuntimeInformation.FrameworkDescription; - return dotNetVersion.ToString(); + var output = ExecuteCommand("dotnet --list-runtimes"); + if (string.IsNullOrEmpty(output)) + { + return "Unknown .NET Version"; + } + + var versions = output + .Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries) + .Select(line => + { + var versionString = line.Split(' ')[1]; + if (Version.TryParse(versionString, out var version)) + { + return version; + } + + return new Version(0, 0, 0); + }) + .Where(version => version > new Version(0, 0, 0)) + .ToList(); + + var latestVersion = versions.Max(); + return $".NET {latestVersion}"; + } + + private static string ExecuteCommand(string command) + { + try + { + var process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "cmd.exe", + Arguments = $"/C {command}", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + }, + }; + + process.Start(); + using var reader = process.StandardOutput; + return reader.ReadToEnd(); + } + catch (Exception ex) + { + return $"Failed to execute command: {ex.Message}"; + } } private string GetOSVersion() @@ -376,6 +423,11 @@ private string GetOSVersion() if (attrData.ContainsKey("OSVersionFull")) { osVersion = attrData["OSVersionFull"]; + var versionParts = osVersion.Split('.'); + if (versionParts.Length >= 3) + { + osVersion = $"{versionParts[0]}.{versionParts[1]}.{versionParts[2]}"; + } } return osVersion.ToString(); From 0b0e8333a10e5e16b0f84ff715b86074674eb432 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 14 Jun 2024 14:16:00 +0300 Subject: [PATCH 21/30] [BugReport] Spellcheck. --- .github/ISSUE_TEMPLATE/bug_report.yml | 4 +-- .github/actions/spell-check/expect.txt | 3 ++ src/runner/bug_report.cpp | 34 ++++++------------- .../ViewModels/GeneralViewModel.cs | 6 ++-- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 691a96f960c5..1274d6448d6d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -33,7 +33,7 @@ body: validations: required: true -- id: iselevated +- id: isElevated type: input attributes: label: Running as admin @@ -105,7 +105,7 @@ body: validations: required: false -- id: othersoftware +- id: otherSoftware type: textarea attributes: label: Other Software diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index a3ceb9fe4578..3caa52fff48b 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -370,6 +370,7 @@ drivedetectionwarning dshow DSTINVERT DUMMYUNIONNAME +dupenv dutil DVASPECT DVASPECTINFO @@ -635,7 +636,9 @@ IBeam ICapture IClass ICONERROR +ICONINFORMATION IData +IDCANCEL IDD IDesktop IDirect diff --git a/src/runner/bug_report.cpp b/src/runner/bug_report.cpp index ed42bd8d4eee..53824e1fbbbd 100644 --- a/src/runner/bug_report.cpp +++ b/src/runner/bug_report.cpp @@ -6,18 +6,8 @@ #include #include #include -#include -#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include #include @@ -62,7 +52,7 @@ std::string LaunchBugReport() } else { - std::cerr << "Failed to start bug report tool." << std::endl; + bugReportFileName = "Failed to start bug report tool."; } isBugReportThreadRunning.store(false); @@ -101,9 +91,9 @@ HWND GetMessageBoxHandle() DWORD WINAPI ShowCancelableMessageBox(LPVOID /*lpParam*/) { - int msgboxID = MessageBox(nullptr, L"Generating bug report, please wait...", L"BugReport", MB_OKCANCEL | MB_ICONINFORMATION); + int msgBoxID = MessageBox(nullptr, L"Generating bug report, please wait...", L"BugReport", MB_OKCANCEL | MB_ICONINFORMATION); - if (msgboxID == IDCANCEL) + if (msgBoxID == IDCANCEL) { cancelPromise.set_value(); canceled.store(true); @@ -155,20 +145,20 @@ void InitializeReportBugLinkAsync() if (!bugReportResult.empty()) { - std::wstring wversion = get_product_version(); + std::wstring wVersion = get_product_version(); std::string version; - std::transform(wversion.begin() + 1, wversion.end(), std::back_inserter(version), [](wchar_t c) { + std::transform(wVersion.begin() + 1, wVersion.end(), std::back_inserter(version), [](wchar_t c) { return static_cast(c); }); - std::string otherSoftware = "OS Build Version: " + GetOSVersion() + "\n.NET Version: " + GetDotNetVersion(); + std::string otherSoftware = "OS Build Version: " + GetOSVersion() + "%0a" + ".NET Version: " + GetDotNetVersion(); GeneralSettings generalSettings = get_general_settings(); std::string isElevatedRun = generalSettings.isElevated ? "Yes" : "No"; - gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + + gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + std::string("&version=") + version + - std::string("&othersoftware=") + otherSoftware + - std::string("&iselevated=") + isElevatedRun; + std::string("&otherSoftware=") + otherSoftware + + std::string("&isElevated=") + isElevatedRun; std::wstring wideBugReportResult = stringToWideString(bugReportResult); MessageBox(nullptr, L"Bug report generated on your desktop. Please attach the file to the GitHub issue.", wideBugReportResult.c_str(), MB_OKCANCEL | MB_ICONINFORMATION); @@ -186,8 +176,8 @@ void InitializeReportBugLinkAsync() } // Open the URL - std::wstring wgitHubURL(gitHubURL.begin(), gitHubURL.end()); - ShellExecuteW(nullptr, L"open", wgitHubURL.c_str(), nullptr, nullptr, SW_SHOWNORMAL); + std::wstring wGitHubURL(gitHubURL.begin(), gitHubURL.end()); + ShellExecuteW(nullptr, L"open", wGitHubURL.c_str(), nullptr, nullptr, SW_SHOWNORMAL); } std::string FindNewestBugReportFile() @@ -316,7 +306,6 @@ std::string GetOSVersion() } catch (...) { - std::cerr << "Failed to get Windows version info\n"; return "Unknown Windows Version"; } @@ -328,7 +317,6 @@ std::string GetOSVersion() } catch (...) { - std::cerr << "Failed to format Windows version info\n"; return "Unknown Windows Version"; } } diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index ac2c3f9e4ae4..1c808f481128 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -243,10 +243,10 @@ public async Task InitializeReportBugLinkAsync() // Bug report task completed string reportResult = await bugReportTask; - gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + + gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + "&version=" + version + - "&othersoftware=" + otherSoftware + - "&iselevated=" + HttpUtility.UrlEncode(isElevatedRun); + "&otherSoftware=" + otherSoftware + + "&isElevated=" + HttpUtility.UrlEncode(isElevatedRun); var dialog = new ContentDialog { From 2d452c8eb3ed025cd31e80f5564a0fca2888cd46 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 14 Jun 2024 14:30:31 +0300 Subject: [PATCH 22/30] [BugReport] Minor check. --- src/runner/bug_report.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/runner/bug_report.cpp b/src/runner/bug_report.cpp index 53824e1fbbbd..b61d68ede0d3 100644 --- a/src/runner/bug_report.cpp +++ b/src/runner/bug_report.cpp @@ -184,7 +184,11 @@ std::string FindNewestBugReportFile() { char* desktopPathC; size_t len; - _dupenv_s(&desktopPathC, &len, "USERPROFILE"); + if (_dupenv_s(&desktopPathC, &len, "USERPROFILE") != 0 || desktopPathC == nullptr) + { + return ""; + } + std::string desktopPath(desktopPathC); free(desktopPathC); From 5b83154a200da7970cb01cba7f69033c8d972fb4 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Tue, 9 Jul 2024 15:54:01 +0300 Subject: [PATCH 23/30] [BugReport] Additional info field is added for systray bugreport --- .github/ISSUE_TEMPLATE/bug_report.yml | 22 ++-- src/runner/Resources.resx | 6 ++ src/runner/bug_report.cpp | 149 ++++++++++---------------- src/runner/bug_report.h | 3 +- 4 files changed, 77 insertions(+), 103 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 1274d6448d6d..4f74a5af2790 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -33,15 +33,6 @@ body: validations: required: true -- id: isElevated - type: input - attributes: - label: Running as admin - description: Are you running PowerToys as Admin? - placeholder: Yes - validations: - required: true - - type: dropdown attributes: label: Area(s) with issue? @@ -104,6 +95,19 @@ body: placeholder: What happened instead? validations: required: false + +- id: additionalInfo + type: textarea + attributes: + label: Additional Information + placeholder: | + OS version + .Net version + Preferred System Language + User or System Installation + Running as admin + validations: + required: false - id: otherSoftware type: textarea diff --git a/src/runner/Resources.resx b/src/runner/Resources.resx index 902e3a08740e..97b674770b48 100644 --- a/src/runner/Resources.resx +++ b/src/runner/Resources.resx @@ -134,4 +134,10 @@ Administrator + + Bug Report + + + Bug report is being generated + diff --git a/src/runner/bug_report.cpp b/src/runner/bug_report.cpp index b61d68ede0d3..910802f41a4f 100644 --- a/src/runner/bug_report.cpp +++ b/src/runner/bug_report.cpp @@ -1,17 +1,26 @@ #include "pch.h" #include "bug_report.h" #include "Generated files/resource.h" +#include #include #include #include +#include +#include #include #include + +#include +#include + + #include #include #include #include using namespace std; +using namespace registry::install_scope; namespace fs = std::filesystem; std::atomic_bool isBugReportThreadRunning = false; @@ -50,98 +59,25 @@ std::string LaunchBugReport() // Find the newest bug report file on the desktop bugReportFileName = FindNewestBugReportFile(); } - else - { - bugReportFileName = "Failed to start bug report tool."; - } isBugReportThreadRunning.store(false); } return bugReportFileName; } -BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM /*lParam*/) -{ - DWORD pid; - GetWindowThreadProcessId(hwnd, &pid); - if (pid == GetCurrentProcessId()) - { - wchar_t className[256]; - GetClassName(hwnd, className, 256); - if (wcscmp(className, L"#32770") == 0) // #32770 is the class name for MessageBox - { - wchar_t title[256]; - GetWindowText(hwnd, title, 256); - if (wcscmp(title, L"BugReport") == 0) - { - hwndMessageBox = hwnd; - return FALSE; // Stop enumerating windows - } - } - } - return TRUE; // Continue enumerating windows -} - -HWND GetMessageBoxHandle() -{ - hwndMessageBox = nullptr; - EnumWindows(EnumWindowsProc, 0); - return hwndMessageBox; -} - -DWORD WINAPI ShowCancelableMessageBox(LPVOID /*lpParam*/) -{ - int msgBoxID = MessageBox(nullptr, L"Generating bug report, please wait...", L"BugReport", MB_OKCANCEL | MB_ICONINFORMATION); - - if (msgBoxID == IDCANCEL) - { - cancelPromise.set_value(); - canceled.store(true); - } - - return 0; -} - void InitializeReportBugLinkAsync() { std::string gitHubURL; - - canceled.store(false); - cancelPromise = std::promise(); - auto cancelFuture = cancelPromise.get_future(); - - std::atomic bugReportCompleted{ false }; std::string bugReportResult; + notifications::show_toast(GET_RESOURCE_STRING(IDS_BUGREPORT_TEXT), GET_RESOURCE_STRING(IDS_BUGREPORT_TITLE)); + // Launch the bug report task - auto bugReportTask = std::async(std::launch::async, [&bugReportCompleted, &bugReportResult] { + auto bugReportTask = std::async(std::launch::async, [&bugReportResult] { bugReportResult = LaunchBugReport(); - bugReportCompleted.store(true); - - HWND hwnd = GetMessageBoxHandle(); - if (hwnd != nullptr) - { - SendMessage(hwnd, WM_CLOSE, 0, 0); - } - }); - - // Show the message box in a separate thread - HANDLE hThread = CreateThread(nullptr, 0, ShowCancelableMessageBox, nullptr, 0, nullptr); - - // Wait for either the bug report to finish or the user to take action - while (!bugReportCompleted.load()) - { - if (cancelFuture.wait_for(std::chrono::milliseconds(100)) == std::future_status::ready) - { - break; - } - } + }); - // Ensure bug report task completion - if (!bugReportCompleted.load()) - { - bugReportTask.wait(); - } + bugReportTask.wait(); if (!bugReportResult.empty()) { @@ -151,30 +87,31 @@ void InitializeReportBugLinkAsync() return static_cast(c); }); - std::string otherSoftware = "OS Build Version: " + GetOSVersion() + "%0a" + ".NET Version: " + GetDotNetVersion(); + std::string additionalInfo = "OS Build Version: " + GetOSVersion() + "%0a" + ".NET Version: " + GetDotNetVersion() + "\n"; GeneralSettings generalSettings = get_general_settings(); - std::string isElevatedRun = generalSettings.isElevated ? "Yes" : "No"; + std::string isElevatedRun = generalSettings.isElevated ? "Running as admin: Yes" : "Running as admin: No"; + + std::string windowsSettings = ReportWindowsSettings(); + + const InstallScope current_install_scope = get_current_install_scope(); + + std::string installScope = current_install_scope == InstallScope::PerUser ? "Installation : User" : "Installation : System"; - gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + + additionalInfo += windowsSettings + "\n" + installScope + "\n" + isElevatedRun; + + gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + std::string("&version=") + version + - std::string("&otherSoftware=") + otherSoftware + - std::string("&isElevated=") + isElevatedRun; + std::string("&additionalInfo=") + additionalInfo; - std::wstring wideBugReportResult = stringToWideString(bugReportResult); - MessageBox(nullptr, L"Bug report generated on your desktop. Please attach the file to the GitHub issue.", wideBugReportResult.c_str(), MB_OKCANCEL | MB_ICONINFORMATION); + std::wstring wideBugReportResult = L"Bug report generated on your desktop. Please attach the file to the GitHub issue.\n\n" + stringToWideString(bugReportResult); + MessageBox(nullptr, wideBugReportResult.c_str(), L"Bug Report", MB_OKCANCEL | MB_ICONINFORMATION); } else { + MessageBox(nullptr, L"Failed to start bug report tool.", L"Bug Report", MB_OKCANCEL | MB_ICONINFORMATION); gitHubURL = "https://aka.ms/powerToysReportBug"; } - // Wait for the message box thread to complete - if (hThread != nullptr) - { - WaitForSingleObject(hThread, INFINITE); - CloseHandle(hThread); - } - // Open the URL std::wstring wGitHubURL(gitHubURL.begin(), gitHubURL.end()); ShellExecuteW(nullptr, L"open", wGitHubURL.c_str(), nullptr, nullptr, SW_SHOWNORMAL); @@ -333,3 +270,31 @@ std::string GetModuleFolderPath() std::string::size_type pos = std::string(buffer).find_last_of("\\/"); return std::string(buffer).substr(0, pos); } + +std::string ReportWindowsSettings() +{ + std::wstring userLanguage; + std::wstring userLocale; + std::string result; + + try + { + const auto lang = winrt::Windows::System::UserProfile::GlobalizationPreferences::Languages().GetAt(0); + userLanguage = winrt::Windows::Globalization::Language{ lang }.DisplayName().c_str(); + wchar_t localeName[LOCALE_NAME_MAX_LENGTH]{}; + if (!LCIDToLocaleName(GetThreadLocale(), localeName, LOCALE_NAME_MAX_LENGTH, 0)) + { + throw -1; + } + userLocale = localeName; + } + catch (...) + { + return "Failed to get windows settings\n"; + } + + result = "Preferred user language: " + WideStringToString(userLanguage) + "\n"; + result += "User locale: " + WideStringToString(userLocale) + "\n"; + + return result; +} \ No newline at end of file diff --git a/src/runner/bug_report.h b/src/runner/bug_report.h index 2028dae88a0d..4e0f563e5d16 100644 --- a/src/runner/bug_report.h +++ b/src/runner/bug_report.h @@ -13,7 +13,6 @@ std::string GetOSVersion(); std::string GetModuleFolderPath(); std::string WideStringToString(const std::wstring& wstr); std::wstring stringToWideString(const std::string& str); -void ShowLoadingMessage(); -void CancelBugReport(std::promise& cancelPromise); +std::string ReportWindowsSettings(); extern std::atomic_bool isBugReportThreadRunning; From 18141c9ec20f3313516a1ec966511ef706620e2c Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Tue, 9 Jul 2024 16:46:13 +0300 Subject: [PATCH 24/30] [BugReport] Additional info field is added for general settings button. --- src/runner/bug_report.cpp | 10 +-- .../ViewModels/GeneralViewModel.cs | 80 ++++++++++++++++--- 2 files changed, 75 insertions(+), 15 deletions(-) diff --git a/src/runner/bug_report.cpp b/src/runner/bug_report.cpp index 910802f41a4f..caa6abc5f4ab 100644 --- a/src/runner/bug_report.cpp +++ b/src/runner/bug_report.cpp @@ -87,7 +87,7 @@ void InitializeReportBugLinkAsync() return static_cast(c); }); - std::string additionalInfo = "OS Build Version: " + GetOSVersion() + "%0a" + ".NET Version: " + GetDotNetVersion() + "\n"; + std::string additionalInfo = "OS Build Version: " + GetOSVersion() + "%0a" + ".NET Version: " + GetDotNetVersion() + "%0a%0a"; GeneralSettings generalSettings = get_general_settings(); std::string isElevatedRun = generalSettings.isElevated ? "Running as admin: Yes" : "Running as admin: No"; @@ -97,7 +97,7 @@ void InitializeReportBugLinkAsync() std::string installScope = current_install_scope == InstallScope::PerUser ? "Installation : User" : "Installation : System"; - additionalInfo += windowsSettings + "\n" + installScope + "\n" + isElevatedRun; + additionalInfo += windowsSettings + "%0a" + installScope + "%0a" + isElevatedRun; gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + std::string("&version=") + version + @@ -290,11 +290,11 @@ std::string ReportWindowsSettings() } catch (...) { - return "Failed to get windows settings\n"; + return "Failed to get windows settings %0a"; } - result = "Preferred user language: " + WideStringToString(userLanguage) + "\n"; - result += "User locale: " + WideStringToString(userLocale) + "\n"; + result = "Preferred user language: " + WideStringToString(userLanguage) + "%0a"; + result += "User locale: " + WideStringToString(userLocale) + "%0a"; return result; } \ No newline at end of file diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 1c808f481128..64c98bd60b15 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -11,14 +11,11 @@ using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Text.Json; using System.Threading; using System.Threading.Tasks; using System.Web; using System.Windows; -using System.Windows.Interop; -using System.Windows.Threading; using CommunityToolkit.Common; using CommunityToolkit.Mvvm.Input; using global::PowerToys.GPOWrapper; @@ -30,8 +27,9 @@ using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; using Microsoft.UI.Xaml.Controls; +using Microsoft.Win32; +using Windows.Globalization; using Windows.System.Profile; -using Windows.UI.Core; namespace Microsoft.PowerToys.Settings.UI.ViewModels { @@ -199,6 +197,14 @@ public GeneralViewModel(ISettingsRepository settingsRepository, private string reportBugLink = "https://aka.ms/powerToysReportBug"; + public enum InstallScope + { + PerMachine = 0, + PerUser, + } + + private const string InstallScopeRegKey = @"Software\Classes\powertoys\"; + // Gets or sets a value indicating whether run powertoys on start-up. public string ReportBugLink { @@ -214,9 +220,17 @@ public async Task InitializeReportBugLinkAsync() { string gitHubURL = string.Empty; var version = HttpUtility.UrlEncode(Helper.GetProductVersion().TrimStart('v')); - var otherSoftwareText = "OS Build Version: " + GetOSVersion() + "\n.NET Version: " + GetDotNetVersion(); - var otherSoftware = HttpUtility.UrlEncode(otherSoftwareText); - var isElevatedRun = IsElevated ? "Yes" : "No"; + + var otherSoftwareText = "OS Build Version: " + GetOSVersion() + "\n.NET Version: " + GetDotNetVersion() + "\n\n"; + var additionalInfo = HttpUtility.UrlEncode(otherSoftwareText); + var isElevatedRun = IsElevated ? "Running as admin: Yes" : "Running as admin: No"; + var windowsSettings = ReportWindowsSettings(); + + var current_install_scope = GetCurrentInstallScope(); + + var installScope = current_install_scope == InstallScope.PerUser ? "Installation : User" : "Installation : System"; + + additionalInfo += windowsSettings + "%0a" + installScope + "%0a" + isElevatedRun; var loadingMessage = new LoadingMessage(); loadingMessage.XamlRoot = App.GetSettingsWindow().Content.XamlRoot; @@ -243,10 +257,9 @@ public async Task InitializeReportBugLinkAsync() // Bug report task completed string reportResult = await bugReportTask; - gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + + gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + "&version=" + version + - "&otherSoftware=" + otherSoftware + - "&isElevated=" + HttpUtility.UrlEncode(isElevatedRun); + "&additionalInfo=" + additionalInfo; var dialog = new ContentDialog { @@ -433,6 +446,53 @@ private string GetOSVersion() return osVersion.ToString(); } + public static string ReportWindowsSettings() + { + string userLanguage; + string userLocale; + string result; + + try + { + var languages = ApplicationLanguages.Languages; + userLanguage = new Language(languages[0]).DisplayName; + + userLocale = CultureInfo.CurrentCulture.Name; + } + catch (Exception) + { + return "Failed to get windows settings\n"; + } + + result = "Preferred user language: " + userLanguage + "%0a"; + result += "User locale: " + userLocale + "%0a"; + + return result; + } + + public static InstallScope GetCurrentInstallScope() + { + // Check HKLM first + if (Registry.LocalMachine.OpenSubKey(InstallScopeRegKey) != null) + { + return InstallScope.PerMachine; + } + + // If not found, check HKCU + var userKey = Registry.CurrentUser.OpenSubKey(InstallScopeRegKey); + if (userKey != null) + { + var installScope = userKey.GetValue("InstallScope") as string; + userKey.Close(); + if (!string.IsNullOrEmpty(installScope) && installScope.Contains("perUser")) + { + return InstallScope.PerUser; + } + } + + return InstallScope.PerMachine; // Default if no specific registry key found + } + public bool Startup { get From 58c5a6f201eef70c786d738800de0b405404cffa Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Fri, 12 Jul 2024 16:14:44 +0300 Subject: [PATCH 25/30] [BugReport] Github link replaced. --- src/runner/bug_report.cpp | 2 +- src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runner/bug_report.cpp b/src/runner/bug_report.cpp index caa6abc5f4ab..27593ea738c7 100644 --- a/src/runner/bug_report.cpp +++ b/src/runner/bug_report.cpp @@ -99,7 +99,7 @@ void InitializeReportBugLinkAsync() additionalInfo += windowsSettings + "%0a" + installScope + "%0a" + isElevatedRun; - gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + + gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + std::string("&version=") + version + std::string("&additionalInfo=") + additionalInfo; diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 64c98bd60b15..eacf5e2511d1 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -257,7 +257,7 @@ public async Task InitializeReportBugLinkAsync() // Bug report task completed string reportResult = await bugReportTask; - gitHubURL = "https://github.com/gokcekantarci/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + + gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + "&version=" + version + "&additionalInfo=" + additionalInfo; From 37b373f84272f4503232ce6877209bac608abbda Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Tue, 23 Jul 2024 13:10:02 +0300 Subject: [PATCH 26/30] [BugReport] Minor changes made to comments in PR have been implemented. --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- src/runner/bug_report.cpp | 4 ++-- .../Controls/SettingsPageControl/LoadingMessage.xaml | 4 +--- .../Settings.UI/SettingsXAML/Views/GeneralPage.xaml | 6 +++--- src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs | 4 ++-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 4f74a5af2790..f2f478cb4a7b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -103,7 +103,7 @@ body: placeholder: | OS version .Net version - Preferred System Language + System Language User or System Installation Running as admin validations: diff --git a/src/runner/bug_report.cpp b/src/runner/bug_report.cpp index 27593ea738c7..721eb3df385a 100644 --- a/src/runner/bug_report.cpp +++ b/src/runner/bug_report.cpp @@ -293,8 +293,8 @@ std::string ReportWindowsSettings() return "Failed to get windows settings %0a"; } - result = "Preferred user language: " + WideStringToString(userLanguage) + "%0a"; - result += "User locale: " + WideStringToString(userLocale) + "%0a"; + result = "System Language: " + WideStringToString(userLanguage) + "%0a"; + result += "User Locale: " + WideStringToString(userLocale) + "%0a"; return result; } \ No newline at end of file diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml index 936ee84a309d..82c964f6a4f1 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml @@ -7,12 +7,10 @@ DefaultButton="Primary"> + Margin="8"/> diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml index becee6fc985d..e4556bffa011 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml @@ -365,13 +365,13 @@ - - + + - + diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index eacf5e2511d1..0d112c03f70b 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -464,8 +464,8 @@ public static string ReportWindowsSettings() return "Failed to get windows settings\n"; } - result = "Preferred user language: " + userLanguage + "%0a"; - result += "User locale: " + userLocale + "%0a"; + result = "System Language: " + userLanguage + "%0a"; + result += "User Locale: " + userLocale + "%0a"; return result; } From 9422b1a95eb8d8a2aa7b91a18c6228444110c6e6 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Fri, 26 Jul 2024 10:51:54 +0100 Subject: [PATCH 27/30] Fix XAML style --- .../SettingsPageControl/LoadingMessage.xaml | 20 ++++++++++--------- .../SettingsPageControl/PageLink.xaml | 13 +++++++----- .../SettingsXAML/Views/GeneralPage.xaml | 9 +++++---- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml index 82c964f6a4f1..1b00403251f1 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/LoadingMessage.xaml @@ -1,16 +1,18 @@ - + DefaultButton="Primary" + PrimaryButtonText="Cancel"> - - + + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml index 13b626ede95c..fe63532889f1 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/SettingsPageControl/PageLink.xaml @@ -1,14 +1,17 @@ - + d:DesignWidth="200" + mc:Ignorable="d"> - + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml index 60c61696a54f..9698cf6e6e85 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml @@ -368,10 +368,11 @@ - + From b1aa218c6c93bd4cefb3f4f8c3e4c0fc9df45d8c Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Thu, 1 Aug 2024 17:12:15 +0300 Subject: [PATCH 28/30] [BugReport] New logs and error messages are added. Minor changes in PR comments have been implemented. --- src/runner/bug_report.cpp | 184 ++++++++++++++++++++++++++------------ src/runner/bug_report.h | 2 +- 2 files changed, 126 insertions(+), 60 deletions(-) diff --git a/src/runner/bug_report.cpp b/src/runner/bug_report.cpp index 721eb3df385a..88b20ac0297e 100644 --- a/src/runner/bug_report.cpp +++ b/src/runner/bug_report.cpp @@ -13,116 +13,171 @@ #include #include - #include #include #include -#include using namespace std; using namespace registry::install_scope; namespace fs = std::filesystem; std::atomic_bool isBugReportThreadRunning = false; -std::mutex LockObject; -std::promise cancelPromise; -static std::atomic canceled{ false }; -static HWND hwndMessageBox = nullptr; -std::string LaunchBugReport() +std::string bugReportResult; + +bool LaunchBugReport() { - std::string bugReportFileName; std::wstring bug_report_path = get_module_folderpath(); bug_report_path += L"\\Tools\\PowerToys.BugReportTool.exe"; + Logger::info("Starting the bug report tool from {}", WideStringToString(bug_report_path)); - bool expected_isBugReportThreadRunning = false; - if (isBugReportThreadRunning.compare_exchange_strong(expected_isBugReportThreadRunning, true)) + bool success = true; + + try { SHELLEXECUTEINFOW sei{ sizeof(sei) }; sei.fMask = { SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE }; sei.lpFile = bug_report_path.c_str(); sei.nShow = SW_HIDE; + if (ShellExecuteExW(&sei)) { - while (WaitForSingleObject(sei.hProcess, 100) == WAIT_TIMEOUT) - { - if (canceled.load()) - { - TerminateProcess(sei.hProcess, 0); - CloseHandle(sei.hProcess); - isBugReportThreadRunning.store(false); - return ""; - } - } + WaitForSingleObject(sei.hProcess, INFINITE); CloseHandle(sei.hProcess); // Find the newest bug report file on the desktop - bugReportFileName = FindNewestBugReportFile(); + bugReportResult = FindNewestBugReportFile(); + Logger::info("Bug report generated: {}", bugReportResult); } + else + { + bugReportResult = "Failed to start bug report tool."; + auto message = get_last_error_message(GetLastError()); - isBugReportThreadRunning.store(false); + if (message.has_value()) + { + bugReportResult = "Failed to start bug report tool. Internal error: " + WideStringToString(message.value()); + } + else + { + bugReportResult = "Failed to start bug report tool with unknown error."; + } + success = false; + } } - return bugReportFileName; + catch (std::exception& ex) + { + bugReportResult = std::string{ ex.what() }; + Logger::error("Exception caught in LaunchBugReport: {}", ex.what()); + success = false; + } + + isBugReportThreadRunning.store(false); + + return success; } void InitializeReportBugLinkAsync() { - std::string gitHubURL; - std::string bugReportResult; + bool expected_isBugReportThreadRunning = false; + + try + { + if (isBugReportThreadRunning.compare_exchange_strong(expected_isBugReportThreadRunning, true)) + { + std::thread([] { + std::string gitHubURL; + bool launchBugReportResult; - notifications::show_toast(GET_RESOURCE_STRING(IDS_BUGREPORT_TEXT), GET_RESOURCE_STRING(IDS_BUGREPORT_TITLE)); + notifications::show_toast(GET_RESOURCE_STRING(IDS_BUGREPORT_TEXT), GET_RESOURCE_STRING(IDS_BUGREPORT_TITLE)); - // Launch the bug report task - auto bugReportTask = std::async(std::launch::async, [&bugReportResult] { - bugReportResult = LaunchBugReport(); - }); + // Launch the bug report task + auto bugReportTask = std::async(std::launch::async, [&launchBugReportResult] { + launchBugReportResult = LaunchBugReport(); + }); - bugReportTask.wait(); - - if (!bugReportResult.empty()) - { - std::wstring wVersion = get_product_version(); - std::string version; - std::transform(wVersion.begin() + 1, wVersion.end(), std::back_inserter(version), [](wchar_t c) { - return static_cast(c); - }); + bugReportTask.wait(); - std::string additionalInfo = "OS Build Version: " + GetOSVersion() + "%0a" + ".NET Version: " + GetDotNetVersion() + "%0a%0a"; - GeneralSettings generalSettings = get_general_settings(); - std::string isElevatedRun = generalSettings.isElevated ? "Running as admin: Yes" : "Running as admin: No"; + if (launchBugReportResult && !bugReportResult.empty()) + { + Logger::info("Bug report successfully generated."); + + std::wstring wVersion = get_product_version(); + std::string version; + std::transform(wVersion.begin() + 1, wVersion.end(), std::back_inserter(version), [](wchar_t c) { + return static_cast(c); + }); + + std::string additionalInfo = "OS Build Version: " + GetOSVersion() + "%0a" + ".NET Version: " + GetDotNetVersion() + "%0a%0a"; + GeneralSettings generalSettings = get_general_settings(); + std::string isElevatedRun = generalSettings.isElevated ? "Running as admin: Yes" : "Running as admin: No"; + + std::string windowsSettings = ReportWindowsSettings(); - std::string windowsSettings = ReportWindowsSettings(); + const InstallScope current_install_scope = get_current_install_scope(); - const InstallScope current_install_scope = get_current_install_scope(); + std::string installScope = current_install_scope == InstallScope::PerUser ? "Installation : User" : "Installation : System"; - std::string installScope = current_install_scope == InstallScope::PerUser ? "Installation : User" : "Installation : System"; + additionalInfo += windowsSettings + "%0a" + installScope + "%0a" + isElevatedRun; - additionalInfo += windowsSettings + "%0a" + installScope + "%0a" + isElevatedRun; + gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + + std::string("&version=") + version + + std::string("&additionalInfo=") + additionalInfo; + + std::wstring wideBugReportResult = L"Bug report generated on your desktop. Please attach the file to the GitHub issue.\n\n" + stringToWideString(bugReportResult); + MessageBox(nullptr, wideBugReportResult.c_str(), L"Bug Report", MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND); + } + else + { + std::wstring message; - gitHubURL = "https://github.com/microsoft/PowerToys/issues/new?assignees=&labels=Issue-Bug%2CNeeds-Triage&template=bug_report.yml" + - std::string("&version=") + version + - std::string("&additionalInfo=") + additionalInfo; + if (bugReportResult.empty()) + { + message = L" Failed to generate bug report. bugReportResult is empty."; + } + else + { - std::wstring wideBugReportResult = L"Bug report generated on your desktop. Please attach the file to the GitHub issue.\n\n" + stringToWideString(bugReportResult); - MessageBox(nullptr, wideBugReportResult.c_str(), L"Bug Report", MB_OKCANCEL | MB_ICONINFORMATION); + // Convert std::string to std::wstring + std::wstring wideBugReportResult = stringToWideString(bugReportResult); + + // Prepare the message + message = L"LaunchBugReport failed: " + wideBugReportResult; + + } + + Logger::error(message); + + MessageBox(nullptr, message.c_str(), L"Bug Report", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); + gitHubURL = "https://aka.ms/powerToysReportBug"; + } + + // Open the URL + std::wstring wGitHubURL(gitHubURL.begin(), gitHubURL.end()); + ShellExecuteW(nullptr, L"open", wGitHubURL.c_str(), nullptr, nullptr, SW_SHOWNORMAL); + }).detach(); + } + else + { + Logger::warn("Bug report thread is already running."); + } } - else + catch (std::exception& ex) { - MessageBox(nullptr, L"Failed to start bug report tool.", L"Bug Report", MB_OKCANCEL | MB_ICONINFORMATION); - gitHubURL = "https://aka.ms/powerToysReportBug"; + Logger::error("Exception in InitializeReportBugLinkAsync: {}", ex.what()); } - - // Open the URL - std::wstring wGitHubURL(gitHubURL.begin(), gitHubURL.end()); - ShellExecuteW(nullptr, L"open", wGitHubURL.c_str(), nullptr, nullptr, SW_SHOWNORMAL); } std::string FindNewestBugReportFile() { char* desktopPathC; size_t len; + + Logger::info("Searching for the newest bug report file on the desktop."); + if (_dupenv_s(&desktopPathC, &len, "USERPROFILE") != 0 || desktopPathC == nullptr) { + Logger::error("Failed to get USERPROFILE environment variable."); return ""; } @@ -134,6 +189,8 @@ std::string FindNewestBugReportFile() if (!fs::exists(desktopDir) || !fs::is_directory(desktopDir)) { + Logger::error("Desktop directory not found or is not a directory: {}", desktopPath); + return ""; } @@ -142,7 +199,7 @@ std::string FindNewestBugReportFile() for (const auto& entry : fs::directory_iterator(desktopDir)) { - if (entry.is_regular_file() && entry.path().filename().string().find("PowerToysReport_") == 0) + if (entry.is_regular_file() && entry.path().filename().wstring().find(L"PowerToysReport_") == 0) { std::time_t fileTime = fs::last_write_time(entry).time_since_epoch().count(); if (fileTime > newestTime) @@ -153,6 +210,15 @@ std::string FindNewestBugReportFile() } } + if (newestFile.empty()) + { + Logger::warn("No bug report files found on the desktop."); + } + else + { + Logger::info("Newest bug report file found: " + newestFile); + } + return newestFile; } diff --git a/src/runner/bug_report.h b/src/runner/bug_report.h index 4e0f563e5d16..43f245090b84 100644 --- a/src/runner/bug_report.h +++ b/src/runner/bug_report.h @@ -6,7 +6,7 @@ #include void InitializeReportBugLinkAsync(); -std::string LaunchBugReport(); +bool LaunchBugReport(); std::string FindNewestBugReportFile(); std::string GetDotNetVersion(); std::string GetOSVersion(); From b9c5173b5e522689c8f7e5b1a9858463b41a61b1 Mon Sep 17 00:00:00 2001 From: Gokce Kantarci Date: Thu, 26 Sep 2024 15:22:24 +0300 Subject: [PATCH 29/30] [BugReport] SpellCheck. --- src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 224b2a5c31aa..2833c0098d6b 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -509,7 +509,7 @@ public static string ReportWindowsSettings() } catch (Exception ex) { - Logger.LogError($"Failed to get windows settingsd: {ex.Message}"); + Logger.LogError($"Failed to get windows settings: {ex.Message}"); return "Failed to get windows settings\n"; } From ad5217df27a9ca07cbd2ab3e43a953853a61abe2 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Fri, 25 Oct 2024 14:52:23 +0100 Subject: [PATCH 30/30] Fix merge issues --- src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 026d06cb6e5a..975ac7cf305c 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -9,6 +9,7 @@ using System.Globalization; using System.IO; using System.IO.Abstractions; +using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Text.Json; @@ -28,11 +29,11 @@ using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using Microsoft.PowerToys.Telemetry; using Microsoft.UI.Xaml.Controls; using Microsoft.Win32; using Windows.Globalization; using Windows.System.Profile; -using Microsoft.PowerToys.Telemetry; namespace Microsoft.PowerToys.Settings.UI.ViewModels {