Skip to content

Commit 87d1572

Browse files
committed
WebView adds a ProcessTerminated event that's raised when a WebView process ends unexpectedly.
1 parent 2297ed3 commit 87d1572

File tree

1 file changed

+75
-61
lines changed

1 file changed

+75
-61
lines changed

src/FmgLib.MauiMarkup/Extensions/WebViewExtension.cs

Lines changed: 75 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,235 +5,249 @@ public static partial class WebViewExtension
55
{
66
public static T CanGoBack<T>(this T self,
77
bool canGoBack)
8-
where T : WebView
8+
where T : Microsoft.Maui.Controls.WebView
99
{
10-
self.SetValue(WebView.CanGoBackProperty, canGoBack);
10+
self.SetValue(Microsoft.Maui.Controls.WebView.CanGoBackProperty, canGoBack);
1111
return self;
1212
}
1313

1414
public static T CanGoBack<T>(this T self,
1515
Func<bool> configure)
16-
where T : WebView
16+
where T : Microsoft.Maui.Controls.WebView
1717
{
1818
var canGoBack = configure();
19-
self.SetValue(WebView.CanGoBackProperty, canGoBack);
19+
self.SetValue(Microsoft.Maui.Controls.WebView.CanGoBackProperty, canGoBack);
2020
return self;
2121
}
2222

2323
public static T CanGoBack<T>(this T self, Func<PropertyContext<bool>, IPropertyBuilder<bool>> configure)
24-
where T : WebView
24+
where T : Microsoft.Maui.Controls.WebView
2525
{
26-
var context = new PropertyContext<bool>(self, WebView.CanGoBackProperty);
26+
var context = new PropertyContext<bool>(self, Microsoft.Maui.Controls.WebView.CanGoBackProperty);
2727
configure(context).Build();
2828
return self;
2929
}
3030

3131
public static SettersContext<T> CanGoBack<T>(this SettersContext<T> self,
3232
bool canGoBack)
33-
where T : WebView
33+
where T : Microsoft.Maui.Controls.WebView
3434
{
35-
self.XamlSetters.Add(new Setter { Property = WebView.CanGoBackProperty, Value = canGoBack });
35+
self.XamlSetters.Add(new Setter { Property = Microsoft.Maui.Controls.WebView.CanGoBackProperty, Value = canGoBack });
3636
return self;
3737
}
3838

3939
public static SettersContext<T> CanGoBack<T>(this SettersContext<T> self, Func<PropertySettersContext<bool>, IPropertySettersBuilder<bool>> configure)
40-
where T : WebView
40+
where T : Microsoft.Maui.Controls.WebView
4141
{
42-
var context = new PropertySettersContext<bool>(self.XamlSetters, WebView.CanGoBackProperty);
42+
var context = new PropertySettersContext<bool>(self.XamlSetters, Microsoft.Maui.Controls.WebView.CanGoBackProperty);
4343
configure(context).Build();
4444
return self;
4545
}
4646

4747
public static T CanGoForward<T>(this T self,
4848
bool canGoForward)
49-
where T : WebView
49+
where T : Microsoft.Maui.Controls.WebView
5050
{
51-
self.SetValue(WebView.CanGoForwardProperty, canGoForward);
51+
self.SetValue(Microsoft.Maui.Controls.WebView.CanGoForwardProperty, canGoForward);
5252
return self;
5353
}
5454

5555
public static T CanGoForward<T>(this T self,
5656
Func<bool> configure)
57-
where T : WebView
57+
where T : Microsoft.Maui.Controls.WebView
5858
{
5959
var canGoForward = configure();
60-
self.SetValue(WebView.CanGoForwardProperty, canGoForward);
60+
self.SetValue(Microsoft.Maui.Controls.WebView.CanGoForwardProperty, canGoForward);
6161
return self;
6262
}
6363

6464
public static T CanGoForward<T>(this T self, Func<PropertyContext<bool>, IPropertyBuilder<bool>> configure)
65-
where T : WebView
65+
where T : Microsoft.Maui.Controls.WebView
6666
{
67-
var context = new PropertyContext<bool>(self, WebView.CanGoForwardProperty);
67+
var context = new PropertyContext<bool>(self, Microsoft.Maui.Controls.WebView.CanGoForwardProperty);
6868
configure(context).Build();
6969
return self;
7070
}
7171

7272
public static SettersContext<T> CanGoForward<T>(this SettersContext<T> self,
7373
bool canGoForward)
74-
where T : WebView
74+
where T : Microsoft.Maui.Controls.WebView
7575
{
76-
self.XamlSetters.Add(new Setter { Property = WebView.CanGoForwardProperty, Value = canGoForward });
76+
self.XamlSetters.Add(new Setter { Property = Microsoft.Maui.Controls.WebView.CanGoForwardProperty, Value = canGoForward });
7777
return self;
7878
}
7979

8080
public static SettersContext<T> CanGoForward<T>(this SettersContext<T> self, Func<PropertySettersContext<bool>, IPropertySettersBuilder<bool>> configure)
81-
where T : WebView
81+
where T : Microsoft.Maui.Controls.WebView
8282
{
83-
var context = new PropertySettersContext<bool>(self.XamlSetters, WebView.CanGoForwardProperty);
83+
var context = new PropertySettersContext<bool>(self.XamlSetters, Microsoft.Maui.Controls.WebView.CanGoForwardProperty);
8484
configure(context).Build();
8585
return self;
8686
}
8787

8888
public static T Cookies<T>(this T self,
8989
System.Net.CookieContainer cookies)
90-
where T : WebView
90+
where T : Microsoft.Maui.Controls.WebView
9191
{
92-
self.SetValue(WebView.CookiesProperty, cookies);
92+
self.SetValue(Microsoft.Maui.Controls.WebView.CookiesProperty, cookies);
9393
return self;
9494
}
9595

9696
public static T Cookies<T>(this T self,
9797
Func<System.Net.CookieContainer> configure)
98-
where T : WebView
98+
where T : Microsoft.Maui.Controls.WebView
9999
{
100100
var cookies = configure();
101-
self.SetValue(WebView.CookiesProperty, cookies);
101+
self.SetValue(Microsoft.Maui.Controls.WebView.CookiesProperty, cookies);
102102
return self;
103103
}
104104

105105
public static T Cookies<T>(this T self, Func<PropertyContext<System.Net.CookieContainer>, IPropertyBuilder<System.Net.CookieContainer>> configure)
106-
where T : WebView
106+
where T : Microsoft.Maui.Controls.WebView
107107
{
108-
var context = new PropertyContext<System.Net.CookieContainer>(self, WebView.CookiesProperty);
108+
var context = new PropertyContext<System.Net.CookieContainer>(self, Microsoft.Maui.Controls.WebView.CookiesProperty);
109109
configure(context).Build();
110110
return self;
111111
}
112112

113113
public static SettersContext<T> Cookies<T>(this SettersContext<T> self,
114114
System.Net.CookieContainer cookies)
115-
where T : WebView
115+
where T : Microsoft.Maui.Controls.WebView
116116
{
117-
self.XamlSetters.Add(new Setter { Property = WebView.CookiesProperty, Value = cookies });
117+
self.XamlSetters.Add(new Setter { Property = Microsoft.Maui.Controls.WebView.CookiesProperty, Value = cookies });
118118
return self;
119119
}
120120

121121
public static SettersContext<T> Cookies<T>(this SettersContext<T> self, Func<PropertySettersContext<System.Net.CookieContainer>, IPropertySettersBuilder<System.Net.CookieContainer>> configure)
122-
where T : WebView
122+
where T : Microsoft.Maui.Controls.WebView
123123
{
124-
var context = new PropertySettersContext<System.Net.CookieContainer>(self.XamlSetters, WebView.CookiesProperty);
124+
var context = new PropertySettersContext<System.Net.CookieContainer>(self.XamlSetters, Microsoft.Maui.Controls.WebView.CookiesProperty);
125125
configure(context).Build();
126126
return self;
127127
}
128128

129129
public static T Source<T>(this T self,
130-
WebViewSource source)
131-
where T : WebView
130+
Microsoft.Maui.Controls.WebViewSource source)
131+
where T : Microsoft.Maui.Controls.WebView
132132
{
133-
self.SetValue(WebView.SourceProperty, source);
133+
self.SetValue(Microsoft.Maui.Controls.WebView.SourceProperty, source);
134134
return self;
135135
}
136136

