nw-skeleton

Class: MainScript

mainScript. MainScript

A Utility class for handling main script (nwjs bg-script) tasks

MainScript()

Creates MainScript instance

Properties

Name Type Description
config Object App configuration
startTime Date App starting time
inspectOptions Object Util.inspect default options
mainWindow Window Reference to main nw.Window
manifest Object Manifest file data
messageHandlers MainMessageHandlers Object that handles messages
asyncMessageHandlers MainAsyncMessageHandlers Object that handles async messages
boundMethods Object Wrapper object for bound method references

Extends

Methods

_doLog(message, type, data, forceToWindow){undefined}

Parameters

Name Type Description
message string Message to be logged
type string Type of log message (debug, info, warning, error, group, groupCollaped, groupend)
data array An array of data strings that are to be applied to logging message
forceToWindow Boolean Flag to force logging to main window console

Return

Logs data to console

addBoundMethods(){undefined}

Return

Method that sets up this.boundMethods property by binding this objects functions to itself to be used as event listener handlers

createDirFileRecursive(fileName, mode, options, data){Boolean}

Parameters

Name Type Description
fileName string Absolute path to file
mode Number Octal mode definition (i.e. 0o775)
options Object Options object for fs.writeFileSync
data string Data to write to file

Return

Creates directory (recursive) and writes file to it

createDirRecursive(directory, mode){Boolean}

Parameters

Name Type Description
directory string Absolute directory path
mode Number Octal mode definition (i.e. 0o775)

Return

Creates directory recursively

finalize(){Boolean}

Return

Finalizes current class instance, setting up any additional properties etc. Entire app structure, including frontend app is available here

formatTimeNormalize(date, options, includeDate, omitSeconds){string}

Parameters

Name Type Description
date Date Date value to format
options Object Date format options
includeDate Boolean Flag to indicate whether to include date
omitSeconds Boolean Flag to indicate whether to omit seconds

Return

Format time normalized (Y-m-d H:i:s format)

getConfig(name, defaultValue){mixed}

Parameters

Name Type Description
name string String representing path to requested var (i.e. 'appConfig.appInfo.name')
defaultValue mixed Default value to be returned if configuration var is not found

Return

Returns configuration var value

getHelper(name){Object}

Parameters

Name Type Description
name string Name of the helper

Return

Returns instance of helper object based on passed parameter (or false if helper can't be found)

getInitialAppConfig(defaultAppConfig){Object}

Parameters

Name Type Description
defaultAppConfig Object Default application config

Return

Loads config overrides if present, and returns config object for the app

getStateVar(varPath, defaultValue){mixed}

Parameters

Name Type Description
varPath string String representing path to requested var (i.e. 'appData.appMainData.cancelable')
defaultValue mixed Default value to be returned if appState var is not found

Return

Returns appState var value

initialize(options){MainScript}

Parameters

Name Type Description
options Object Object with 'manifest' property containing manifest file data and 'config' property containing config data

Return

Initializes MainScript using manifest and app config data

initializeLogging(){BaseClass}

Return

Determines whether logging for this class is regulated through configuration, setting the logging by it (or warning if there are no configuration settings for this class)

log(message, type, data, force, forceToWindow){undefined}

Parameters

Name Type Description
message string Message to be logged
type string Type of log message (debug, info, warning, error, group, groupCollaped, groupend)
data array An array of data strings that are to be applied to logging message
force Boolean Flag to force logging output even if config does not allow it
forceToWindow Boolean Flag to force logging to main window console

Return

Logs message to console or stdout

printLog(message, type){undefined}

Parameters

Name Type Description
message string Message to print
type string Type of message

Return

Prints message to stdout with newline appended

windowClosed(e, noExit){undefined}

Parameters

Name Type Description
e Event Event that triggered the method
noExit Boolean Flag to prevent exiting main process

Return

Handler for mainWindow 'closed' event