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

Hex viewer #31

Merged
merged 7 commits into from
May 4, 2024
Merged

Hex viewer #31

merged 7 commits into from
May 4, 2024

Conversation

davedelong
Copy link
Contributor

This adds a hex viewer to Pasteboard Viewer and fixes #24.

This uses the HexFiend framework to add a hex viewer to the app, which can be accessed by toggling a picker in the toolbar.

Some things to note:

  • This depends on the package branch of the HexFiend project, as that is the branch that adds a Package.swift file. It is technically unreleased, although it appears to be fully functional.
  • The format of the "extra info" in the toolbar is meant to mimic the format shown in the Hex Fiend app as closely as possible.
  • Selection is not preserved when toggling between text and hex modes.
Screenshot 2024-05-02 at 9 10 09 PM Screenshot 2024-05-02 at 9 10 21 PM

@sindresorhus
Copy link
Owner

Thanks for working on this! This is already looking pretty good.

  • You need to if-def it out for iOS.
  • The selection needs to be reset when the pasteboard changes.
    • I also think it makes sense to reset the selection when switching between pasteboard items.
  • I noticed it's quite slow to select something when viewing an image. Not sure if the problem is the framework or the wrapper code.
  • Would be useful to have the text/hex picker in the "View" menu bar menu too, with keyboard shortcuts. But not a requirement for this pull request.

Pasteboard Viewer/ContentsScreen.swift Outdated Show resolved Hide resolved
Pasteboard Viewer/ContentsScreen.swift Outdated Show resolved Hide resolved
Pasteboard Viewer/ContentsScreen.swift Outdated Show resolved Hide resolved
- macOS only
- extract extra into to helper property
- appease the SwiftLint gods
- simplify HexView.Coordinator
When either the selected type changes or there's new data on the pasteboard, force the contents view to reset, thereby losing selection state
@davedelong
Copy link
Contributor Author

  • I noticed it's quite slow to select something when viewing an image. Not sure if the problem is the framework or the wrapper code.

I took a quick look at this in instruments, and from what I can tell there's an identical spike when showing the text view as showing the hex view. I'm reasonably confident that this is down to retrieving the type.data() from the pasteboard to provide to the UI. There's probably an optimization that could be made there around caching it once it's been read, so that subsequent calls to .data() are instantaneous.

@davedelong
Copy link
Contributor Author

Besides the hiccup when showing large datas (like images), all the other feedback has been addressed, including adding the ⌘1 and ⌘2 switcher in the View menu. 😃

@davedelong
Copy link
Contributor Author

(I also confirmed that the branch builds cleanly for iOS)

@sindresorhus sindresorhus merged commit 3c96cbd into sindresorhus:main May 4, 2024
@sindresorhus
Copy link
Owner

Looks great 🙌

@sindresorhus
Copy link
Owner

Update submitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hex screen
2 participants