mirror of
https://github.com/tgeorgiadis/quiver-launcher.git
synced 2026-11-24 22:38:03 -05:00
Quiver asks once, after the welcome or on the first start after updating, whether it may send anonymous usage data. It stays off unless they say yes, and Settings > General > Usage data changes it later. Events go to the same PostHog project as the website and the v4 launcher, marked app "launcher-csharp", with a random install id and no names, files or folders (paths and the OS user name are scrubbed). They cover starts, screens, installs, updates, launches, uninstalls, adds, mods, catalog failures and searches with no results, and errors go to error tracking. Release builds take the project token from the POSTHOG_PROJECT_TOKEN repository variable; without it nothing is sent and nothing is asked.
92 lines
3.9 KiB
C#
92 lines
3.9 KiB
C#
using Android.App;
|
|
using Android.Content.PM;
|
|
using Android.OS;
|
|
using Android.Views;
|
|
using Avalonia.Android;
|
|
using QuiverLauncher.Services;
|
|
|
|
namespace QuiverLauncher.Android;
|
|
|
|
[Activity(
|
|
Label = "Quiver Launcher",
|
|
Theme = "@style/MyTheme.NoActionBar",
|
|
Icon = "@mipmap/ic_launcher",
|
|
MainLauncher = true,
|
|
LaunchMode = LaunchMode.SingleTop,
|
|
WindowSoftInputMode = SoftInput.AdjustResize,
|
|
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.UiMode)]
|
|
public class MainActivity : AvaloniaMainActivity
|
|
{
|
|
private AndroidLauncherInstaller? _launcherInstaller;
|
|
private SidebarGestureExclusion? _sidebarGestureExclusion;
|
|
protected override void OnCreate(Bundle? savedInstanceState)
|
|
{
|
|
var filesDirectory = FilesDir?.AbsolutePath;
|
|
QuiverLauncherPaths.AndroidFilesDirProvider = () => filesDirectory;
|
|
AppInstallLaunch.Current = new AndroidAppInstallLaunchService(this);
|
|
_launcherInstaller = new AndroidLauncherInstaller(this);
|
|
if (AndroidLauncherUpdater.Current == null)
|
|
AndroidLauncherUpdater.Current = new AndroidLauncherUpdater(new HttpClient { Timeout = TimeSpan.FromMinutes(30) },
|
|
Path.Combine(filesDirectory!, "launcher-updates"), _launcherInstaller, () => AppSettings.Load(),
|
|
action => Avalonia.Threading.Dispatcher.UIThread.Post(action));
|
|
else AndroidLauncherUpdater.Current.Installer = _launcherInstaller;
|
|
QuiverLauncherPaths.EnsureUserDataRootExists();
|
|
base.OnCreate(savedInstanceState);
|
|
if (OperatingSystem.IsAndroidVersionAtLeast(29) && Window?.DecorView is { } decor)
|
|
{
|
|
_sidebarGestureExclusion = new SidebarGestureExclusion(decor,
|
|
() => Content is MainView view && view.CanOpenMobileNavigation);
|
|
decor.ViewTreeObserver?.AddOnPreDrawListener(_sidebarGestureExclusion);
|
|
if (Content is MainView mainView)
|
|
mainView.LayoutUpdated += UpdateSidebarGestureExclusion;
|
|
}
|
|
}
|
|
|
|
private void UpdateSidebarGestureExclusion(object? sender, EventArgs e)
|
|
{
|
|
if (OperatingSystem.IsAndroidVersionAtLeast(29))
|
|
_sidebarGestureExclusion?.OnPreDraw();
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
if (Content is MainView mainView)
|
|
mainView.LayoutUpdated -= UpdateSidebarGestureExclusion;
|
|
if (OperatingSystem.IsAndroidVersionAtLeast(29) && _sidebarGestureExclusion != null)
|
|
{
|
|
Window?.DecorView?.ViewTreeObserver?.RemoveOnPreDrawListener(_sidebarGestureExclusion);
|
|
_sidebarGestureExclusion.Dispose();
|
|
_sidebarGestureExclusion = null;
|
|
}
|
|
_launcherInstaller?.Detach();
|
|
// Dispose only this activity's view; a replacement activity may already exist.
|
|
if (Content is MainView view)
|
|
view.HandleClosed();
|
|
base.OnDestroy();
|
|
}
|
|
|
|
protected override void OnActivityResult(int requestCode, Result resultCode, global::Android.Content.Intent? data)
|
|
{
|
|
base.OnActivityResult(requestCode, resultCode, data);
|
|
_launcherInstaller?.ActivityResult(requestCode);
|
|
if (requestCode == AndroidAppInstallLaunchService.InstallRequestCode)
|
|
AndroidAppInstallLaunchService.CompleteInstall(resultCode == Result.Ok);
|
|
else if (requestCode == AndroidAppInstallLaunchService.UninstallRequestCode)
|
|
AndroidAppInstallLaunchService.CompleteUninstall(resultCode == Result.Ok);
|
|
}
|
|
|
|
protected override void OnPause()
|
|
{
|
|
// The player may not come back before Android ends the process: send usage data now.
|
|
_ = Telemetry.Current.FlushAsync();
|
|
base.OnPause();
|
|
}
|
|
|
|
protected override void OnResume()
|
|
{
|
|
base.OnResume();
|
|
if (!VelopackUpdateService.ShouldSkipAutomaticSelfUpdate())
|
|
_ = AndroidLauncherUpdater.Current?.CheckAsync();
|
|
}
|
|
}
|