experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #8 from autonome/win

Win

authored by

Dietrich Ayala and committed by
GitHub
38bbd345 9db8d8af

+72 -219
+6 -59
features/cmd/cmd.js
··· 114 114 let _windows = {}; 115 115 116 116 const openInputWindow = (api) => { 117 + const height = 50; 118 + const width = 600; 119 + 117 120 const params = { 118 121 type: labels.featureType, 119 122 file: 'features/cmd/panel.html', 120 - height: 50, 121 - width: 600 123 + height, 124 + width 122 125 }; 123 126 124 - _api.openWebWindow(params); 125 - 126 - return; 127 - 128 - const height = 50; 129 - const width = 600; 130 - 131 - let win = null; 132 - 133 - const windowKey = labels.featureType; 134 - 135 - if (_windows[windowKey]) { 136 - console.log(labels.featureType, 'using stored window'); 137 - win = _windows[windowKey]; 138 - win.show(); 139 - } 140 - else { 141 - console.log(labels.featureType, 'creating new window'); 142 - 143 - win = new BrowserWindow({ 144 - height, 145 - width, 146 - center: true, 147 - skipTaskbar: true, 148 - autoHideMenuBar: true, 149 - titleBarStyle: 'hidden', 150 - webPreferences: { 151 - preload: api.preloadPath, 152 - // isolate content and do not persist it 153 - partition: Date.now() 154 - } 155 - }); 156 - 157 - //_windows[windowKey] = win; 158 - } 159 - 160 - const onGoAway = () => { 161 - /* 162 - if (item.keepLive) { 163 - _windows[windowKey] = win; 164 - win.hide(); 165 - } 166 - else { 167 - win.destroy(); 168 - } 169 - */ 170 - win.destroy(); 171 - } 172 - win.on('blur', onGoAway); 173 - win.on('close', onGoAway); 174 - 175 - win.webContents.send('window', { type: labels.featureType, id: win.id}); 176 - 177 - //win.webContents.openDevTools(); 178 - 179 - win.loadFile('features/cmd/panel.html'); 180 - console.log('loaded'); 127 + _api.openWindow(params); 181 128 }; 182 129 183 130 const initStore = (store, data) => {
+7 -46
features/peeks/peeks.js
··· 130 130 const executeItem = (api, item) => { 131 131 const height = item.height || 600; 132 132 const width = item.width || 800; 133 - 134 - let win = null; 135 133 136 - const windowKey = labels.featureType + item.keyNum; 134 + const params = { 135 + type: labels.featureType, 136 + address: item.address, 137 + height, 138 + width 139 + }; 137 140 138 - if (_windows[windowKey]) { 139 - console.log(labels.featureType, item.keyNum, 'using stored window'); 140 - win = _windows[windowKey]; 141 - win.show(); 142 - } 143 - else { 144 - console.log(labels.featureType, item.keyNum, 'creating new window'); 145 - 146 - win = new BrowserWindow({ 147 - height, 148 - width, 149 - center: true, 150 - skipTaskbar: true, 151 - autoHideMenuBar: true, 152 - titleBarStyle: 'hidden', 153 - webPreferences: { 154 - preload: api.preloadPath, 155 - // isolate content and do not persist it 156 - partition: Date.now() 157 - } 158 - }); 159 - 160 - //_windows[windowKey] = win; 161 - } 162 - 163 - const onGoAway = () => { 164 - /* 165 - if (item.keepLive) { 166 - _windows[windowKey] = win; 167 - win.hide(); 168 - } 169 - else { 170 - win.destroy(); 171 - } 172 - */ 173 - win.destroy(); 174 - } 175 - win.on('blur', onGoAway); 176 - win.on('close', onGoAway); 177 - 178 - win.webContents.send('window', { type: labels.featureType, id: win.id, data: item }); 179 - 180 - win.loadURL(item.address); 141 + _api.openWindow(params); 181 142 }; 182 143 183 144 const initStore = (store, data) => {
+25 -34
features/scripts/scripts.js
··· 112 112 prefs: { 113 113 }, 114 114 items: [ 115 - /* 116 115 { 117 116 id: 'peek:script:localhost:test', 118 117 title: 'localhost test', ··· 124 123 storehistory: false, 125 124 notifyOnChange: false 126 125 }, 127 - */ 128 126 ] 129 127 }; 130 - 131 - let _windows = {}; 132 128 133 129 const executeItem = (api, script, cb) => { 134 - const view = new BrowserWindow({ 135 - show: false, 136 - webPreferences: { 137 - preload: api.preloadPath, 138 - // isolate content and do not persist it 139 - partition: Date.now() 140 - } 141 - }); 142 - 143 - view.webContents.send('window', { 144 - id: 'view', 145 - type: 'script', 146 - data: script 147 - }); 148 - 149 - view.webContents.loadURL(script.address); 130 + console.log('script.executeItem') 150 131 151 132 const str = ` 152 133 const s = "${script.selector}"; ··· 155 136 value; 156 137 `; 157 138 158 - view.webContents.on('dom-ready', async () => { 159 - try { 160 - const r = await view.webContents.executeJavaScript(str); 161 - cb(r); 162 - } catch(ex) { 163 - console.error('cs exec error', ex); 164 - cb(null); 139 + const callback = (result) => { 140 + console.log('lcb', result); 141 + cb(result); 142 + }; 143 + 144 + const params = { 145 + type: labels.featureType, 146 + address: script.address, 147 + show: false, 148 + script: { 149 + script: str, 150 + domEvent: 'dom-ready', 151 + closeOnCompletion: true, 152 + callback 165 153 } 166 - view.destroy(); 167 - }); 154 + }; 155 + 156 + _api.openWindow(params); 168 157 }; 169 158 170 159 const initStore = (store, data) => { ··· 190 179 // at once every time app starts 191 180 items.forEach(item => { 192 181 const interval = setInterval(() => { 193 - //console.log('interval hit', item.title); 194 182 const r = executeItem(api, item, (res) => { 195 - //console.log('cs r', res); 196 183 197 184 if (item.previousValue != res) { 198 185 186 + // TODO: figure this out - it blows away all timers, which isn't great 187 + // 199 188 // update stored value 200 - item.previousValue = res; 201 - updateItem(item); 189 + //item.previousValue = res; 190 + //updateItem(item); 202 191 203 192 // notification 204 193 // add to schema and support per script ··· 220 209 }; 221 210 222 211 const init = (api, store) => { 212 + console.log('scripts: init') 213 + 223 214 _store = store; 224 215 _api = api; 225 216 ··· 230 221 get items() { return _store.get('items'); }, 231 222 }; 232 223 233 - // initialize peeks 224 + // initialize scripts 234 225 if (_data.items.length > 0) { 235 226 initItems(api, _data.prefs, _data.items); 236 227 }
+7 -56
features/settings/settings.js
··· 65 65 const openSettingsWindow = (api, prefs) => { 66 66 const height = prefs.height || 600; 67 67 const width = prefs.width || 800; 68 - 69 - let win = null; 70 68 71 - const windowKey = labels.featureType; 72 - 73 - if (_windows[windowKey]) { 74 - console.log(labels.featureType, 'using stored window'); 75 - win = _windows[windowKey]; 76 - win.show(); 77 - } 78 - else { 79 - console.log(labels.featureType, 'creating new window'); 80 - 81 - win = new BrowserWindow({ 82 - height, 83 - width, 84 - center: true, 85 - skipTaskbar: true, 86 - autoHideMenuBar: true, 87 - titleBarStyle: 'hidden', 88 - webPreferences: { 89 - preload: api.preloadPath, 90 - // isolate content and do not persist it 91 - partition: Date.now() 92 - } 93 - }); 69 + const params = { 70 + type: labels.featureType, 71 + file: 'features/settings/content.html', 72 + height, 73 + width 74 + }; 94 75 95 - //_windows[windowKey] = win; 96 - } 97 - 98 - win.webContents.openDevTools(); 99 - 100 - /* 101 - win.on('close', (e) => { 102 - console.log('onClose - just hiding'); 103 - e.preventDefault(); 104 - win.hide(); 105 - }); 106 - */ 107 - 108 - const onGoAway = () => { 109 - /* 110 - if (item.keepLive) { 111 - _windows[windowKey] = win; 112 - win.hide(); 113 - } 114 - else { 115 - win.destroy(); 116 - } 117 - */ 118 - win.destroy(); 119 - } 120 - win.on('blur', onGoAway); 121 - win.on('close', onGoAway); 122 - 123 - win.webContents.send('window', { type: labels.featureType, id: win.id, data: prefs }); 124 - 125 - win.loadFile('features/settings/content.html'); 76 + _api.openWindow(params); 126 77 }; 127 78 128 79 const initStore = (store, data) => {
-20
features/slides/slides.js
··· 267 267 win.on('blur', onGoAway); 268 268 win.on('close', onGoAway); 269 269 270 - /* 271 - const str = ` 272 - window.addEventListener('keyup', e => { 273 - if (e.key == 'Escape') { 274 - console.log('peek script esc'); 275 - } 276 - }); 277 - 1; 278 - `; 279 - 280 - win.webContents.on('dom-ready', async () => { 281 - try { 282 - const r = await win.webContents.executeJavaScript(str); 283 - console.log(r); 284 - } catch(ex) { 285 - console.error('cs exec error', ex); 286 - } 287 - }); 288 - */ 289 - 290 270 win.webContents.send('window', { type: labels.featureType, id: win.id, data: item }); 291 271 292 272 win.loadURL(item.address);
+27 -4
index.js
··· 159 159 // eventually get to less tight coupling 160 160 const api = { 161 161 preloadPath, 162 - openWebWindow 162 + openWindow 163 163 }; 164 164 165 165 const datastorePrefix = 'peekFeature'; ··· 278 278 }); 279 279 280 280 281 - const openWebWindow = (params) => { 282 - console.log('creating new web window', params); 281 + const openWindow = (params) => { 282 + console.log('creating new window', params); 283 283 284 284 const height = params.height || 600; 285 285 const width = params.width || 800; 286 + const show = params.hasOwnProperty('show') ? params.show : true; 286 287 287 288 const win = new BrowserWindow({ 288 289 height, 289 290 width, 291 + show, 290 292 center: true, 291 293 skipTaskbar: true, 292 294 autoHideMenuBar: true, ··· 298 300 } 299 301 }); 300 302 303 + // TODO: make configurable 301 304 const onGoAway = () => { 302 305 win.destroy(); 303 306 } ··· 314 317 win.loadURL(params.address); 315 318 } 316 319 else if (params.file) { 317 - win.loadFile('features/cmd/panel.html'); 320 + win.loadFile(params.file); 318 321 } 319 322 else { 320 323 console.error('openWindow: neither address nor file!'); 324 + } 325 + 326 + if (params.script) { 327 + const script = params.script; 328 + const domEvent = script.domEvent || 'dom-ready'; 329 + 330 + win.webContents.on(domEvent, async () => { 331 + try { 332 + const r = await win.webContents.executeJavaScript(script.script); 333 + if (script.callback) { 334 + script.callback(r); 335 + } 336 + } catch(ex) { 337 + console.error('cs exec error', ex); 338 + script.callback(null); 339 + } 340 + if (script.closeOnCompletion) { 341 + win.destroy(); 342 + } 343 + }); 321 344 } 322 345 }; 323 346