Skip to content

Commit 05df19b

Browse files
committed
更新 v0.1.6
取消下载默认检查可用空间 修改 Deferrals 储存 兜住初始加载
1 parent 64266b1 commit 05df19b

File tree

9 files changed

+104
-97
lines changed

9 files changed

+104
-97
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ body:
3434
label: App version
3535
description: Specify the version of APK Installer you're using.
3636
options:
37+
- 0.1.6
3738
- 0.0.5
3839
- 0.0.4
3940
- 0.0.3

APKInstaller/APKInstaller/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs e)
116116
private async void EnsureWindow(IActivatedEventArgs e)
117117
{
118118
RegisterExceptionHandlingSynchronizationContext();
119+
e.SetDeferral();
119120

120121
if (!isLoaded)
121122
{
@@ -124,7 +125,6 @@ private async void EnsureWindow(IActivatedEventArgs e)
124125
}
125126

126127
Window window = Window.Current;
127-
e.SetDeferral();
128128

129129
// 不要在窗口已包含内容时重复应用程序初始化,
130130
// 只需确保窗口处于活动状态

APKInstaller/APKInstaller/Controls/SettingsCard/SettingsCard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private void RegisterAutomation()
6969
// We don't want to override an AutomationProperties.Name that is manually set, or if the Content basetype is of type ButtonBase (the ButtonBase.Content will be used then)
7070
if (Content is UIElement element
7171
&& string.IsNullOrEmpty(AutomationProperties.GetName(element))
72-
&& element is not ButtonBase or TextBlock)
72+
&& element is not (ButtonBase or TextBlock))
7373
{
7474
AutomationProperties.SetName(element, headerString);
7575
}

APKInstaller/APKInstaller/Helpers/DownloadHelper.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ namespace APKInstaller.Helpers
44
{
55
public static class DownloadHelper
66
{
7-
public static DownloadConfiguration Configuration { get; }
8-
9-
static DownloadHelper()
7+
public static DownloadConfiguration Configuration { get; } = new DownloadConfiguration
108
{
11-
Configuration = new DownloadConfiguration
12-
{
13-
ChunkCount = 8,
14-
ParallelDownload = true
15-
};
16-
}
9+
CheckDiskSizeBeforeDownload = false,
10+
ChunkCount = 8,
11+
ParallelDownload = true
12+
};
1713
}
1814
}

APKInstaller/APKInstaller/Helpers/WindowHelper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ public static T SetXAMLRoot<T>(this T element, UIElement target) where T : UIEle
6363

6464
public static void SetDeferral(this IActivatedEventArgs args)
6565
{
66+
if (args == null || Deferrals.ContainsKey(args)) { return; }
6667
switch (args.Kind)
6768
{
6869
case ActivationKind.CommandLineLaunch when args is CommandLineActivatedEventArgs commandLineActivatedEventArgs:
69-
Deferrals.AddOrUpdate(args, commandLineActivatedEventArgs.Operation.GetDeferral());
70+
Deferrals[args] = commandLineActivatedEventArgs.Operation.GetDeferral();
7071
break;
7172
}
7273
}
@@ -76,11 +77,12 @@ public static void CompleteDeferral(this IActivatedEventArgs args)
7677
if (Deferrals.TryGetValue(args, out Deferral deferral))
7778
{
7879
deferral?.Complete();
80+
_ = Deferrals.Remove(args);
7981
}
8082
}
8183

8284
public static Dictionary<CoreDispatcher, Window> ActiveWindows { get; } = [];
8385

84-
public static ConditionalWeakTable<IActivatedEventArgs, Deferral> Deferrals { get; } = [];
86+
public static Dictionary<IActivatedEventArgs, Deferral> Deferrals { get; } = [];
8587
}
8688
}

APKInstaller/APKInstaller/Pages/InstallPage.xaml.cs

Lines changed: 88 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -57,113 +57,121 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
5757
}
5858
else if (e.Parameter is IActivatedEventArgs args)
5959
{
60-
switch (args?.Kind)
60+
try
6161
{
62-
case ActivationKind.File when args is IFileActivatedEventArgs fileActivatedEventArgs:
63-
Provider = new InstallViewModel(file: null, this);
64-
_ = Provider.OpenAPKAsync(fileActivatedEventArgs.Files);
65-
return;
66-
case ActivationKind.ShareTarget when args is IShareTargetActivatedEventArgs shareTargetEventArgs:
67-
Provider = new InstallViewModel(file: null, this);
68-
_ = Provider.OpenAPKAsync(shareTargetEventArgs.ShareOperation.Data);
69-
return;
70-
case ActivationKind.Protocol when args is ProtocolActivatedEventArgs protocolArgs:
71-
ValueSet protocolData = protocolArgs.Data;
72-
if (protocolData?.Count >= 1)
73-
{
74-
if (protocolData.TryGetValue("Url", out object url))
62+
switch (args?.Kind)
63+
{
64+
case ActivationKind.File when args is IFileActivatedEventArgs fileActivatedEventArgs:
65+
Provider = new InstallViewModel(file: null, this);
66+
_ = Provider.OpenAPKAsync(fileActivatedEventArgs.Files);
67+
return;
68+
case ActivationKind.ShareTarget when args is IShareTargetActivatedEventArgs shareTargetEventArgs:
69+
Provider = new InstallViewModel(file: null, this);
70+
_ = Provider.OpenAPKAsync(shareTargetEventArgs.ShareOperation.Data);
71+
return;
72+
case ActivationKind.Protocol when args is ProtocolActivatedEventArgs protocolArgs:
73+
ValueSet protocolData = protocolArgs.Data;
74+
if (protocolData?.Count >= 1)
7575
{
76-
Provider = new InstallViewModel(url as Uri, this);
77-
break;
78-
79-
}
80-
else if (protocolData.TryGetValue("FilePath", out object filePath))
81-
{
82-
try
76+
if (protocolData.TryGetValue("Url", out object url))
8377
{
84-
StorageFile file = await StorageFile.GetFileFromPathAsync(filePath?.ToString());
85-
Provider = new InstallViewModel(file, this);
78+
Provider = new InstallViewModel(url as Uri, this);
8679
break;
80+
8781
}
88-
catch (Exception ex)
82+
else if (protocolData.TryGetValue("FilePath", out object filePath))
8983
{
90-
SettingsHelper.LoggerFactory.CreateLogger<InstallPage>().LogError(ex, "Failed to get file from path in protocol activation. {message} (0x{hResult:X})", ex.GetMessage(), ex.HResult);
84+
try
85+
{
86+
StorageFile file = await StorageFile.GetFileFromPathAsync(filePath?.ToString());
87+
Provider = new InstallViewModel(file, this);
88+
break;
89+
}
90+
catch (Exception ex)
91+
{
92+
SettingsHelper.LoggerFactory.CreateLogger<InstallPage>().LogError(ex, "Failed to get file from path in protocol activation. {message} (0x{hResult:X})", ex.GetMessage(), ex.HResult);
93+
}
9194
}
9295
}
93-
}
94-
Provider = new InstallViewModel(protocolArgs.Uri, this);
95-
break;
96-
case ActivationKind.ProtocolForResults when args is ProtocolForResultsActivatedEventArgs protocolForResultsArgs:
97-
ValueSet ProtocolForResultsData = protocolForResultsArgs.Data;
98-
if (ProtocolForResultsData?.Count >= 1)
99-
{
100-
if (ProtocolForResultsData.TryGetValue("Url", out object url))
101-
{
102-
Provider = new InstallViewModel(url as Uri, this, protocolForResultsArgs.ProtocolForResultsOperation);
103-
break;
104-
}
105-
else if (ProtocolForResultsData.TryGetValue("FilePath", out object filePath))
96+
Provider = new InstallViewModel(protocolArgs.Uri, this);
97+
break;
98+
case ActivationKind.ProtocolForResults when args is ProtocolForResultsActivatedEventArgs protocolForResultsArgs:
99+
ValueSet ProtocolForResultsData = protocolForResultsArgs.Data;
100+
if (ProtocolForResultsData?.Count >= 1)
106101
{
107-
try
102+
if (ProtocolForResultsData.TryGetValue("Url", out object url))
108103
{
109-
StorageFile file = await StorageFile.GetFileFromPathAsync(filePath?.ToString());
110-
Provider = new InstallViewModel(file, this, protocolForResultsArgs.ProtocolForResultsOperation);
104+
Provider = new InstallViewModel(url as Uri, this, protocolForResultsArgs.ProtocolForResultsOperation);
111105
break;
112106
}
113-
catch (Exception ex)
107+
else if (ProtocolForResultsData.TryGetValue("FilePath", out object filePath))
114108
{
115-
SettingsHelper.LoggerFactory.CreateLogger<InstallPage>().LogError(ex, "Failed to get file from path in protocol activation. {message} (0x{hResult:X})", ex.GetMessage(), ex.HResult);
109+
try
110+
{
111+
StorageFile file = await StorageFile.GetFileFromPathAsync(filePath?.ToString());
112+
Provider = new InstallViewModel(file, this, protocolForResultsArgs.ProtocolForResultsOperation);
113+
break;
114+
}
115+
catch (Exception ex)
116+
{
117+
SettingsHelper.LoggerFactory.CreateLogger<InstallPage>().LogError(ex, "Failed to get file from path in protocol activation. {message} (0x{hResult:X})", ex.GetMessage(), ex.HResult);
118+
}
116119
}
117120
}
118-
}
119-
Provider = new InstallViewModel(protocolForResultsArgs.Uri, this, protocolForResultsArgs.ProtocolForResultsOperation);
120-
break;
121-
case ActivationKind.CommandLineLaunch when args is ICommandLineActivatedEventArgs commandLineActivatedEventArgs:
122-
try
123-
{
124-
CommandLineActivationOperation operation = commandLineActivatedEventArgs.Operation;
125-
string[] arguments = operation.Arguments?.Split(' ', StringSplitOptions.RemoveEmptyEntries);
126-
if (arguments is [.., { Length: > 0 } path])
121+
Provider = new InstallViewModel(protocolForResultsArgs.Uri, this, protocolForResultsArgs.ProtocolForResultsOperation);
122+
break;
123+
case ActivationKind.CommandLineLaunch when args is ICommandLineActivatedEventArgs commandLineActivatedEventArgs:
124+
try
127125
{
128-
path = path.Trim('\'', '"');
129-
if (!string.IsNullOrWhiteSpace(path))
126+
CommandLineActivationOperation operation = commandLineActivatedEventArgs.Operation;
127+
string[] arguments = operation.Arguments?.Split(' ', StringSplitOptions.RemoveEmptyEntries);
128+
if (arguments is [.., { Length: > 0 } path])
130129
{
131-
try
130+
path = path.Trim('\'', '"');
131+
if (!string.IsNullOrWhiteSpace(path))
132132
{
133-
string basePath = operation.CurrentDirectoryPath;
134-
if (basePath[^1] != '\\')
133+
try
135134
{
136-
basePath += "\\";
137-
}
138-
if (Uri.TryCreate(basePath, UriKind.Absolute, out Uri baseUri) && baseUri.IsFile)
139-
{
140-
if (Uri.TryCreate(baseUri, path, out Uri uri) && uri.IsFile)
135+
string basePath = operation.CurrentDirectoryPath;
136+
if (basePath[^1] != '\\')
141137
{
142-
StorageFile file = await StorageFile.GetFileFromPathAsync(uri.AbsoluteUri);
143-
Provider = new InstallViewModel(file, this);
138+
basePath += "\\";
144139
}
145-
else if (Uri.TryCreate(path, UriKind.Absolute, out uri) && uri.Scheme is "http" or "https")
140+
if (Uri.TryCreate(basePath, UriKind.Absolute, out Uri baseUri) && baseUri.IsFile)
146141
{
147-
Provider = new InstallViewModel(uri, this);
142+
if (Uri.TryCreate(baseUri, path, out Uri uri) && uri.IsFile)
143+
{
144+
StorageFile file = await StorageFile.GetFileFromPathAsync(uri.AbsoluteUri);
145+
Provider = new InstallViewModel(file, this);
146+
}
147+
else if (Uri.TryCreate(path, UriKind.Absolute, out uri) && uri.Scheme is "http" or "https")
148+
{
149+
Provider = new InstallViewModel(uri, this);
150+
}
148151
}
152+
break;
153+
}
154+
catch (Exception ex)
155+
{
156+
SettingsHelper.LoggerFactory.CreateLogger<InstallPage>().LogError(ex, "Failed to get file from path in command line activation. {message} (0x{hResult:X})", ex.GetMessage(), ex.HResult);
149157
}
150-
break;
151-
}
152-
catch (Exception ex)
153-
{
154-
SettingsHelper.LoggerFactory.CreateLogger<InstallPage>().LogError(ex, "Failed to get file from path in command line activation. {message} (0x{hResult:X})", ex.GetMessage(), ex.HResult);
155158
}
156159
}
157160
}
158-
}
159-
finally
160-
{
161-
commandLineActivatedEventArgs.CompleteDeferral();
162-
}
163-
goto default;
164-
default:
165-
Provider = new InstallViewModel(file: null, this);
166-
break;
161+
finally
162+
{
163+
commandLineActivatedEventArgs.CompleteDeferral();
164+
}
165+
goto default;
166+
default:
167+
Provider = new InstallViewModel(file: null, this);
168+
break;
169+
}
170+
}
171+
catch (Exception ex)
172+
{
173+
SettingsHelper.LoggerFactory.CreateLogger<InstallPage>().LogError(ex, "Failed to initialize InstallViewModel with activation arguments. {message} (0x{hResult:X})", ex.GetMessage(), ex.HResult);
174+
Provider = new InstallViewModel(file: null, this);
167175
}
168176
}
169177
else

APKInstaller/APKInstaller/Pages/SettingsPages/SettingsPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private async void HyperlinkButton_Click(object sender, RoutedEventArgs e)
102102
_ = await Launcher.LaunchFolderAsync(await StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(Provider.ADBPath)));
103103
break;
104104
case "LogFolder":
105-
_ = await Launcher.LaunchFolderAsync(await ApplicationData.Current.LocalFolder.CreateFolderAsync("MetroLogs", CreationCollisionOption.OpenIfExists));
105+
_ = await Launcher.LaunchFolderAsync(await ApplicationData.Current.LocalFolder.CreateFolderAsync("Logs", CreationCollisionOption.OpenIfExists));
106106
break;
107107
case "WindowsColor":
108108
_ = Launcher.LaunchUriAsync(new Uri("ms-settings:colors"));

APKInstaller/APKInstaller/ViewModels/InstallViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ private async ValueTask DownloadADBAsync()
526526
{
527527
Directory.Delete(ADBTemp, true);
528528
}
529-
using (DownloadService downloader = new(DownloadHelper.Configuration))
529+
using (DownloadService downloader = new(DownloadHelper.Configuration, SettingsHelper.LoggerFactory))
530530
{
531531
bool isCompleted = false;
532532
Exception exception = null;
@@ -1126,7 +1126,7 @@ private async ValueTask DownloadAPKAsync()
11261126
{
11271127
Directory.Delete(APKTemp, true);
11281128
}
1129-
using (DownloadService downloader = new(DownloadHelper.Configuration))
1129+
using (DownloadService downloader = new(DownloadHelper.Configuration, SettingsHelper.LoggerFactory))
11301130
{
11311131
bool isCompleted = false;
11321132
Exception exception = null;

APKInstaller/Zeroconf/ZeroconfResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Zeroconf
1818
public static partial class ZeroconfResolver
1919
{
2020
private static readonly AsyncLock ResolverLock = new();
21-
private static readonly INetworkInterface NetworkInterface = new NetworkInterface();
21+
private static readonly NetworkInterface NetworkInterface = new();
2222

2323
private static IEnumerable<string> BrowseResponseParser(Response response) =>
2424
response.RecordsPTR.Select(ptr => ptr.PTRDNAME);

0 commit comments

Comments
 (0)