Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Conversation

@timkur
Copy link
Contributor

@timkur timkur commented Jul 29, 2024

Summary of the pull request

This moves the Clipboard monitoring tool out from an expando in the Extended Control and is treated like any other external tool. On launching it, a new undocked window opens that contains the clipboard monitor.

image

The clipboard monitor can be pinned/unpinned from the bar. However, it currently can't be unregistered like other tools.

Note, the goal here is to reduce folks dependencies on http://error and make it really quick and easy to do decimal<->hex conversions and lookup Windows error codes.

References and relevant issues

Detailed description of the pull request / Additional comments

While I have a command class for both external and internal tools (Tool.cs) I do have them separate for now. The biggest reason that I didn't try to combine the implementation even more is (a) I wanted to keep the clipboard monitor running in-proc, and (b) I didn't want settings persisted in the externaltools.json file that could be deleted/modified/etc, The code is pretty simple right now to take everything in externaltools.json wholesale, and didn't want to muck with that. So persistent settings, like if the Clipboard Monitor is pinned, is stored in app settings vs the JSON database.

This is only hooked up in the horizontal bar view. Rather than write duplicate code to put it in the vertical bar, I'm going to wait and hopefully will get it for free when the vertical bar moves to using a CommandBar.

Validation steps performed

PR checklist

  • Closes #xxx
  • Tests added/passed
  • Documentation updated

@timkur timkur changed the title User/timkur/updated clipboard monitor Move clipboard monitor to be a standalone tool Jul 30, 2024
@timkur timkur marked this pull request as ready for review July 30, 2024 00:36
@timkur timkur changed the title Move clipboard monitor to be a standalone tool Project Ironsides - Move clipboard monitor to be a standalone tool Jul 30, 2024
Copy link
Contributor

@jaholme jaholme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

{
var process = await InvokeToolInternal(targetProcessId, hWnd);
}
catch (Exception ex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Catch InvalidOperationException instead because the exception InvokeToolInternal throws is InvalidOperationException

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I don't want any exception to be unhandled here. Is there an advantage to only catching one type of exception?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readability and adding intent to the code. Catching InvalidOperationException tells readers that the method knows how to deal with that particular exception.

If the method can't do anything helpful for other exceptions, it should bubble up to a try/catch in the stack.

Also, InvokeToolExternal already catches Exception so InvokeTool will never get an Exception from InvokeToolsExternal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does pop an error message letting the user know that it couldn't launch a tool. Nobody further up the stack has anything more to say about it. For errors launching a tool, the buck stops here.

@timkur timkur requested a review from xhan65 July 31, 2024 05:59

public ClipboardMonitorControlViewModel()
{
_dispatcher = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the rest of Dev Home it's not good to use this, since we may not be on the UI thread, and therefore this may return null. Is different in PI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in PI we always create the view model in the view's constructor. When does DevHome create its view models?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes in view's constructor, but often in services registered with the host.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh... so your services push data to a singleton view models vs having the view models pull data from the services?

We did go down that path a bit, but since our views can come and go, it became a pain to "retarget" the view model to new views when they went away. So now our services/models maintain state, and view models can come and go and query that/register callbacks/etc when needed.

@timkur timkur merged commit 749e7ab into main Jul 31, 2024
@krschau krschau added this to the Dev Home v0.17 milestone Aug 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants