r/angularjs • u/schizoduckie • Nov 06 '14
[Show] Started out with a chrome extension to teach myself some pure angularjs. After 8 months of development it's a full-fledged TV-Show Tracking calendar with an API into uTorrent that also runs standalone on Windows / Mac / Linux
https://schizoduckie.github.io/DuckieTV/3
u/2basco Nov 07 '14
Can you elaborate on the process of porting your extension into a standalone client and what that involves?
3
u/schizoduckie Nov 07 '14 edited Nov 07 '14
Ofcourse :)
It was actually not as hard as I initially thought. The biggest hurdle was that DuckieTV relied (hardcoded) on several Chrome Extension specific API's (namely Storage, Alams and topSites).
I've already been working on adding an abstraction layer here and there over the last builds to make sure that DuckieTV can also work on other platforms than chrome. The chrome.alarms api was the last challenge.
This used to work like so:
There is a listener in the background page for events fired by the chrome.alarms API. The background page is basically a headless, minimal version of the app's core that get's initialized by Chrome when a timer is about to fire, so that the update procedure can do it's thing, even when chrome is closed or DuckieTV is not active.
The first step was to refactor the calls so that it runs through the adaper layer, and write an interface that could handle this thing exactly the same way. This became the AlarmService
This is just an angular factory that hold a ChromeAdapter and a DuckieTVAdapter. Both have exactly the same interface, and the DuckieTVAdapter just dumps it's list of timers serialized in LocalStorage. Whenever the AlarmService is instantiated, it checks which adaptor it needs to use, and if it's the DuckieTVAdapter it unserializes the alarms array from and wakes up the alarms. Each alarm just creates a long-running setTimeout() for when it's supposed to fire, and cleans itself up or reschedules itself after firing.
Quite happy with the way that works, especially since I just whipped up 99.9% of that code off the top of my head in one go, and then started testing it. (still need to add docs though)
The next step was trying to get some sort of packaging working and get my feet wet with node-webkit. This mainly involved some testing with the existing available build scripts, failing, trying to find out why DomParser.parseFromString() would fail silently (dependencies and shitty build scripts) and trying some more.
I went back to the drawing board and decided to find another way than the Node-Webkit-Builder and finally stumbled upon the awesome Web2Executable python program.
This seemed to handle everything nicely, but there were some unexpected results using the latest node-webkit build and the optional (but very important) 'Use Nodejs' checkbox.
This final unassuming checkbox, that I figured I could just leave turned off, broke the Cross-Domain functionalities. Thankfully, a good round of testing allowed me to fix that, and now it all just works :)
One of the last challenges left is implementing an auto-update system, something you also get for free when doing Chrome Extensions, but you need to create something manually when you're a Node-Webkit app.
1
0
u/ThunderTherapist Nov 07 '14
I've got a chrome extension too. It adds spotify links to rolling stone magazines top 100 list pages. I used it to listen to the top 500 albums of all time.
It doesn't use angular though.
1
0
Nov 07 '14
[deleted]
2
u/schizoduckie Nov 07 '14
That would be awesome!
We're well aware of the crappyness of the translations (basically google-translated stuff)
We're hoping to get people to help out with it by providing a baseline and a proper english version.
If you're willing to help, all you have to do is work through this file: https://github.com/SchizoDuckie/DuckieTV/edit/permissions-refactor/_locales/it_it.json and submit a pull-request afterwards :)
0
Nov 07 '14
[deleted]
3
u/schizoduckie Nov 07 '14 edited Nov 07 '14
It was started by the fact that we're already using a load of angular at work, but indeed: there's a lot to digest before you can feel comfortable.
I mostly just read tutorials until I had a proper view in my mind of how an angular 'works', being able to work with providers, services, directives, scopes, promises, etcetera really needs to 'click' in your brain sometime soon after you get started or you'll end up in a mess.
From there on it's just writing code, seeing if it works, reading, reading, reading and learning how to apply those concepts. It can get overwhelming indeed since there's just so many tutorials out there that offer wrong or outdated information. Thankfully, the guys at #angular.js on irc are also very helpful, and they showed me some insights into how working with promises can create some beautiful code (still working on that, it's the feature that allows you to sync your local DuckieTV instance with the cloud to any engine that adheres to the interface).
All in all i'm still learning nearly every day and refactoring code to make things more logical and beautiful now that I have a proper view of all the things that DuckieTV has to do.
It's probably worth mentioning that in those 8 months I did not just write DuckieTV, but also ported my PHP ORM to pure Javascript before I started. I wanted to work with a proper SQLite database in this project without the fuss. Also, I reverse-engineered BitTorrent's BtApp.js API when I found out about about it, and turned it into DuckieTorrent, an Angular.js module to communicate with BitTorrent and uTorrent
0
Nov 07 '14
[deleted]
1
u/schizoduckie Nov 07 '14
The one thing I really truely rely on a lot is the actual angular.js docs. They're very comprehensive and always up to date.
But particularly, these two come to mind:
http://promise-nuggets.github.io/
http://stackoverflow.com/questions/15666048/service-vs-provider-vs-factory
0
0
Nov 06 '14
[deleted]
4
u/schizoduckie Nov 06 '14 edited Nov 07 '14
Not really, but I just put up a really barebones extension bootstrapped with angular here
It's basically a package.json that describes how to integrate it in chrome (by hooking into the startup function for the extension and adding a button to the browser which launches a tab to the url)
You can load it up by cloning the repository or downloading the zip, enabling 'developer mode' in chrome://extensions and pointing the directory browser that comes up after clicking 'load unpacked' extension to that specific folder.
3
Nov 06 '14
You can use about any front end JS you'd like in a Chrome extension. There are security limitations, but a lot is achievable regardless. One of the first things I used Angular for was an extension that long polled an API, stored data in local storage and used desktop notifications when something of interest occurred.
Googles docs on extensions were pretty solid last I read through them. Some of the APIs have changed, but you're largely writing a web app that hooks in a few places for different uses.
3
u/najra3000 Nov 07 '14 edited Nov 07 '14
This looks awesome, going to play around with it!
any plans to add other torrent clients? :)