Skip to content

Commit

Permalink
Fixed new version handling
Browse files Browse the repository at this point in the history
• Message is no longer shown before UI rendering is finalized
• Message on new version availability no longer conflicts with message on release notes
  • Loading branch information
Alex4SSB committed Jan 5, 2025
1 parent eae4559 commit 7d5aa44
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
36 changes: 32 additions & 4 deletions ADB Explorer/Helpers/AppInfra/SettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,44 @@ public static async void SplashScreenTask()
Data.RuntimeSettings.FinalizeSplash = true;
}

public static async void CheckForUpdates()
public static async void CheckAppVersions()
{
Version currentVersion = new(Properties.Resources.AppVersion);
if (currentVersion > new Version(Data.Settings.LastVersion))
{
await App.Current.Dispatcher.Invoke(async () =>
{
var res = await DialogService.ShowConfirmation(
Strings.S_NEW_VERSION_MSG,
"New Version",
"Go To Release Notes",
cancelText: "Close");

if (res.Item1 is ContentDialogResult.Primary)
Process.Start(Data.RuntimeSettings.DefaultBrowserPath, $"\"https://github.com/Alex4SSB/ADB-Explorer/releases/tag/v{Properties.Resources.AppVersion}\"");
});

Data.Settings.LastVersion = Properties.Resources.AppVersion;
}

if (Data.RuntimeSettings.IsAppDeployed || !Data.Settings.CheckForUpdates)
return;

var version = await Network.LatestAppReleaseAsync();
if (version is null || version <= Data.AppVersion)
var latestVersion = await Network.LatestAppReleaseAsync();
if (latestVersion is null || latestVersion <= Data.AppVersion)
return;

App.Current.Dispatcher.Invoke(() => DialogService.ShowMessage(Strings.S_NEW_VERSION(version), Strings.S_NEW_VERSION_TITLE, DialogService.DialogIcon.Informational));
await App.Current.Dispatcher.Invoke(async () =>
{
var res = await DialogService.ShowConfirmation(Strings.S_NEW_VERSION(latestVersion),
Strings.S_NEW_VERSION_TITLE,
"Go To Version Page",
cancelText: "Close",
icon: DialogService.DialogIcon.Informational);

if (res.Item1 is ContentDialogResult.Primary)
Process.Start(Data.RuntimeSettings.DefaultBrowserPath, $"\"https://github.com/Alex4SSB/ADB-Explorer/releases/tag/v{latestVersion}\"");
});
}

public static void ShowAndroidRobotLicense()
Expand Down
19 changes: 2 additions & 17 deletions ADB Explorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public MainWindow()
});
}

private async void FinalizeSplash()
private void FinalizeSplash()
{
SetTheme();

Expand All @@ -159,20 +159,7 @@ private async void FinalizeSplash()

RuntimeSettings.MainWinRect = new Rect(PointToScreen(new(0, 0)), new Size(ActualWidth, ActualHeight));

Version version = new(Properties.Resources.AppVersion);
if (version > new Version(Settings.LastVersion))
{
var res = await DialogService.ShowConfirmation(
S_NEW_VERSION_MSG,
"New Version",
"Go To Release Notes",
cancelText:"Close");

if (res.Item1 is ContentDialogResult.Primary)
Process.Start(Data.RuntimeSettings.DefaultBrowserPath, $"\"https://github.com/Alex4SSB/ADB-Explorer/releases/tag/v{Properties.Resources.AppVersion}\"");

Settings.LastVersion = Properties.Resources.AppVersion;
}
SettingsHelper.CheckAppVersions();
}

private void DiskUsageTimer_Tick(object sender, EventArgs e)
Expand Down Expand Up @@ -891,8 +878,6 @@ private void LaunchSequence()

DeviceHelper.UpdateWsaPkgStatus();

SettingsHelper.CheckForUpdates();

UpdateFileOpFilterCheck();

FileToIcon = new();
Expand Down
22 changes: 11 additions & 11 deletions ADB Explorer/Services/ADB/ADBService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public static string GetMmcId(string deviceID)

