Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevTools can't inspect views that aren't windows or single view of a mobile app #10296

Closed
kekekeks opened this issue Feb 10, 2023 · 6 comments · Fixed by #10510
Closed

DevTools can't inspect views that aren't windows or single view of a mobile app #10296

kekekeks opened this issue Feb 10, 2023 · 6 comments · Fixed by #10510
Assignees
Labels
Milestone

Comments

@kekekeks
Copy link
Member

For some reason it's now tightly coupled with application lifetimes (those aren't guaranteed to be present at all) and only shows windows or the main view. So it's no longer possible to inspect any embedded TopLevels.

Since it's a regression from 0.10.x I'm considering to revert #6771

@kekekeks kekekeks added the bug label Feb 10, 2023
@kekekeks kekekeks added this to the 11.0 milestone Feb 10, 2023
@kekekeks kekekeks changed the title DevTools can't inspect views that aren't Windows DevTools can't inspect views that aren't windows or single view of a mobile app Feb 10, 2023
@workgroupengineering
Copy link
Contributor

I don't agree to copletaly revert the PR. Original PR can manage both path, see this. If you want, I can fix the current behavior to handle both molality.

@workgroupengineering
Copy link
Contributor

Hi, @kekekeks
What is issue you found?
I have moditfy following file:

./samples/MobileSandbox/App.xaml.cs

    public class App : Application
    {
        public override void Initialize()
        {
            AvaloniaXamlLoader.Load(this);
        }

        public override void OnFrameworkInitializationCompleted()
        {
            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
            {
                desktopLifetime.MainWindow = new MainWindow();
            }
            else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewLifetime)
            {
                singleViewLifetime.MainView = new MainView();
            }

            base.OnFrameworkInitializationCompleted();
+            this.AttachDevTools(new()
+            {
+                StartupScreenIndex = 1,
+            });
        }
    }

./samples/MobileSandbox.Desktop/Program.cs

 using System;
 using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.ApplicationLifetimes;
 
 namespace MobileSandbox.Desktop
 {
     static class Program
     {
         [STAThread]
-        static int Main(string[] args) =>
-            BuildAvaloniaApp()
+        static int Main(string[] args)
+        {
+            var lt = new MyClass();
+            var app = BuildAvaloniaApp()
                 .StartWithClassicDesktopLifetime(args);
+            lt.Start();
+            return app;
+        }
 
         /// <summary>
         /// This method is needed for IDE previewer infrastructure
@@ -18,4 +25,17 @@ public static AppBuilder BuildAvaloniaApp()
                 .UsePlatformDetect()
                 .LogToTrace();
     }
+
+    class MyClass : ISingleViewApplicationLifetime
+    {
+        public Control MainView { get ; set; }
+        public void Start()
+        {
+            var host = new MainWindow()
+            {
+                Content = MainView,
+            };
+            host.Show();
+        }
+    }
 }

And i try run, it work as expected.

@kekekeks
Copy link
Member Author

kekekeks commented Feb 11, 2023

  1. try attaching devtools to a window when running without application lifetime (e. g. builder.Start((app, _) => app.RunWithMainWindow<MainWindow>(), args);)
  2. try attaching devtools to embedded toplevels in WindowsInteropTest test app

@kekekeks
Copy link
Member Author

kekekeks commented Feb 11, 2023

Note, that application lifetimes have always been an entirely optional feature and are documented as such. Even ApplicationLifetime property is nullable. Nothing in the framework should break if there is no registered lifetime.

This is important for various embedding scenarios like this one:

unreal.mp4

@workgroupengineering
Copy link
Contributor

workgroupengineering commented Feb 16, 2023

OK! I got it. Can you give me a sample repo to try and fix this?

Note, that application lifetimes have always been an entirely optional feature and are documented as such. Even ApplicationLifetime property is nullable. Nothing in the framework should break if there is no registered lifetime.

This is important for various embedding scenarios like this one:

@maxkatz6
Copy link
Member

@workgroupengineering
AppMain.zip

[STAThread]
public static void Main(string[] args)
{
    BuildAvaloniaApp().Start(AppMain, args);
}

private static void AppMain(Application app, string[] args)
{
    app.Run(new MainWindow());
}

public static AppBuilder BuildAvaloniaApp()
    => AppBuilder.Configure<App>()
        .UsePlatformDetect()
        .LogToTrace();

mjcheetham added a commit to mjcheetham/git-credential-manager that referenced this issue Sep 28, 2023
The issue AvaloniaUI/Avalonia#10296 has been
fixed so we can now remove this workaround.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants