Skip to content

Commit b85d937

Browse files
committed
🎨 optimize
1 parent 530016c commit b85d937

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

src/Avalonia.WebView2.Sample/MainWindow.xaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ void UrlTextBox_KeyDown(object? sender, KeyEventArgs e)
9595
void SetTitle(string? browserVersion, Architecture architecture = Unknown)
9696
=> Title.Content = base.Title = GetTitle(browserVersion, architecture);
9797

98-
void InitializeComponent()
99-
{
100-
AvaloniaXamlLoader.Load(this);
101-
}
102-
10398
//void Environment_ProcessInfosChanged(object? sender, object e)
10499
//{
105100
// var processInfos = Environment!.GetProcessInfos();

src/Avalonia.WebView2.Sample/WebView2Compat.xaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ void WebView2_DOMContentLoaded(object? sender, CoreWebView2DOMContentLoadedEvent
4343
}
4444
#endif
4545

46-
private void InitializeComponent()
47-
{
48-
AvaloniaXamlLoader.Load(this);
49-
}
50-
5146
IEnumerable<KeyValuePair<(StorageItemType type, string key), StorageItemValue>>? IStorageService.GetStorages(string requestUri)
5247
{
5348
var result = SampleHelper.GetStorages(requestUri);

src/Avalonia.WebView2/Platforms/Droid/Controls/WebView2.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,23 +254,28 @@ public override bool ShouldOverrideUrlLoading(AWebView? view, string? url)
254254
public override void OnPageStarted(AWebView? view, string? url, Bitmap? favicon)
255255
{
256256
var handler = Handler;
257-
if (!string.IsNullOrWhiteSpace(url))
258-
{
259-
handler.VirtualView.SyncPlatformCookiesToWebView2(url).FireAndForget();
260-
}
261257

262-
if (view != null)
258+
if (handler != null)
263259
{
264260
if (!string.IsNullOrWhiteSpace(url))
265261
{
266-
var js = HandlerStorageServiceGenerateJSString(handler.VirtualView.StorageService, url);
267-
if (js != null)
262+
handler.VirtualView.SyncPlatformCookiesToWebView2(url).FireAndForget();
263+
}
264+
265+
if (view != null)
266+
{
267+
if (!string.IsNullOrWhiteSpace(url))
268268
{
269-
view.EvaluateJavascript(js, null);
269+
var js = HandlerStorageServiceGenerateJSString(handler.VirtualView.StorageService, url);
270+
if (js != null)
271+
{
272+
view.EvaluateJavascript(js, null);
273+
}
270274
}
271275
}
272276
}
273277

278+
274279
base.OnPageStarted(view, url, favicon);
275280
}
276281

src/Avalonia.WebView2/Platforms/iOS/Controls/WebView2.Cookie.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async Task<List<NSHttpCookie>> GetCookiesFromPlatformStore(string url)
161161
{
162162
NSHttpCookie[]? _initialCookiesLoaded = null;
163163

164-
if (OperatingSystem.IsIOSVersionAtLeast(11))
164+
if (OperatingSystem.IsIOSVersionAtLeast(11) && PlatformWebView != null)
165165
{
166166
_initialCookiesLoaded = await PlatformWebView.Configuration.WebsiteDataStore.HttpCookieStore.GetAllCookiesAsync();
167167
}
@@ -195,6 +195,9 @@ async Task<List<NSHttpCookie>> GetCookiesFromPlatformStore(string url)
195195

196196
async Task SetCookie(List<Cookie> cookies)
197197
{
198+
if (PlatformWebView is null)
199+
return;
200+
198201
if (OperatingSystem.IsIOSVersionAtLeast(11))
199202
{
200203
foreach (var cookie in cookies)
@@ -215,6 +218,10 @@ async Task SetCookie(List<Cookie> cookies)
215218

216219
async Task DeleteCookies(List<NSHttpCookie> cookies)
217220
{
221+
if (PlatformWebView is null)
222+
return;
223+
224+
218225
if (OperatingSystem.IsIOSVersionAtLeast(11))
219226
{
220227
foreach (var cookie in cookies)

0 commit comments

Comments
 (0)