From cb49a91bc39c5b1deb16fba9d7951780c334f37d Mon Sep 17 00:00:00 2001 From: Ognjen Sobajic Date: Tue, 12 Mar 2024 20:21:27 -0700 Subject: [PATCH 1/8] Some progress on Experimental --- wv2util/AppState.cs | 3 ++ wv2util/ExperimentalFeature.cs | 79 ++++++++++++++++++++++++++++++++++ wv2util/MainWindow.xaml | 37 +++++++++++++--- wv2util/MainWindow.xaml.cs | 5 +++ wv2util/wv2util.csproj | 1 + 5 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 wv2util/ExperimentalFeature.cs diff --git a/wv2util/AppState.cs b/wv2util/AppState.cs index a688900..2d5dccd 100644 --- a/wv2util/AppState.cs +++ b/wv2util/AppState.cs @@ -11,6 +11,9 @@ public class AppState private static AppOverrideList s_AppOverrideList = new AppOverrideList(); public static AppOverrideList GetAppOverrideList() => s_AppOverrideList; + private static ExperimentalFeatureList s_ExperimentalFeatureList = new ExperimentalFeatureList(); + public static ExperimentalFeatureList GetExperimentalFeatureList() => s_ExperimentalFeatureList; + private static RuntimeList s_RuntimeList = new RuntimeList(); public static RuntimeList GetRuntimeList() => s_RuntimeList; diff --git a/wv2util/ExperimentalFeature.cs b/wv2util/ExperimentalFeature.cs new file mode 100644 index 0000000..cadd275 --- /dev/null +++ b/wv2util/ExperimentalFeature.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace wv2util +{ + public class ExperimentalFeature : IEquatable, IComparable + { + public string Name { get; set; } + + public bool isEnabled; + + public bool IsEnabled + { + get { return isEnabled; } + set + { + if (value) + { + turnOn(); + } + else + { + turnOff(); + } + isEnabled = value; + } + } + + public string Description { get; set; } + + private Action turnOn, turnOff; + + public ExperimentalFeature(Action turnOn, Action turnOff) + { + this.turnOn = turnOn; + this.turnOff = turnOff; + } + + static public bool IsEnabledForApp(string commandLine, string envVars) + { + // TODO implement + return false; + } + + public int CompareTo(ExperimentalFeature other) + { + return Name.CompareTo(other.Name); + } + + public bool Equals(ExperimentalFeature other) + { + return Name.Equals(other.Name); + } + } + + public class ExperimentalFeatureList : ObservableCollection + { + private List m_List = new List(); + + public ExperimentalFeatureList() + { + Items.Add(new ExperimentalFeature( + () => { }, + () => { }) { Name = "Hosting", IsEnabled = true }); + Items.Add(new ExperimentalFeature(() => { }, () => { }) { Name = "Canary", IsEnabled = false }); + } + + public List GetList() + { + return m_List; + } + + public IDisposable Subscribe(IObserver observer) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/wv2util/MainWindow.xaml b/wv2util/MainWindow.xaml index 6493848..094b0a6 100644 --- a/wv2util/MainWindow.xaml +++ b/wv2util/MainWindow.xaml @@ -9,9 +9,10 @@ Title="WebView2Utilities" Height="700" Width="1100" ResizeMode="CanResizeWithGrip" MinWidth="662" MinHeight="360"> - - - + + + + @@ -246,7 +247,7 @@ - + @@ -261,7 +262,7 @@ - + @@ -349,6 +350,32 @@ + + + + + + + + + + + + + Name + + + IsEnabled + + + + + + + + + diff --git a/wv2util/MainWindow.xaml.cs b/wv2util/MainWindow.xaml.cs index 4b26d55..4d2a847 100644 --- a/wv2util/MainWindow.xaml.cs +++ b/wv2util/MainWindow.xaml.cs @@ -120,6 +120,11 @@ private void HostAppsGoToOverride_Click(object sender, RoutedEventArgs e) } } + private void ExperimentalFeatureListViewSelectionChanged(object sender, SelectionChangedEventArgs e) + { + //todo + } + private void RuntimeListViewSelectionChanged(object sender, SelectionChangedEventArgs e) { if (RuntimeList.SelectedIndex >= 0) diff --git a/wv2util/wv2util.csproj b/wv2util/wv2util.csproj index 73c577a..88c859c 100644 --- a/wv2util/wv2util.csproj +++ b/wv2util/wv2util.csproj @@ -113,6 +113,7 @@ CreateReportWindow.xaml + From 952a316be94d53fc394c6c6f09674a4c9aa77858 Mon Sep 17 00:00:00 2001 From: Ognjen Sobajic Date: Tue, 12 Mar 2024 23:41:51 -0700 Subject: [PATCH 2/8] Finish the Experimental tab feature --- wv2util/ExperimentalFeature.cs | 59 ++++++++++++++++++++++++++-------- wv2util/MainWindow.xaml | 14 ++++++-- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/wv2util/ExperimentalFeature.cs b/wv2util/ExperimentalFeature.cs index cadd275..4b6ae80 100644 --- a/wv2util/ExperimentalFeature.cs +++ b/wv2util/ExperimentalFeature.cs @@ -31,10 +31,11 @@ public bool IsEnabled private Action turnOn, turnOff; - public ExperimentalFeature(Action turnOn, Action turnOff) + public ExperimentalFeature(Action turnOn, Action turnOff, Func isOn) { this.turnOn = turnOn; this.turnOff = turnOff; + isEnabled = isOn(); } static public bool IsEnabledForApp(string commandLine, string envVars) @@ -54,26 +55,58 @@ public bool Equals(ExperimentalFeature other) } } + public class EnvVarExperimentalFeature : ExperimentalFeature + { + public EnvVarExperimentalFeature(string envVar, string onVal, string offVal) : base( + () => + { + // Turn on: + Environment.SetEnvironmentVariable(envVar, onVal, EnvironmentVariableTarget.User); + }, + () => + { + // Turn off: + Environment.SetEnvironmentVariable(envVar, offVal, EnvironmentVariableTarget.User); + }, + () => + { + string val = Environment.GetEnvironmentVariable(envVar, EnvironmentVariableTarget.User); + return val != null && val == onVal; + }) + { + } + } + public class ExperimentalFeatureList : ObservableCollection { private List m_List = new List(); public ExperimentalFeatureList() { - Items.Add(new ExperimentalFeature( - () => { }, - () => { }) { Name = "Hosting", IsEnabled = true }); - Items.Add(new ExperimentalFeature(() => { }, () => { }) { Name = "Canary", IsEnabled = false }); - } + // Visual Hosting + Items.Add(new EnvVarExperimentalFeature( + "COREWEBVIEW2_FORCED_HOSTING_MODE", + "COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL", + "COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_WINDOW") + { + Name = "Visual hosting", + Description = "When on apps will be running in Visual Hosting instead of regular Window hosting" + }); - public List GetList() - { - return m_List; - } + // Canary self-hosting + Items.Add(new EnvVarExperimentalFeature( + "WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", + "1", + null) + { + Name = "Canary self-hosting", + Description = "When on apps will use canary WebView2 runtime if installed instead of stable" + }); - public IDisposable Subscribe(IObserver observer) - { - throw new NotImplementedException(); + // To add more experimental features to the list either: + // add EnvVarExperimentalFeature if the feature is controlled by an enviroment variable + // OR + // add ExperimentalFeature with on, off and check delegates if the feature requires more specific operations } } } \ No newline at end of file diff --git a/wv2util/MainWindow.xaml b/wv2util/MainWindow.xaml index 094b0a6..175a43c 100644 --- a/wv2util/MainWindow.xaml +++ b/wv2util/MainWindow.xaml @@ -364,8 +364,18 @@ Name - - IsEnabled + + Enabled + + + + + + + + + + Description From 6911c1a536f285b7f5402e9bf5e0a74c0e834164 Mon Sep 17 00:00:00 2001 From: Ognjen Sobajic Date: Wed, 13 Mar 2024 16:47:52 -0700 Subject: [PATCH 3/8] Resolving most comments from Dave --- wv2util/AppState.cs | 8 +-- wv2util/ExperimentalFeature.cs | 90 +++++++++++++++++++++++----------- wv2util/MainWindow.xaml | 5 +- wv2util/MainWindow.xaml.cs | 5 -- 4 files changed, 63 insertions(+), 45 deletions(-) diff --git a/wv2util/AppState.cs b/wv2util/AppState.cs index 2d5dccd..531b00b 100644 --- a/wv2util/AppState.cs +++ b/wv2util/AppState.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace wv2util +namespace wv2util { public class AppState { diff --git a/wv2util/ExperimentalFeature.cs b/wv2util/ExperimentalFeature.cs index 4b6ae80..6a987ad 100644 --- a/wv2util/ExperimentalFeature.cs +++ b/wv2util/ExperimentalFeature.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; +using System.Windows; namespace wv2util { @@ -8,40 +10,36 @@ public class ExperimentalFeature : IEquatable, IComparable< { public string Name { get; set; } - public bool isEnabled; + private bool m_IsEnabled; public bool IsEnabled { - get { return isEnabled; } + get { return m_IsEnabled; } set { if (value) { - turnOn(); + m_IsEnabled = m_turnOn(); + return; } else { - turnOff(); + m_turnOff(); } - isEnabled = value; + m_IsEnabled = value; } } public string Description { get; set; } - private Action turnOn, turnOff; + private Func m_turnOn; + private Action m_turnOff; - public ExperimentalFeature(Action turnOn, Action turnOff, Func isOn) + public ExperimentalFeature(Func turnOn, Action turnOff, Func isOn) { - this.turnOn = turnOn; - this.turnOff = turnOff; - isEnabled = isOn(); - } - - static public bool IsEnabledForApp(string commandLine, string envVars) - { - // TODO implement - return false; + this.m_turnOn = turnOn; + this.m_turnOff = turnOff; + m_IsEnabled = isOn(); } public int CompareTo(ExperimentalFeature other) @@ -62,11 +60,13 @@ public EnvVarExperimentalFeature(string envVar, string onVal, string offVal) : b { // Turn on: Environment.SetEnvironmentVariable(envVar, onVal, EnvironmentVariableTarget.User); + return true; }, () => { // Turn off: Environment.SetEnvironmentVariable(envVar, offVal, EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable(envVar, offVal, EnvironmentVariableTarget.Machine); }, () => { @@ -83,27 +83,59 @@ public class ExperimentalFeatureList : ObservableCollection public ExperimentalFeatureList() { - // Visual Hosting - Items.Add(new EnvVarExperimentalFeature( - "COREWEBVIEW2_FORCED_HOSTING_MODE", - "COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL", - "COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_WINDOW") + // Canary self-hosting + Items.Add(new ExperimentalFeature( + () => + { + var runtimes = AppState.GetRuntimeList(); + + // Only if Canary is installed turn self-hosting on + if (runtimes.Any(runtime => runtime.Channel == "Canary")) + { + Environment.SetEnvironmentVariable("WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", "1", EnvironmentVariableTarget.User); + return true; + } + + const string canaryLink = "https://go.microsoft.com/fwlink/?linkid=2084649&Channel=Canary&language=en"; + if (MessageBox.Show( + $"Before turning on this feature you need to have Canary installed from {canaryLink}. Do you want to install it now?", + "Canary missing", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) + { + System.Diagnostics.Process.Start(canaryLink); + } + + return false; + }, + () => + { + var list = AppState.GetRuntimeList(); + + // Turn off: + Environment.SetEnvironmentVariable("WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", null, EnvironmentVariableTarget.User); + }, + () => + { + var list = AppState.GetRuntimeList(); + string val = Environment.GetEnvironmentVariable("WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", EnvironmentVariableTarget.User); + return val != null && val == "1"; + } + ) { - Name = "Visual hosting", - Description = "When on apps will be running in Visual Hosting instead of regular Window hosting" + Name = "Canary self-hosting", + Description = "Host apps use canary WebView2 runtime if installed instead of stable." }); - // Canary self-hosting + // Visual Hosting Items.Add(new EnvVarExperimentalFeature( - "WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", - "1", + "COREWEBVIEW2_FORCED_HOSTING_MODE", + "COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL", null) { - Name = "Canary self-hosting", - Description = "When on apps will use canary WebView2 runtime if installed instead of stable" + Name = "Visual hosting", + Description = "Host apps use visual hosting instead of regular window hosting." }); - // To add more experimental features to the list either: + // To add more experimental features to the runtimes either: // add EnvVarExperimentalFeature if the feature is controlled by an enviroment variable // OR // add ExperimentalFeature with on, off and check delegates if the feature requires more specific operations diff --git a/wv2util/MainWindow.xaml b/wv2util/MainWindow.xaml index 175a43c..df797a5 100644 --- a/wv2util/MainWindow.xaml +++ b/wv2util/MainWindow.xaml @@ -262,7 +262,7 @@ - + @@ -383,9 +383,6 @@ - - diff --git a/wv2util/MainWindow.xaml.cs b/wv2util/MainWindow.xaml.cs index 4d2a847..4b26d55 100644 --- a/wv2util/MainWindow.xaml.cs +++ b/wv2util/MainWindow.xaml.cs @@ -120,11 +120,6 @@ private void HostAppsGoToOverride_Click(object sender, RoutedEventArgs e) } } - private void ExperimentalFeatureListViewSelectionChanged(object sender, SelectionChangedEventArgs e) - { - //todo - } - private void RuntimeListViewSelectionChanged(object sender, SelectionChangedEventArgs e) { if (RuntimeList.SelectedIndex >= 0) From 420c0a6b3d87c3b54ea69a6a4b6923a046bbfbd6 Mon Sep 17 00:00:00 2001 From: Ognjen Sobajic Date: Wed, 13 Mar 2024 23:59:42 +0000 Subject: [PATCH 4/8] Revert MainWindow.xaml around RuntimeList --- wv2util/MainWindow.xaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/wv2util/MainWindow.xaml b/wv2util/MainWindow.xaml index df797a5..16ba593 100644 --- a/wv2util/MainWindow.xaml +++ b/wv2util/MainWindow.xaml @@ -247,7 +247,7 @@ - + @@ -351,13 +351,13 @@ - - - - - - - + + + + + + + @@ -379,9 +379,9 @@ - - - + + + From d0070a7284d73b660afe2bad4d33ecdc15c290b6 Mon Sep 17 00:00:00 2001 From: Ognjen Sobajic Date: Thu, 14 Mar 2024 01:01:05 +0000 Subject: [PATCH 5/8] Remove extra list --- wv2util/ExperimentalFeature.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/wv2util/ExperimentalFeature.cs b/wv2util/ExperimentalFeature.cs index 6a987ad..ed90600 100644 --- a/wv2util/ExperimentalFeature.cs +++ b/wv2util/ExperimentalFeature.cs @@ -108,8 +108,6 @@ public ExperimentalFeatureList() }, () => { - var list = AppState.GetRuntimeList(); - // Turn off: Environment.SetEnvironmentVariable("WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", null, EnvironmentVariableTarget.User); }, From 1839ff8285882fae4753516d7eaaf881b7f4c1a6 Mon Sep 17 00:00:00 2001 From: Ognjen Sobajic Date: Wed, 13 Mar 2024 19:48:31 -0700 Subject: [PATCH 6/8] Reload overrides tab when toggling the self-hosting option --- wv2util/ExperimentalFeature.cs | 4 ++-- wv2util/MainWindow.xaml | 2 +- wv2util/MainWindow.xaml.cs | 8 ++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/wv2util/ExperimentalFeature.cs b/wv2util/ExperimentalFeature.cs index ed90600..e9af90f 100644 --- a/wv2util/ExperimentalFeature.cs +++ b/wv2util/ExperimentalFeature.cs @@ -79,8 +79,6 @@ public EnvVarExperimentalFeature(string envVar, string onVal, string offVal) : b public class ExperimentalFeatureList : ObservableCollection { - private List m_List = new List(); - public ExperimentalFeatureList() { // Canary self-hosting @@ -93,6 +91,7 @@ public ExperimentalFeatureList() if (runtimes.Any(runtime => runtime.Channel == "Canary")) { Environment.SetEnvironmentVariable("WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", "1", EnvironmentVariableTarget.User); + AppState.GetAppOverrideList().FromSystem(); return true; } @@ -110,6 +109,7 @@ public ExperimentalFeatureList() { // Turn off: Environment.SetEnvironmentVariable("WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", null, EnvironmentVariableTarget.User); + AppState.GetAppOverrideList().FromSystem(); }, () => { diff --git a/wv2util/MainWindow.xaml b/wv2util/MainWindow.xaml index 16ba593..2228369 100644 --- a/wv2util/MainWindow.xaml +++ b/wv2util/MainWindow.xaml @@ -297,7 +297,7 @@ -