137137
public static T Source<T>(this T self,
138-
Func<WebViewSource> configure)
139-
where T : WebView
138+
Func<Microsoft.Maui.Controls.WebViewSource> configure)
139+
where T : Microsoft.Maui.Controls.WebView
140140
{
141141
var source = configure();
142-
self.SetValue(WebView.SourceProperty, source);
142+
self.SetValue(Microsoft.Maui.Controls.WebView.SourceProperty, source);
143143
return self;
144144
}
145145

146-
public static T Source<T>(this T self, Func<PropertyContext<WebViewSource>, IPropertyBuilder<WebViewSource>> configure)
147-
where T : WebView
146+
public static T Source<T>(this T self, Func<PropertyContext<Microsoft.Maui.Controls.WebViewSource>, IPropertyBuilder<Microsoft.Maui.Controls.WebViewSource>> configure)
147+
where T : Microsoft.Maui.Controls.WebView
148148
{
149-
var context = new PropertyContext<WebViewSource>(self, WebView.SourceProperty);
149+
var context = new PropertyContext<Microsoft.Maui.Controls.WebViewSource>(self, Microsoft.Maui.Controls.WebView.SourceProperty);
150150
configure(context).Build();
151151
return self;
152152
}
153153

154154
public static SettersContext<T> Source<T>(this SettersContext<T> self,
155-
WebViewSource source)
156-
where T : WebView
155+
Microsoft.Maui.Controls.WebViewSource source)
156+
where T : Microsoft.Maui.Controls.WebView
157157
{
158-
self.XamlSetters.Add(new Setter { Property = WebView.SourceProperty, Value = source });
158+
self.XamlSetters.Add(new Setter { Property = Microsoft.Maui.Controls.WebView.SourceProperty, Value = source });
159159
return self;
160160
}
161161