// Get a list of all volumes (and their nodes)
// The public flag reduces execution time significantly
int exitCode = ExecuteDeviceAdbShellCommand(deviceID, "sm", out string stdout, out _, new(), "list-volumes", "public");
int exitCode = ExecuteDeviceAdbShellCommand(deviceID, "sm", out string stdout, out _, CancellationToken.None, "list-volumes", "public");
if (exitCode != 0)
return "";

Expand All @@ -314,33 +314,33 @@ public static string GetMmcId(string deviceID)

public static bool CheckMDNS()
{
var res = ExecuteAdbCommandAsync("mdns", new(), "check");
var res = ExecuteAdbCommandAsync("mdns", CancellationToken.None, "check");

return res.First().Contains("mdns daemon version");
}

public static void KillAdbServer(bool restart = false)
{
ExecuteAdbCommand("kill-server", out _, out _, new());
ExecuteAdbCommand("kill-server", out _, out _, CancellationToken.None);

if (restart)
ExecuteAdbCommand("start-server", out _, out _, new());
ExecuteAdbCommand("start-server", out _, out _, CancellationToken.None);
}

public static bool KillAdbProcess()
{
return ExecuteCommand("taskkill", "/f", out _, out _, Encoding.UTF8, new(), "/im", "\"adb.exe\"") == 0;
return ExecuteCommand("taskkill", "/f", out _, out _, Encoding.UTF8, CancellationToken.None, "/im", "\"adb.exe\"") == 0;
}

public static bool Root(Device device)
{
ExecuteDeviceAdbCommand(device.ID, "", out string stdout, out _, new(), Settings.RootArgs);
ExecuteDeviceAdbCommand(device.ID, "", out string stdout, out _, CancellationToken.None, Settings.RootArgs);
return !stdout.Contains("cannot run as root");
}

public static bool Unroot(Device device)
{
ExecuteDeviceAdbCommand(device.ID, "", out string stdout, out _, new(), Settings.UnrootArgs);
ExecuteDeviceAdbCommand(device.ID, "", out string stdout, out _, CancellationToken.None, Settings.UnrootArgs);
var result = stdout.Contains("restarting adbd as non root");
DevicesObject.UpdateDeviceRoot(device.ID, result);

Expand All @@ -349,7 +349,7 @@ public static bool Unroot(Device device)

public static bool WhoAmI(string deviceId)
{
if (ExecuteDeviceAdbShellCommand(deviceId, "whoami", out string stdout, out _, new()) != 0)
if (ExecuteDeviceAdbShellCommand(deviceId, "whoami", out string stdout, out _, CancellationToken.None) != 0)
return false;

return stdout.Trim() == "root";
Expand All @@ -359,7 +359,7 @@ public static ulong CountFiles(string deviceID, string path, IEnumerable<string>
{
string[] args = PrepFindArgs(path, includeNames, excludeNames, true);

ExecuteDeviceAdbShellCommand(deviceID, "find", out string stdout, out _, new(), args);
ExecuteDeviceAdbShellCommand(deviceID, "find", out string stdout, out _, CancellationToken.None, args);

return ulong.TryParse(stdout, out var count) ? count : 0;
}
Expand All @@ -368,14 +368,14 @@ public static string[] FindFilesInPath(string deviceID, string path, IEnumerable
{
string[] args = PrepFindArgs(path, includeNames, excludeNames, false, caseSensitive);

ExecuteDeviceAdbShellCommand(deviceID, "find", out string stdout, out _, new(), args);
ExecuteDeviceAdbShellCommand(deviceID, "find", out string stdout, out _, CancellationToken.None, args);

return stdout.Split(LINE_SEPARATORS, StringSplitOptions.RemoveEmptyEntries);
}

public static string[] FindFiles(string deviceID, IEnumerable<string> paths)
{
ExecuteDeviceAdbShellCommand(deviceID, "find", out string stdout, out _, new(), paths.Select(item => EscapeAdbShellString(item)).Append(@"2>/dev/null").ToArray());
ExecuteDeviceAdbShellCommand(deviceID, "find", out string stdout, out _, CancellationToken.None, paths.Select(item => EscapeAdbShellString(item)).Append(@"2>/dev/null").ToArray());

return stdout.Split(LINE_SEPARATORS, StringSplitOptions.RemoveEmptyEntries);
}
Expand Down

0 comments on commit 7d5aa44

Please sign in to comment.