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

[WIP] Migrate to Swift #391

Closed
wants to merge 333 commits into from
Closed

[WIP] Migrate to Swift #391

wants to merge 333 commits into from

Conversation

oleander
Copy link

@oleander oleander commented Jan 14, 2017

This pull request aims to add support for Swift 3. It's based up-on the beta branch and implements support for all parameters described in the README. The main goal has been to modernize the application stack by implementing a combinatory LL parser verified using property-based testing.

The parser

The parser, the piece of software responsible for processing script outputs, is implemented using the FootlessParser parser and is located in App/BitBar/Parser/Parser.swift. It's build up-on 50+ smaller parser (hence the name; parser combinator), such as Length.init <^> attribute("length") { digits() } for parsing the length attribute (length=X).

The parser is context aware and will handle nested sub menus as well as invalid arguments, i.e length=false. One of the major benefits of using a parser like this ability to generate easy-to-understand error messages much similar to those generated by a compiler/transpiler. This makes implementing plugins easier as errors are caught and raised early. An example is Expected 'a number' on 3:12, but got 'false' when passing length=false.

Testing

The parser is verified using the SwiftCheck library, a property-based testing framework for generating test data. The current test suit is ran against 1400 random examples.

The rest of the implementation is partially tested (about 80 tests) using the Quick testing framework.

Run make test to run the suit once or make watch to run make test each time a file is changed. Don't forget to install the dependencies listed below.

The application is ready for travis-ci and the latest builds can be found here.

Dependencies

I've tried to "out source" as much of the implementation as possible to external libraries using CocoaPods. There's currently 11 dependencies which can be found the in the App/Podfile file. They are automatically installed when running make deps.

How to use

  1. Clone the project
  2. Install project dependencies using
    1. gem install cocoapods xcpretty
    2. make deps to install the pods
  3. Run tests suit using make test
  4. Build and run using XCode by opening App/BitBar.xcworkspace. This will use the App/Scripts/sub.1m.sh example script and output something like

skarmavbild 2017-01-14 kl 18 37 31

What's next

  • Test quoted values, i.e href="...". Implementation is done but hasn't been tested using SwiftCheck
  • Better error messages
  • (Re)implement
    • The preference menus
    • Sparkle for updates
  • Dynamic plugin path. The current one is hard coded
  • Refactor test suit, custom matchers?
  • Handle both ANSI and truncate for the same title
  • The font size is a bit off right now, not really sure why

Flow

This is the basic flow of data in the application. I tried to use the same naming convention as the existing application.

skarmavbild 2017-01-14 kl 19 18 09

A summery

  • Parser with support for
    • ANSI colors
    • Params (length, trim and so on)
    • Menus
    • Infinitive number of sub menus
  • CocoaPods for dependency management
  • Property-based testing using SwiftCheck
  • BDD/TDD using the Quick framework
  • XCode independent, using xcpretty for output formatting and make watch as file watcher
  • Swiftlint compatible (make fix and make lint uses this)
  • Makefile based on the Alcatraz project
  • Gitignore from github/gitignore
  • Travis-ci compatible (make ci) (latest builds)

Epilog

I might have gone a bit overboard with this pull request. The initial idea was to fix #379 but after spending hours with segmentation faults and other obscure errors, caused by my lack of understanding of the language, I decided to look for alternatives. After searching for "swift" in issue tracker I found a few comments from @matryer regarding migrating to Swift – so I decided to give it a go my self.

With that said I understand if this is "to much" and if you decide not to merge.

A side note; I might have removed files from the original project when simplifying the implementation a few weeks ago. If you find something that should be in the project but isn't, such as assets files, let me know and I'll add it.

~ L

@oleander
Copy link
Author

oleander commented Jan 20, 2017

skarmavbild 2017-01-20 kl 18 17 07

skarmavbild 2017-01-20 kl 18 06 51

  • ANSI
    • Combine with other params, such as length
    • Other colors and styles, such as bold and italic
    • Fix invalid offset in menu bar (fixes: Vertical offset in Sierra #376) when using ANSI
    • Support for ANSI in menu bar
  • Preference items
    • Reload all
    • Quit
    • Select plugin folder and store the result with the application
    • Open plugin folder
    • Open at login
  • Descriptive error messages
  • Simple error messages using :warning:

@oleander
Copy link
Author

skarmavbild 2017-01-20 kl 23 48 04
skarmavbild 2017-01-20 kl 23 47 58

@oleander
Copy link
Author

The offset fix for #376 now also applies to emojis (now / before)

offset

@matryer
Copy link
Owner

matryer commented Jan 23, 2017

This is great work!

@matryer
Copy link
Owner

matryer commented Jan 23, 2017

There are LOTS of open PRs for the obj-C project... seems we need to make a decision about Swift vs Obj-C. @iosdeveloper, what do you think?

@oleander
Copy link
Author

oleander commented Jan 23, 2017

@matryer Thanks! :)

Made a quick summary of the open PRs.

Some of the PRs from @iosdeveloper above was merged into the beta branch when I started a few weeks back.

Hope that helps.

@oleander
Copy link
Author

2 132 passing specs implemented. 2000 property based and 132 static.

@oleander
Copy link
Author

oleander commented Jun 23, 2017

The latest version now bundles the CLI. Install it via the setting panel (see print screen)

skarmavbild 2017-06-23 kl 11 27 06

Latest BitBar.app build.

@russelg @plessbd I'll get back to you guys in the end of the week.

@palmerj
Copy link

palmerj commented Jul 5, 2017

I just tried this and the on 10.12 and the application keeps quitting and falling our of the menubar. Has anyone else had this problem?

@oleander
Copy link
Author

oleander commented Jul 5, 2017

@palmerj That's fixed in the latest, currently not deployed, but pushed, version. Stay tuned!

@palmerj
Copy link

palmerj commented Jul 5, 2017

Ok thanks. Any idea on when a new version will be release. If it's not planned soon, I will revert to the official bitbar for now.

@fazibear
Copy link

Any updates ?

@oleander
Copy link
Author

Long story short; I'm currently doing a bike tour since two months back from London to Iran. Don't have that much time any more to work on this. I do still work on it, but its going a bit to slow. The project has been stable a few times in the past since I made the fork, but since I didn't get any feedback I continued adding features - which made it unstable - and thats where we are right now.

I see two options that doesn't involve throwing the project away.

  1. Finding a commit prior to HEAD that implements as much, if not all functionally of matryer/bitbar and continuing the development from there.
  2. Continuing from HEAD and fixing whats currently broken. This will you give an array of new features that as been requested for years (that's how I decided what features to include, I looked at the issues).

I sincerely hope that my fork isn't thrown away and forgotten considering the 1000 of hours spent on it. Last time I checked in May I had 1200h (according to wakatime.com) - and thats only the editing part.

I cant promise anything, but I probably gonna continue on this fork when I reach Iran as I use my version of BitBar every day.

21743039_1959121557666874_5454914103067717631_n

@plessbd
Copy link

plessbd commented Sep 14, 2017

@oleander Congratulations on your bike tour, it sounds amazing.

I use your version daily and also don't want to see it disappear.

It has been updated more recently than than this version and does have many fixes and features that have helped me.

I dont know enough swift to help out, but will continue to use and offer any feedback that I can. Keep up the good work and if nothing else I would appreciate a stable release that even if it doesnt get any enhancements just continues to work with the newer versions of macOS (since High Sierra is coming out in a couple weeks) I would be happy.

@unrzn0
Copy link

unrzn0 commented Feb 8, 2018

Hi, just tried your version (from source and as dmg) - and the code seems to be not compatible anymore to latest Xcode versions - and it also aks for an upgrade to Swift4. The dmg then seems to refer to some dylibs from Xcode, which I think a casual user wouldn't have installed and also some symbols seem to have changed (maybe because of Swift4). I myself never did Swift, but I think if you'd make it compile again ans bundle a complete dmg with all dependencies, barrier for users would be lower to look into the code and fix what's broken (if anything is broken).

@matryer
Copy link
Owner

matryer commented Feb 8, 2018 via email

@oleander
Copy link
Author

oleander commented Feb 8, 2018 via email

@jannik-mohemian
Copy link

@matryer @oleander What is the status on this? Would love to see progress using this branch/version...

Also using oleander's version

@matryer
Copy link
Owner

matryer commented Oct 16, 2018

@jannik-mohemian It's stalled at the moment. I'm in search of new maintainers.

@gingerbeardman
Copy link
Collaborator

@oleander where are you right now? did you look at this recently?

@mpicard
Copy link
Collaborator

mpicard commented Jul 12, 2019

Is there anything missing to merge this? @oleander @matryer can we get an update? I don't know Swift but we could merge and close a bunch of issues and "start fresh" so to speak with Swift

@gingerbeardman
Copy link
Collaborator

gingerbeardman commented Jul 12, 2019

@mpicard let's assume nothing has changed since the comment above #391 (comment)

Happy to help go through the commit logs and test builds to find the last stable release that was feature complete

@mpicard
Copy link
Collaborator

mpicard commented Jul 16, 2019

@gingerbeardman I'd love a little code walk through since I'm not familiar with Swift but since you seem to have fixed a lot of bugs and stuff I'd be really nice to merge this, pending @matryer approval as well. Let's schedule a Zoom soon so reach out at martin8768#gmail#com

@gingerbeardman
Copy link
Collaborator

gingerbeardman commented Jul 16, 2019

@mpicard the Swift fork is not mine, it is by @oleander who is travelling around the world on a bike

@oleander
Copy link
Author

I'm still biking. 25 000 km in but I'm willing to help.

IMG_6858

@eldemcan
Copy link

I hope it is possible to merge contributions of @oleander 🤞 . Best of luck in your journey.

@kdeldycke
Copy link

FTR, there is an alternative Swift-based project too BitBar, and seems to be actively maintained: https://github.com/swiftbar/SwiftBar

@gingerbeardman
Copy link
Collaborator

SwiftBar (above) is currently 10.15+ only

@matryer matryer closed this Mar 8, 2021
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.