162-
public static SettersContext<T> Source<T>(this SettersContext<T> self, Func<PropertySettersContext<WebViewSource>, IPropertySettersBuilder<WebViewSource>> configure)
163-
where T : WebView
162+
public static SettersContext<T> Source<T>(this SettersContext<T> self, Func<PropertySettersContext<Microsoft.Maui.Controls.WebViewSource>, IPropertySettersBuilder<Microsoft.Maui.Controls.WebViewSource>> configure)
163+
where T : Microsoft.Maui.Controls.WebView
164164
{
165-
var context = new PropertySettersContext<WebViewSource>(self.XamlSetters, WebView.SourceProperty);
165+
var context = new PropertySettersContext<Microsoft.Maui.Controls.WebViewSource>(self.XamlSetters, Microsoft.Maui.Controls.WebView.SourceProperty);
166166
configure(context).Build();
167167
return self;
168168
}
169169

170170
public static T UserAgent<T>(this T self,
171171
string userAgent)
172-
where T : WebView
172+
where T : Microsoft.Maui.Controls.WebView
173173
{
174-
self.SetValue(WebView.UserAgentProperty, userAgent);
174+
self.SetValue(Microsoft.Maui.Controls.WebView.UserAgentProperty, userAgent);
175175
return self;
176176
}
177177

