├── .eslintrc.yml ├── .gitignore ├── .vscode └── settings.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── application.json ├── example.js ├── index.js ├── lib ├── logger.js ├── q-signal.js ├── storage.js └── utility.js ├── package.json ├── test └── test.js └── yarn.lock /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | extends: airbnb-base 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Test data 44 | test/auth.json 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | **/Properties/launchSettings.json 59 | 60 | # StyleCop 61 | StyleCopReport.xml 62 | 63 | # Files built by Visual Studio 64 | *_i.c 65 | *_p.c 66 | *_i.h 67 | *.ilk 68 | *.meta 69 | *.obj 70 | *.iobj 71 | *.pch 72 | *.pdb 73 | *.ipdb 74 | *.pgc 75 | *.pgd 76 | *.rsp 77 | *.sbr 78 | *.tlb 79 | *.tli 80 | *.tlh 81 | *.tmp 82 | *.tmp_proj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | 259 | # Microsoft Fakes 260 | FakesAssemblies/ 261 | 262 | # GhostDoc plugin setting file 263 | *.GhostDoc.xml 264 | 265 | # Node.js Tools for Visual Studio 266 | .ntvs_analysis.dat 267 | node_modules/ 268 | 269 | # Visual Studio 6 build log 270 | *.plg 271 | 272 | # Visual Studio 6 workspace options file 273 | *.opt 274 | 275 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 276 | *.vbw 277 | 278 | # Visual Studio LightSwitch build output 279 | **/*.HTMLClient/GeneratedArtifacts 280 | **/*.DesktopClient/GeneratedArtifacts 281 | **/*.DesktopClient/ModelManifest.xml 282 | **/*.Server/GeneratedArtifacts 283 | **/*.Server/ModelManifest.xml 284 | _Pvt_Extensions 285 | 286 | # Paket dependency manager 287 | .paket/paket.exe 288 | paket-files/ 289 | 290 | # FAKE - F# Make 291 | .fake/ 292 | 293 | # JetBrains Rider 294 | .idea/ 295 | *.sln.iml 296 | 297 | # CodeRush 298 | .cr/ 299 | 300 | # Python Tools for Visual Studio (PTVS) 301 | __pycache__/ 302 | *.pyc 303 | 304 | # Cake - Uncomment if you are using it 305 | # tools/** 306 | # !tools/packages.config 307 | 308 | # Tabs Studio 309 | *.tss 310 | 311 | # Telerik's JustMock configuration file 312 | *.jmconfig 313 | 314 | # BizTalk build output 315 | *.btp.cs 316 | *.btm.cs 317 | *.odx.cs 318 | *.xsd.cs 319 | 320 | # OpenCover UI analysis results 321 | OpenCover/ 322 | 323 | # Azure Stream Analytics local run output 324 | ASALocalRun/ 325 | 326 | # MSBuild Binary and Structured Log 327 | *.binlog 328 | 329 | # NVidia Nsight GPU debugger configuration file 330 | *.nvuser 331 | 332 | # MFractors (Xamarin productivity tool) working folder 333 | .mfractor/ 334 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "eslint.enable": false 3 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | #### 2.11.4 (2019-02-25) 2 | 3 | ##### New Features 4 | 5 | * **QDesktopApp:** Added ability to clear signals for an applet ([b60477ce](https://github.com/daskeyboard/daskeyboard-applet/commit/b60477ceb114ddf2bcae1038c1529398243cb9dd)) 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Metadot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Das Keyboard Applet API 2 | The API for creating Applets that will run inside the Das Keyboard Q Desktop 3 | environment. 4 | 5 | ## Installation 6 | This module is installed via npm. 7 | 8 | ``` 9 | npm install --save daskeyboard-applet 10 | ``` 11 | 12 | ## Getting Started 13 | Require the Q Applet API with: 14 | ``` 15 | const q = require('daskeyboard-applet'); 16 | ``` 17 | 18 | Your app should extend `DesktopApp`, as in: 19 | 20 | ``` 21 | class QExample extends q.DesktopApp { 22 | /** just send a signal without thinking about it */ 23 | async run() { 24 | // do some work, then return a signal 25 | return new q.Signal({ points: [[new q.Point('#FF0000')]] }); 26 | } 27 | } 28 | 29 | const myExample = new QExample(); 30 | 31 | ``` 32 | - Always instantiate your Applet instance in your main body to begin processing 33 | and sending signals. 34 | 35 | # DesktopApp functions 36 | ## Constructor 37 | - If you need to create a `constructor()` method, please be sure to invoke 38 | `super()` to initialize some important variables and signal handlers. 39 | - Do not use the constructor for any functionality or state that is related to 40 | the applet's configuration. The configuration may change as the applet is 41 | running. To update the applet's state based on configuration, extend the 42 | `applyConfig()` method. 43 | 44 | ## run() 45 | - The `run()` method is your primary extension point. This method will be 46 | invoked at regular intervals. This method should do some work, and then 47 | return a Signal object. 48 | 49 | - If you need to perform any work before the Applet is ready to run, then 50 | it can be included in the main body of your script. 51 | 52 | - If you need to perform any work before the Applet is closed, implement the 53 | `shutdown()` function. This function is invoked by a signal handler. 54 | 55 | - If you throw an `Error` in this method, the extension host will transmit a 56 | signal to the Q Desktop with your error message in the body. 57 | 58 | 59 | ## applyConfig() 60 | - The applet will process any configuration, at launch and whenever a 61 | configuration change is sent, with a method `processConfig({*})`. If your 62 | applet's state needs to change based on the new configuration, implement 63 | `applyConfig()`. The applet's `this.config` object will have been updated to 64 | reflect the new configuration. 65 | 66 | - During this phase, you can also validate input. If you receive an invalid 67 | value, you can throw an `Error` that contains a message explaining the 68 | invalid input. *Important*: The Q Desktop application may invoke this method 69 | before it has had a chance to receive configuration input from the user. In 70 | this case, expected values may not yet exist. Do not throw an exception when 71 | an expected value is missing, only when an expected value is defined but the 72 | value is invalid. 73 | 74 | 75 | ## options(fieldId, search) 76 | When you specify the questions in `package.json`, you have the ability to 77 | specify dynamic options in a dropdown or search control. An example is: 78 | 79 | ``` 80 | "questions": [ 81 | { 82 | "key": "zoneId", 83 | "label": "Choose a location", 84 | "help": "select a location from the list", 85 | "required": true, 86 | "order": 1, 87 | "controlType": "dropdown", 88 | "dynamic": true, 89 | "options": [] 90 | } 91 | ] 92 | ``` 93 | 94 | In the above case, the extension host will invoke the method 95 | `#options(fieldId)`, where `fieldId` is the name of the configuration property 96 | that is being shown, such as `#options('zoneid')`. You should respond with a 97 | JSON data structure as follows: 98 | 99 | ``` 100 | [ 101 | { 102 | "key": "the unique key for the option:", 103 | "value": "the value to be displayed in the option list" 104 | } ... 105 | ] 106 | 107 | ``` 108 | 109 | An alternate case is where you would like the user to search for the possible 110 | values using a typeahead control. An example of this case follows: 111 | 112 | ``` 113 | "questions": [ 114 | { 115 | "key": "cityId", 116 | "label": "Choose a city", 117 | "help": "select a location from the list", 118 | "required": true, 119 | "order": 1, 120 | "controlType": "search", 121 | "options": [] 122 | }, 123 | ] 124 | ``` 125 | 126 | When specifying `"controlType": "search"`, the extension host will invoke the 127 | method `#options(fieldId, search)`, where `search` is a string contain the 128 | user's search term(s). 129 | 130 | ## clearSignals() 131 | 132 | Will clear all the signals on the applet 133 | 134 | 135 | 136 | # Creating Signals 137 | Your applet communicates with the Das Keyboard Signal Center by returning 138 | `Signal` objects. A `Signal` object includes a 2-D array of `Point` objects, 139 | along with an optional `name` and `description`. 140 | 141 | For example, the simplest `Signal` object would be: 142 | 143 | ``` 144 | return new q.Signal({ points: [[new q.Point('#FF0000)]] }); 145 | ``` 146 | 147 | To light up a row of keys, send a single row of Points, e.g.: 148 | ``` 149 | return new q.Signal({ 150 | points: [[ 151 | new q.Point('#FF0000), 152 | new q.Point('#00FF00), 153 | new q.Point('#0000FF), 154 | ]], 155 | name: 'My Applet Name', 156 | description: 'Some description of the signal' 157 | }); 158 | ``` 159 | 160 | To light up a rectangular region, send multiple rows of points, e.g: 161 | ``` 162 | return new q.Signal({ 163 | points: [ 164 | [new q.Point('#FF0000), new q.Point('#00FF00), new q.Point('#0000FF)], 165 | [new q.Point('#FF0000), new q.Point('#00FF00), new q.Point('#0000FF)], 166 | [new q.Point('#FF0000), new q.Point('#00FF00), new q.Point('#0000FF)], 167 | ]}); 168 | ``` 169 | 170 | ## Signal options 171 | The `Signal` class takes the following options in its constructor: 172 | 173 | - `points`: A 2-D array of `Point` objects. 174 | - `name`: Will be displayed as the title of any signal dialog. 175 | - `message`: Detailed message that will be displayed within a signal dialog. 176 | - `isMuted`: Boolean value. If set to `false`, the signal will invoke an on-screen notification. 177 | - `action`: The action of the signal, typically `DRAW`. This is the default. Possible values are: 178 | - `DRAW`: Light a key until the signal is dismissed. 179 | - `ERROR`: The signal will relay an error message to the host service. 180 | - `FLASH`: The signal will cause the key(s) to flash. 181 | - `errors`: In the case of an `ERROR` action, `errors` should contain an 182 | array of error messages. 183 | 184 | 185 | ## Creating a signal within a callback function 186 | There are cases when your `run()` function may have to use a callback, and so 187 | cannot directly pass a `Signal` object as its return. In this case, you can 188 | either return a promise, or you can use the `this.signal()` function, e.g.: 189 | 190 | ``` 191 | this.signal(new q.Signal({ points: [[new q.Point('#FF0000)]] })); 192 | ``` 193 | 194 | ## The Point Class 195 | Each `Point` should specify, at a minimum, the RGB color that the key should 196 | be illuminated to: 197 | 198 | ``` 199 | let point = new q.Point('#FF0000'); 200 | ``` 201 | 202 | You can also specify an effect if you wish: 203 | ``` 204 | let point = new q.Point('#FF0000', q.Effects.BLINK); 205 | ``` 206 | 207 | # Applet Configuration 208 | The applet is configured with the following member variables: 209 | 210 | ## this.geometry 211 | The geometry configuration is stored in an object with the following format: 212 | ``` 213 | { 214 | width: 215 | height: 216 | origin: { 217 | x: , 218 | y: 219 | } 220 | } 221 | ``` 222 | You can also inspect the applet's geometry with the functions: 223 | - `this.getWidth()` 224 | - `this.getHeight()` 225 | - `this.getOriginX()` 226 | - `this.getOriginY()` 227 | 228 | ## this.authorization 229 | Currently we support authorization by API Key or Basic Authentication. The 230 | authorization object looks like: 231 | 232 | ``` 233 | { 234 | apiKey: , 235 | username: , 236 | password: 237 | } 238 | ``` 239 | 240 | ## this.config 241 | The config object is for any values that are specific to the application. This 242 | object is built by merging the default configuration values that are supplied 243 | in `package.json` with any user-supplied values that were input during applet 244 | installation. 245 | 246 | ## this.store 247 | The `store` object is an instance of 248 | [node-storage](https://www.npmjs.com/package/node-storage). When running within 249 | the Q Desktop App, the storage file is located in the `~/.quio` directory. When 250 | running from a command line, a file `local-storage.json` will be created. You 251 | should not commit a `local-storage.json` file to the repo, because it will be 252 | ignored unless running from a command line. 253 | 254 | 255 | # Logging 256 | Applets use the [winston](https://github.com/winstonjs/winston) logging system. 257 | Log files can be found in `~/.quio/v2/applet.log.json`. When running from a 258 | command line, logging will output to the console. 259 | 260 | To access the logger, you can invoke: 261 | ``` 262 | const q = require('daskeyboard-applet'); 263 | const logger = q.logger; 264 | 265 | logger.info('This is an info'); 266 | logger.warn('This is a warn'); 267 | logger.error('This is an error.'); 268 | ``` 269 | 270 | # Running an Applet in dev mode 271 | You can run an applet in `dev mode` by invoking it via node, using the following 272 | syntax: 273 | 274 | `node