The codebase for the UWP Companion is extremely modular, and adding support for a new client should be a breeze.
Getting started: | |
---|---|
Adding a client | Adding a platform |
- Very basic experience with Javascript
- A working launch protocol for the app you're adding
- App logo and a smaller icon version (optional for clients, falls back to platform icons)
- These are stored in the
/assets/
folder, with self-descriptive subfolders for sorting them out. - Should be stored locally for maximum performance.
- Paths are generated automatically, but can be overridden by declaring the
icon
andlogo
properties (not recommended, see below).
- Logos:
- Logo for the app, shown to the user in the PlatformView in the browser action popup.
- Should have as little padding possible
.png
files only- Store in
/assets/logos/platforms/
or/assets/logos/clients/
, with the filename matching thename
of the corresponding client or platform.
- Icons:
- A smaller version of the logo used in the extension bar when the user is on a compatible site.
- Should be 48x48 with no padding
.png
files only- Store in
/assets/icons/platforms/
or/assets/icons/clients/
, with the filename matching thename
of the corresponding client or platform.
If the platform is already set up, you can add a new client in less than 20 lines of code.
Steps for creating a new client:
- Find the folder for the platform you are targeting in
/core/lib/
. If your platform doesn't exist, you'll have to add a new platform - Create a new file, and name it after your client (all lowercase). The file extension is
.js
. For example, if you're adding a client calledFoo
, createfoo.js
- Populate the newly created file using the documentation below
- Make sure to add icons/logos using the guidelines above
- In
master.js
within the same folder,import
the client as the same exactname
you created when populating your client. - Find the
export default
statement inmaster.js
Add your imported client to theclients
key.
- If you have other helper methods that are specific to the platform and not the client, place them in the file
helpers.js
in the platform directory.
Param | Type | Description |
---|---|---|
name | string |
Name of the client |
parseUrl | function |
Used to transform an HTTP URL to a protocol URI for your app. Runs every time the current tab is updated or reloaded, and only on sites that pass baseUrlMatch for the platform. Consumes a (url: string ) and should return (protocol: `string |
postLaunch | function |
Runs after a client is launched. Used to perform actions on a page such as pausing a video |
config | object |
Config object. See below |
Param | Type | Description |
---|---|---|
logo | string |
(optional) Set this to override automatic logo config (Not recommended). |
icon | string |
(optional) Set this to override automatic icon config (Not recommended). |
color | string |
Unused for now, may be used for themeing in the future |
appProtocol | string |
The registered protocol for the UWP App. Will be used in the future for auto-detecting installed apps |
usePlatformLogo | boolean |
(optional) Set true to use the platform logo/icon instead of custom client assets |
That's it! The end result for your new .js
file will look something like this:
import RedditParser from './parsing.js';
export default {
config: {
color: "#FF4500"
},
name: "Legere",
parseUrl: function(url) {
if (RedditParser.isSubreddit(url) || RedditParser.isUser(url) || RedditParser.isPost(url)) {
return "legere://" + url
}
}
}
Steps for adding a new platform
- Create a new folder for the platform in
/core/lib/
with the name of your app (all lowercase) - Create
master.js
andparsing.js
in the new folder. Populate these as needed using the documentation below - In
/core/libs.js
, import the platform just like the rest. - Add the new platform as a key under the
platforms
object, and the imported platform as the value. Make sure the key matches thename
property of the platform exactly. - In
/core/helpers/settings.js
, add a new entry underDefaultSettings.platforms
. The key is yourplatform.name
, while the value is anIPlatformSetting
(as defined in/core/typings.ts
).
master.js
must export a default object like so:
Param | Type | Description |
---|---|---|
name | string |
Name of the platform |
logo | string |
(optional) Set this to override automatic logo config (Not recommended). |
icon | string |
(optional) Set this to override automatic icon config (Not recommended). |
baseUrlMatch | function |
Used to match a website to a platform. Should be imported from parsing.js . Consumes a (url: string ) and should return a bool |
shouldCloseOnSwitch | function |
(Optional) Used to determine if the extension should close the tab after a client is launched. Consumes (url: string , tab: object ) and returns a bool |
clients | object |
Key-value pairs of the clients supported on this platform. Keep these comma seperated for brevity |
When all set up, master.js
should look something like this:
import myTube from './mytube.js';
import YTParser from './parsing.js';
export default {
name: "YouTube",
baseUrlMatch: YTParser.isYoutube,
clients: {
myTube
}
};
This file will contains all the URL parsing methods you'll need for detecting and capturing certain parts of an official URL.
The only major requirement is that all methods get exported as default on an object, like so:
export default {
hasId,
isSomething,
isSomethingElse
}