178178
public static T UserAgent<T>(this T self,
179179
Func<string> configure)
180-
where T : WebView
180+
where T : Microsoft.Maui.Controls.WebView
181181
{
182182
var userAgent = configure();
183-
self.SetValue(WebView.UserAgentProperty, userAgent);
183+
self.SetValue(Microsoft.Maui.Controls.WebView.UserAgentProperty, userAgent);
184184
return self;
185185
}
186186

187187
public static T UserAgent<T>(this T self, Func<PropertyContext<string>, IPropertyBuilder<string>> configure)
188-
where T : WebView
188+
where T : Microsoft.Maui.Controls.WebView
189189
{
190-
var context = new PropertyContext<string>(self, WebView.UserAgentProperty);
190+
var context = new PropertyContext<string>(self, Microsoft.Maui.Controls.WebView.UserAgentProperty);
191191
configure(context).Build();
192192
return self;
193193
}
194194

195195
public static SettersContext<T> UserAgent<T>(this SettersContext<T> self,
196196
string userAgent)
197-
where T : WebView
197+
where T : Microsoft.Maui.Controls.WebView
198198
{
199-
self.XamlSetters.Add(new Setter { Property = WebView.UserAgentProperty, Value = userAgent });
199+
self.XamlSetters.Add(new Setter { Property = Microsoft.Maui.Controls.WebView.UserAgentProperty, Value = userAgent });
200200
return self;
201201
}
202202

203203
public static SettersContext<T> UserAgent<T>(this SettersContext<T> self, Func<PropertySettersContext<string>, IPropertySettersBuilder<string>> configure)
204-
where T : WebView
204+
where T : Microsoft.Maui.Controls.WebView
205205
{
206-
var context = new PropertySettersContext<string>(self.XamlSetters, WebView.UserAgentProperty);
206+
var context = new PropertySettersContext<string>(self.XamlSetters, Microsoft.Maui.Controls.WebView.UserAgentProperty);
207207
configure(context).Build();
208208
return self;
209209
}
210210

211-
public static T OnNavigated<T>(this T self, System.EventHandler<WebNavigatedEventArgs> handler)
212-
where T : WebView
211+
public static T OnNavigated<T>(this T self, System.EventHandler<Microsoft.Maui.Controls.WebNavigatedEventArgs> handler)
212+
where T : Microsoft.Maui.Controls.WebView
213213
{
214214
self.Navigated += handler;
215215
return self;
216216
}
217217

218218
public static T OnNavigated<T>(this T self, System.Action<T> action)
219-
where T : WebView
219+
where T : Microsoft.Maui.Controls.WebView
220220
{
221221
self.Navigated += (o, arg) => action(self);
222222
return self;
223223
}
224224

225-
public static T OnNavigating<T>(this T self, System.EventHandler<WebNavigatingEventArgs> handler)
226-
where T : WebView
225+
public static T OnNavigating<T>(this T self, System.EventHandler<Microsoft.Maui.Controls.WebNavigatingEventArgs> handler)
226+
where T : Microsoft.Maui.Controls.WebView
227227
{
228228
self.Navigating += handler;
229229
return self;
230230
}
231231

232232
public static T OnNavigating<T>(this T self, System.Action<T> action)
233-
where T : WebView
233+
where T : Microsoft.Maui.Controls.WebView
234234
{
235235
self.Navigating += (o, arg) => action(self);
236236
return self;
237237
}
238238

239+
public static T OnProcessTerminated<T>(this T self, System.EventHandler<Microsoft.Maui.Controls.WebViewProcessTerminatedEventArgs> handler)
240+
where T : Microsoft.Maui.Controls.WebView
241+
{
242+
self.ProcessTerminated += handler;
243+
return self;
244+
}
245+
246+
public static T OnProcessTerminated<T>(this T self, System.Action<T> action)
247+
where T : Microsoft.Maui.Controls.WebView
248+
{
249+
self.ProcessTerminated += (o, arg) => action(self);
250+
return self;
251+
}
252+
239253
}

0 commit comments

Comments
 (0)