From 00a8b20bc7e5b4425edbae208098c1555a8aeded Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Mon, 28 Mar 2016 18:34:26 +0200 Subject: [PATCH] allow specifying args type by passing objects (buttons values and preArgs) --- main/osc.js | 11 ++++++++--- resources/docs/widgets-reference.md | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/main/osc.js b/main/osc.js index d8779368..276b56ae 100644 --- a/main/osc.js +++ b/main/osc.js @@ -24,15 +24,20 @@ module.exports = function(ipc, settings) { if (typeof args=='object' && args!==null) { for (i in args) { var arg = args[i] - if (typeof arg == 'number' && arg!==null) { + + if (typeof arg == 'number' && arg!==null && typeof arg != 'object') { message.append({type:numberType,value:arg}) - } else if (arg!==null){ + } else if (arg!==null && typeof arg != 'object'){ message.append({type:'string',value:String(arg)}) - } + } else if (arg!==null && typeof arg == 'object' && arg.type && arg.value!=undefined) { + message.append({type:arg.type,value:arg.value}) + } } } else if (args!==null){ if (typeof args == 'number') { message.append({type:numberType,value:args}) + } else if (typeof args == 'object' && arg.type && arg.value!=undefined) { + message.append({type:args.type,value:args.value}) } else { message.append({type:'string',value:String(args)}) } diff --git a/resources/docs/widgets-reference.md b/resources/docs/widgets-reference.md index 0967a867..32c0c5c6 100644 --- a/resources/docs/widgets-reference.md +++ b/resources/docs/widgets-reference.md @@ -20,6 +20,8 @@ Every widget has the following properties: target:false, // [array/string] List of target hosts ("ip:port" pairs), separated by spaces path:false, // [string] osc path, default to '/widget_id' preArgs:[] // [array] list of constant values to prepend to the sent value(s) + // a value's type can be specified by writing it as an object: + // preArgs: [{type:"integer",value:1}] } ``` @@ -27,7 +29,7 @@ Every widget has the following properties: ## CSS -The css property can be used to override theming variables (see [theming](theming.md) for a widget. Also, some widgets expose specific theming variables that allow a finer customization. +The css property can be used to override theming variables (see [theming](theming.md) for a widget. Also, some widgets expose specific theming variables that allow a finer customization. ## Widget specifics