Skip to content

Commit

Permalink
AttachDevTools (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarfgp authored Nov 15, 2024
1 parent 8b51fe4 commit 24a52c3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
17 changes: 9 additions & 8 deletions extensions/Fabulous.Avalonia.Diagnostics/DevTools.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,44 @@

open System.Runtime.CompilerServices
open Avalonia
open Avalonia.Controls
open Avalonia.Diagnostics
open Fabulous
open Fabulous.Avalonia

module DevTools =
let AttachDevTools =
Attributes.defineProperty "Application_AttachDevTools" (ValueNone, ValueNone) (fun target (value: DevToolsOptions voption * Input.KeyGesture voption) ->
let app = target :?> FabApplication
Attributes.defineProperty "MainWindow_AttachDevTools" (ValueNone, ValueNone) (fun target (value: DevToolsOptions voption * Input.KeyGesture voption) ->
let app = target :?> Window
let options, gesture = value

if options.IsSome then
app.MainWindow.AttachDevTools(options.Value)
app.AttachDevTools(options.Value)
else if gesture.IsSome then
app.MainWindow.AttachDevTools(gesture.Value)
app.AttachDevTools(gesture.Value)
else
app.MainWindow.AttachDevTools())
app.AttachDevTools())

type DevToolsModifiers =
/// <summary>Attaches the Avalonia Developer Tools with the specified options.
/// See https://docs.avaloniaui.net/docs/guides/implementation-guides/developer-tools</summary>
/// <param name="this">The Current widget.</param>
/// <param name="value">The Developer Tools options.</param>
[<Extension>]
static member inline attachDevTools(this: WidgetBuilder<'msg, #IFabApplication>, value: DevToolsOptions) =
static member inline attachDevTools(this: WidgetBuilder<'msg, #IFabWindow>, value: DevToolsOptions) =
this.AddScalar(DevTools.AttachDevTools.WithValue((ValueSome value, ValueNone)))

/// <summary>Attaches the Avalonia Developer Tools with the specified gesture.
/// See https://docs.avaloniaui.net/docs/guides/implementation-guides/developer-tools</summary>
/// <param name="this">The Current widget.</param>
/// <param name="value">The key gesture.</param>
[<Extension>]
static member inline attachDevTools(this: WidgetBuilder<'msg, #IFabApplication>, value: Input.KeyGesture) =
static member inline attachDevTools(this: WidgetBuilder<'msg, #IFabWindow>, value: Input.KeyGesture) =
this.AddScalar(DevTools.AttachDevTools.WithValue((ValueNone, ValueSome value)))

/// <summary>Attaches the Avalonia Developer Tools opened using F12.
/// See https://docs.avaloniaui.net/docs/guides/implementation-guides/developer-tools</summary>
/// <param name="this">The Current widget.</param>
[<Extension>]
static member inline attachDevTools(this: WidgetBuilder<'msg, #IFabApplication>) =
static member inline attachDevTools(this: WidgetBuilder<'msg, #IFabWindow>) =
this.AddScalar(DevTools.AttachDevTools.WithValue((ValueNone, ValueNone)))
12 changes: 4 additions & 8 deletions samples/Gallery/MainWindow.fs
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,17 @@ module MainWindow =
Component("MainWindow") {
let! model = Context.Mvu program

(DesktopApplication() {
(Window() { hamburgerMenu model })
DesktopApplication() {
Window(hamburgerMenu model)
.title("Fabulous Gallery")
.menu(createMenu())
.width(1024.)
.height(800.)
.icon("avares://Gallery/Assets/Icons/logo.ico")
})
// FIXME this is not working after the last update of Fabulous pre 8
// MainWindow is null for some reason. I will investigate this later.
// Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'root')
// at Avalonia.Diagnostics.DevTools.Attach(TopLevel root, DevToolsOptions options)
#if DEBUG
.attachDevTools()
.attachDevTools()
#endif
}
|> _.trayIcon(trayIcon())
|> _.requestedThemeVariant(model.CurrentTheme)
}
Expand Down
10 changes: 6 additions & 4 deletions samples/Playground/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ module App =
#if MOBILE
SingleViewApplication(content())
#else
DesktopApplication(Window(content()))
#endif

DesktopApplication(
Window(content())
#if DEBUG
.attachDevTools()
.attachDevTools()
#endif
)
#endif


let create () =
FabulousAppBuilder.Configure(FluentTheme, view)
3 changes: 3 additions & 0 deletions samples/RenderDemo/MainWindow.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ module MainWindow =
})
.expandedModeThresholdWidth(760)
}
#if DEBUG
|> _.attachDevTools()
#endif
}

let create () =
Expand Down
1 change: 1 addition & 0 deletions samples/RenderDemo/RenderDemo.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Fabulous.Avalonia\Fabulous.Avalonia.fsproj" />
<ProjectReference Include="..\ControlSamples\ControlSamples.csproj" />
<ProjectReference Include="..\..\extensions\Fabulous.Avalonia.Diagnostics\Fabulous.Avalonia.Diagnostics.fsproj" />
</ItemGroup>
</Project>

0 comments on commit 24a52c3

Please sign in to comment.