-
Notifications
You must be signed in to change notification settings - Fork 239
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
Customisation #175
Customisation #175
Conversation
…ldm/vimari into nieldm-feature/access_configuration
Due to the extra options introduced by @nieldm the layout of the application panel became increasingly vertical. This change introduces a two column layout that shows the icon and app name on the left side while showing the actionable buttons on the right side.
As the application name is provided in the title bar it can be removed from the ui in the helper application to reduce clutter.
Due to not being able to request the containing tab of a pinned tab (as they don't have one), a bug was introduced that did not allow the user to switch tabs if the active tab was a pinned one. This change introduces some additional logic that in this case returns the current active window.
As there are twoo distinct methods that both handle messages I added documentation to clarify the distinction between the two.
The use of .getSettings could be confusing in the sense that it would seem to return the current user preferences, the implementation however loads the default settings. Hence the rename of the function.
The Vimari Extension is used as the backend for the Extension, therefore no longer requiring the use of the global.js file.
The .updateSettings and .fallbackSettings methods used the activePage as target for their dispatch. However we have access to the requesting page through the .messageRecieved function which should be used instead.
The communication between the safari extension and the actual JavaScript can be difficult to understand at first, therefore I decided to abstract the logic into a separate class/file. Thereby giving a name to logic indicating the communication with a separate entity.
In line with the previous commit (240ffc7) we move the assignment of an event listener for the messages from the Extension to the SafariExtensionCommunicator.
Likely because of the previous working the code for opening a new tab was extracted into a separate function. However now that we call the Vimari Extension for this behaviour the code should be called in the same way as for example the close tab action. Therefore it is placed directly in the actionmap.
I think JSON is fine here, it avoids an extra dependency and I'm not a huge fan of YAML in general. If we can check the JSON before save and avoid saving invalid JSON that should solve most of the issues.
Yep, this would be idiomatic behaviour. NSUserDefaults behaves this way, and is likely what we'd want to use long-term.
I think this is in progress in #176 now?
Yep, this seems like a good idea. SwiftFormat and Prettier would be my preferences for formatting. I have a weak preference for ESLint for linting JS, I have no opinions on linting Swift.
Generally they would end up in Zooming out a little bit:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't say I 100% understand everything that is happening here, but I'm happy with the approach you're taking. Merge when you're ready. Thanks for your hard work on this!
Okay this is fine by me.
I'll make an issue for both of these.
Yes it is.
SwiftFormat and Prettier both provide some default configuration we could use of the box. Prettier also seems to have an experimental plugin for Swift but I think we should stick with SwiftFormat instead. I'll make an issue out of this.
These changes: configuration (this issue), isolation (#176), smooth scrolling and possibly a help mode would bring Vimari to a good point. From there it would be interesting to see how far we can get with Vimium using WebExtensions for Safari. If I find the time this weekend I might have another go at trying to get Vimium working (for those interested: philc/vimium#3610). |
Co-authored-by: Daniel Compton <desk@danielcompton.net>
Has this been submitted for review? Would love to be able to use it! |
Any luck on the Vimium port to WebExtensions? If you need any help, let me know. I'm interested in contributing. |
Resolves #142
As specified in #172 I started bringing some of my work on Vimari from my own fork into the main repo. This PR is the first of these, it builds upon the work of @nieldm to bring customisation back to Vimari.
Changes
Instead of creating a PR from my own fork (which mainly consists of one branch with all the features I wanted to see) I decided to take a fresh look on the changes by nieldm, fix some of the bugs and clear up some of the related code:
Removed some of the legacy code that was related to the now legacy configuration handling (
global.js
and some functions ininjected.js
).Remove
closeTabReverse
as it was no longer supported through the Safari Extension. This could be added back in, but seemed like something for a separate pull request.Update the layout from being extremely vertical (see Enabled option to edit configuration file #163) to a more compact two-column layout:
This was introduced by the Vimari Extension handling tab switching. This code tried to find the active window from the current tab, however pinned tabs do not have a specific window as they appear in all Safari windows. Therefore the code returned
nil
and therefore tab switching did not work. I was able to resolve this behaviour by using the activeWindow as default value in case we are not able to retrieve the window for a page: (see this extract fromSafariExtensionHandler.swift
)As a new tab need to be opened through the Vimari Extension a url needs to be provided. I experimented with using
topsites.com
andtopsites://
to open the default Safari start page, however the.openTab
function does not see those as valid urls. Since this PR introduces configuration back into Vimari I introduced aopenTabUrl
setting that can be set by the user.Configuration
So currently the default configuration (if it does not exist) will be placed in
~/Library/Containers/net.televator.Vimari.SafariExtension/Data/
. This is the location we get when using the following code:I'm not sure if this is the correct way to go about it. When using the
.applicationSupportDirectory
instead of.documentDirectory
in our call toFileManager.default.url
the url becomes~/Library/Containers/net.televator.Vimari.SafariExtension/Data/Library/
which leads me to believe that both are good choices as they seem to be placed in some sort of container specifically for Vimari. I was not able to find anything specific on developer.apple.com except for hig/macos/architecture/preferences, however the page does not mention a preferred location for configuration files on the os.The configuration file looks as follows (by default):
Whats next?
I don't think this PR is the final step in adding customisation to Vimari. Currently I see some issues that we should address (perhaps before releasing this to the app store):
Validation of the configuration
There are many pitfalls where a user could make a wrong change in the configuration that could potentially break the extension for her. For example not providing a correct url for
openTabUrl
would disable the newTab functionality (as it fails). More worrying though is if a user misses something crucial to the json structure. In the current implementation this would revert the user back to the default settings without any feedback, likely causing confusion.Perhaps YAML could be a better alternative here as it requires less syntax, feedback would be appreciated.
A longer term goal would be to implement the configuration in the UI of Vimari.App (while keeping the file option for advanced users).
Future configuration options
Given the current implementation it might be difficult to add configuration options in the future. Which is something that is already being requested (copy current tab url with 'yy' #173). This would require us to add/remove configuration options from a user customised file. My best guess here is to change the implementation to use the user configuration as overrides to the default one. This would allow us to add new configuration options, which the user could then override, and remove configuration options, by simply only looking for overrides for the default options. All while leaving the user configuration alone. Again feedback would be appreciated.
Proper insert/normal mode
Some of the requests for configuring keybindings (like in Add more key bindings + ability to assign own key bindings #171) stem from an overlap with the keybindings present on a given website. In my fork of Vimari I have resolved this by creating a proper separation between insert and normal mode. This will be where I put my focus after this pull request.
Linting (not related to configurability)
While making these changes I found there no linting setup for Swift or JavaScript. I think contributors would greatly benefit from a linting setup for both of these languages as it would remove the need to try and replicate the same code style and would enhance readability of the code as all will have a similar structure.
My apologies for the somewhat large PR, while summarising my changes above I clearly see how I could have done a better job at creating smaller and more easily reviewable changes. I hope that the explanation given together with the commit messages helps guide you through the changes. For future development I will take this into account, feedback is very welcome!