The Jancy Object
The Jancy object is going to be the primary interface through which your plug-in will add to/modify Jancy. It contains a number of useful methods and is the home for all of the core interfaces.
The global Jancy object is always available at global.jancy.
Methods
jancy.addURLHandler(func)
func(function)
Register a function that will be called any time a tab navigates.
func will be called with the following arguments:
jancy(Jancy object) the global Jancy objecttab(Tab object) a Tab objecturl(string) the URL being navigated to
func should return true if no further evaluation of the URL needs to happen otherwise it should return false.
To unregister your function use the jancy.removeURLHandler method.
function myHandler(jancy, tab, url) { if (url.startsWith('josh://')) { // Do something special here. return true } return false } jancy.addURLHandler(myHandler)
jancy.addWebReadyFunction(name, func, state)
name(string)func(function)state(any) optional passed as an argument tofunc. Iffuncresolves with a value, that value will be used asstateon the call tofunc.
Register a function to be called when the webcontents of a tab has been established but before the first navigation event.
func will be called with the following arguments:
jancy(Jancy object) the global jancy objecttab(Tab object) a Tab objectwc(WebContents) the Electron WebContents object associated with the tabstate(any) seestateabove.
func must return a promise that resolves with a new state value.
To unregister your function use the jancy.removeWebReadyFunction method.
async function myWebReady(jancy, tab, wc, state) { if (state === undefined) { state = 1 } console.log(`I've been called ${ state } times`) return state + 1 } jancy.addWebReadyFunction("my webready function", func)
jancy.getAppDataPath(file)
file(string) optional
Returns a string with the app data path or optionally a file/folder in the app data path if file is defined.
- On Windows the plug-in folder is located at
%appdata%\Jancy\plugins- On MacOS the plug-in folder is locatd at
~/Library/Application Support/Jancy/plugins
jancy.getBundlePath(file)
file(string) optional
Returns a string with the bundle path or optionally a file/folder in the bundle if file is defined.
jancy.getHomePage()
Returns a string with the currently configured home page.
This is a convience method that does some error checking on the homePage preference and returns a default home page if the user hasn’t set the homePage preference.
jancy.getInterface(key)
key(string)
Returns the object associated with key previously regisitered with jancy.registerInterface().
jancy.getPlatform()
Returns a string describing the platform (OS) Jancy is currently running on.
- For Windows the return value will be
win32- For MacOS the return value will be
darwin
jancy.getShortUUID()
Returns a string containing the last 12 characters of UUID generated from the uudiv4 package.
const uuid = jancy.getUUID() console.log(uuid) // "a7006c25a39f"
jancy.getUUID()
Returns a string containing a UUID generated from the uudiv4 package.
const uuid = jancy.getUUID() console.log(uuid) // "75442486-0878-440c-9db1-a7006c25a39f"
jancy.readFromMemory(arg)
arg(object)tag(string)
Returns data previously associated with tag (see jancy.writeToMemory) or null if the tag doesn’t exist.
jancy.registerInterface(key, obj)
key(string)obj(object)
Associates obj with key. obj can be retrieved later via jancy.getInterface().
Interfaces are a simple way to extend Jancy functionality. The intended use-case was for plug-ins to add specialized interfaces (simple objects with custom methods). Other plug-ins could then query for a handle to the interface object and do something with it.
You can call
jancy.unregisterInterface()to remove a previously registered interface.
const myObj = { doSomething() { // some special thing that only myObj can do... } } jancy.registerInterface('myInterface', myObj) // Later on... const myObj = jancy.getInterface('myInterface') myObj.doSomething()
jancy.removeURLHandler(func)
func(function)
Unregister a function previously registered via jancy.addURLHandler().
function myHandler(jancy, tab, url) { if (url.startsWith('josh://')) { // Do something special here. return true } return false } jancy.addURLHandler(myHandler) // later on... jancy.removeURLHandler(myHandler)
jancy.removeWebReadyFunction(name)
name(string)
Unregister a function previously registered via jancy.addWebReadyFunction().
async function myWebReady(jancy, tab, wc, state) { if (state === undefined) { state = 1 } console.log(`I've been called ${ state } times`) return state + 1 } jancy.addWebReadyFunction("my webready function", func) // later on... jancy.removeWebReadyFunction("my webready function")
jancy.require(path, invalidateCache=false)
path(string)invalidateCache(boolean)
Returns the module exported from the file at path optionally invalidating any previously cached versions of the module.
jancy.writeToMemory(arg)
arg(Object)tag(string) required an identifier used to associatedatawith.data(any) required thedatato associate withtag.
Associates data to tag. If data is null then the tag is deleted.
data must be a standard Javascript type.
jancy.unregisterInterface(key)
key(string)
Remove an interface that was previously registered with jancy.registerInterface()
Interfaces
A list of all the core Jancy interfaces can be found here.