├── translations └── en.json ├── LICENSE ├── README.md └── MMM-Glance.js /translations/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "CMD_GLANCENAMES_DESCRIPTION" : "List of all available glancable names.", 3 | "CMD_GLANCE_DESCRIPTION" : "Glance specific module(s) for a while. See `/glancenames` also.\ne.g)`/glance clock`.", 4 | "CMD_GLANCEOFF_DESCRIPTION" : "Turn off glancing mode and back to previous.", 5 | "CMD_ASSTNT_GLANCEABLENAMES" : "list of glance", 6 | "CMD_ASSTNT_GLANCE" : "glance at :name", 7 | "CMD_ASSTNT_GLANCE_DESCRIPTION" : "Glance specific modules for a while.", 8 | "CMD_ASSTNT_GLANCEOFF" : "glance mode off", 9 | "CMD_GLANCE_SUCCESS" : "Yes, It will be done.", 10 | "CMD_GLANCE_IMPOSSIBLE" : "I cannot find module {name} for glancing now.", 11 | "CMD_GLANCE_NO_ARGS" : "Alias or name of module is required." 12 | } 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 eouia 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 | # MMM-Glance 2 | To glance specific module and hide others. 3 | You can use this to reveal some module(s) and hide others for a short time. It could be convenient when you are using too many modules or using background image modules. 4 | 5 | ## Installation 6 | ```sh 7 | cd /modules 8 | git clone https://github.com/eouia/MMM-Glance 9 | ``` 10 | 11 | 12 | ## Configuration 13 | Add below codes in your `config.js`. 14 | ```javascript 15 | { 16 | module: 'MMM-Glance', 17 | } 18 | ``` 19 | 20 | You can use more detailed configuration like these; See the below section. 21 | ```javascript 22 | { 23 | module: 'MMM-Glance', 24 | config: { 25 | defaultGlancingTime: 10000, 26 | alias: { 27 | "news" : "newsfeed", 28 | "party mode" : ["clock", "helloworld", "MMM-Something"], 29 | ... 30 | } 31 | } 32 | } 33 | ``` 34 | 35 | ### Configuration values 36 | 37 | |name |default value |description 38 | |--- |---|--- 39 | |defaultGlancingTime | 10000 |Duration time(milliseconds) for glancing mode. After this time, previous screen will be back. 40 | |alias | {`name` : `module name` or array of `module name`} | - You can use this field for glancing multi modules at a same time.
e.g) `{"party mode":["clock", "MMM-DropboxWallpaper"}` => You can reveal these 2 modules by calling `party mode`
- For easy use with `MMM-TelegramBot` or `MMM-Assistant`. When you feel the difficutly to type or to pronounce `MMM-BlahBlahModule`, you can use this field for changing easier name.
e.g) `{"sensor":"MMM-HDC1080"}` 41 | 42 | ## How to use 43 | ### with Notification 44 | ```javascript 45 | this.sendNotification("GLANCE_ON", {name:"helloworld", time:10000}) 46 | this.sendNotification("GLANCE_OFF") 47 | ``` 48 | |notification |payload |description 49 | |--- |--- |--- 50 | |GLANCE_ON | {name: "``", time:``} | reveal some module(s). alias for module name is available. 51 | |GLANCE_OFF | | back to previous screen. 52 | 53 | ### with `MMM-TelegramBot` 54 | |command | description 55 | |--- |--- 56 | |`/glance `| reveal some module(s). alias for module name is available. 57 | |`/glanceoff` | back to previous screen. 58 | |`/glanceables` | list of glanceable modules and aliases. 59 | 60 | 61 | ### with `MMM-Assistant` 62 | |command | description 63 | |--- |--- 64 | |`glance at <:name>`| reveal some module(s). alias for module name is available. 65 | |`glance mode off` | back to previous screen. 66 | |`list of glance` | list of glanceable modules and aliases. 67 | 68 | If you have a trouble of pronouncing command or module name, you can use `alias` of `MMM-Assistant` for command and `alias` of `MMM-Glance` for module. 69 | 70 | -------------------------------------------------------------------------------- /MMM-Glance.js: -------------------------------------------------------------------------------- 1 | /********************************* 2 | Magic Mirror Module: 3 | MMM-Glance 4 | By eouia 5 | 6 | MIT Licensed 7 | 8 | *********************************/ 9 | 10 | Module.register("MMM-Glance", { 11 | 12 | 13 | defaults: { 14 | defaultGlancingTime : 10000, 15 | alias: {} 16 | }, 17 | 18 | start: function() { 19 | this.status = {} 20 | this.alias = {} 21 | this.glancing = false 22 | this.timer = null 23 | this.defaultAlias = { 24 | "news" : "newsfeed", 25 | "weather" : "currentweather", 26 | "forecast" : "weatherforecast", 27 | "hello" : "helloworld", 28 | "test" : ["clock", "newsfeed"] 29 | } 30 | }, 31 | 32 | getTranslations: function() { 33 | return { 34 | en: "translations/en.json", 35 | } 36 | }, 37 | 38 | getCommands: function(register) { 39 | if (register.constructor.name == 'TelegramBotCommandRegister') { 40 | register.add({ 41 | command: "glanceables", 42 | description: this.translate("CMD_GLANCENAMES_DESCRIPTION"), 43 | callback: "cmd_glancenames" 44 | }) 45 | register.add({ 46 | command: "glance", 47 | description: this.translate("CMD_GLANCE_DESCRIPTION"), 48 | args_pattern: [/.*/], 49 | args_mapping: ["name"], 50 | callback: "cmd_glanceon" 51 | }) 52 | register.add({ 53 | command: "glanceoff", 54 | description: this.translate("CMD_GLANCEOFF_DESCRIPTION"), 55 | callback: "cmd_glanceoff" 56 | }) 57 | } 58 | if (register.constructor.name == 'AssistantCommandRegister') { 59 | register.add({ 60 | command: this.translate("CMD_ASSTNT_GLANCEABLENAMES"), 61 | description: this.translate("CMD_GLANCENAMES_DESCRIPTION"), 62 | callback: "cmd_glancenames" 63 | }) 64 | register.add({ 65 | //command: "glance :name", 66 | command: this.translate("CMD_ASSTNT_GLANCE"), 67 | description: this.translate("CMD_ASSTNT_GLANCE_DESCRIPTION"), 68 | callback: "cmd_glanceon" 69 | }) 70 | register.add({ 71 | command: this.translate("CMD_ASSTNT_GLANCEOFF"), 72 | description: this.translate("CMD_GLANCEOFF_DESCRIPTION"), 73 | callback: "cmd_glanceoff" 74 | }) 75 | } 76 | }, 77 | 78 | cmd_glanceon: function(command, handler) { 79 | if (handler.args) { 80 | var ret = this.glanceOn(handler.args.name) 81 | if (ret) { 82 | handler.reply("TEXT", this.translate("CMD_GLANCE_SUCCESS")) 83 | } else { 84 | handler.reply("TEXT", this.translate("CMD_GLANCE_IMPOSSIBLE"), handler.args.name) 85 | } 86 | } else { 87 | handler.reply("TEXT", this.translate("CMD_GLANCE_NO_ARGS")) 88 | } 89 | 90 | }, 91 | cmd_glanceoff: function(command, handler) { 92 | this.glanceOff() 93 | handler.reply("TEXT", this.translate("CMD_GLANCE_SUCCESS")) 94 | }, 95 | 96 | cmd_glancenames: function(command, handler) { 97 | var text="" 98 | text = Object.keys(this.alias).join() 99 | handler.reply("TEXT", text) 100 | }, 101 | 102 | initialize: function() { 103 | var self = this 104 | MM.getModules().enumerate(function(m) { 105 | if(m.data.position) { 106 | self.alias[m.name] = m.name 107 | } 108 | }) 109 | this.alias = Object.assign({}, this.alias, this.defaultAlias, this.config.alias) 110 | }, 111 | 112 | glanceOn : function (call, time) { 113 | var filter = [] 114 | var self = this 115 | 116 | if (!time) { 117 | time = this.config.defaultGlancingTime 118 | } 119 | if (Object.keys(this.alias).indexOf(call) >= 0) { 120 | var modules = this.alias[call] 121 | if (Array.isArray(modules)) { 122 | filter = modules 123 | } else { 124 | filter.push(modules) 125 | } 126 | } else { 127 | return false 128 | } 129 | 130 | if (!this.glancing) { 131 | MM.getModules().enumerate(function(m) { 132 | if (m.data.position) { 133 | self.status[m.name] = m.hidden 134 | } 135 | }) 136 | } 137 | MM.getModules().enumerate(function(m) { 138 | if(Object.values(filter).indexOf(m.name) >= 0) { 139 | matched = 1 140 | } 141 | }) 142 | 143 | 144 | if (matched == 0) { 145 | return false 146 | } else { 147 | clearTimeout(this.timer) 148 | this.timer = null 149 | MM.getModules().enumerate(function(m) { 150 | if (Object.values(filter).indexOf(m.name) >= 0) { 151 | m.show(0) 152 | } else { 153 | m.hide(0) 154 | } 155 | }) 156 | this.glancing = true 157 | this.sendNotification('GLANCE_STARTED', {modules:filter, time:time}) 158 | this.timer = setTimeout(function(){ 159 | self.glanceOff() 160 | }, time) 161 | return true 162 | } 163 | }, 164 | 165 | glanceOff: function() { 166 | this.glancing = false 167 | if (this.timer) { 168 | clearTimeout(this.timer) 169 | this.timer = null 170 | var self = this 171 | MM.getModules().enumerate(function(m) { 172 | if (typeof self.status[m.name] !== 'undefined') { 173 | if (self.status[m.name]) { 174 | m.hide(0) 175 | } else { 176 | m.show(0) 177 | } 178 | } 179 | }) 180 | this.status = {} 181 | 182 | this.sendNotification('GLANCE_ENDED') 183 | return true 184 | } 185 | return false 186 | 187 | }, 188 | 189 | notificationReceived: function(notification, payload, sender) { 190 | switch(notification) { 191 | case 'DOM_OBJECTS_CREATED': 192 | this.initialize() 193 | break 194 | case 'GLANCE_ON': 195 | this.glanceOn(payload.name, payload.time) 196 | break 197 | case 'GLANCE_OFF': 198 | this.glanceOff() 199 | break 200 | } 201 | }, 202 | }) 203 | --------------------------------------------------------------------------------