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 #18 from autonome/moreweb

support for named profiles, default profile, debug profile, and more …

authored by

Dietrich Ayala and committed by
GitHub
ff51d0a0 0a910f1f

+80 -26
+2 -1
README.md
··· 148 148 Core+settings 149 149 [x] move feature list and enablement to storage 150 150 [x] merge core + settings 151 - [] enable/disable features 151 + [x] enable/disable features 152 152 [] configurable default feature to load on app open (or none) 153 153 [] figure out re-init/reload story when pref/feature changes 154 + [] figure out feature unload/reload (unreg shortcuts, close windows, etc) 154 155 155 156 History 156 157 [] implement pubsub api
+22 -19
features/core/background.js
··· 57 57 58 58 const initShortcut = (shortcut) => { 59 59 _api.shortcuts.register(shortcut, () => { 60 - console.log('settings shortcut executed') 61 60 openSettingsWindow(prefs()); 62 61 }); 63 62 }; ··· 65 64 const prefs = () => JSON.parse(_store.getItem('prefs')); 66 65 const items = () => JSON.parse(_store.getItem('items')); 67 66 68 - const initFeature = feature => { 69 - if (!feature.enabled) { 67 + const initFeature = f => { 68 + if (!f.enabled) { 70 69 return; 71 70 } 72 71 73 - log('initializing feature ' + feature); 72 + log('initializing feature ' + f); 74 73 75 74 const params = { 76 - feature, 75 + feature: f.title, 77 76 debug, 78 - file: feature.address, 77 + file: f.address, 79 78 keepLive: true, 80 - show: true 79 + show: false 81 80 }; 82 81 83 82 window.app.openWindow(params); ··· 98 97 }); 99 98 }; 100 99 101 - const onChange = (changed, old) => { 102 - log(labels.featureType, 'onChange', changed); 100 + const odiff = (a, b) => Object.entries(b).reduce((c, [k, v]) => Object.assign(c, a[k] ? {} : { [k]: v }), {}); 103 101 104 - // TODO only update store if changed 105 - if (changed.prefs) { 106 - _store.setItem('prefs', JSON.stringify(changed.prefs)); 107 - } 108 - 109 - if (changed.items) { 110 - _store.setItem('items', JSON.stringif(changed.items)); 111 - } 112 - 113 - // re-init 102 + const onStorageChange = (e) => { 103 + console.log(e); 104 + //log('oSC', e.key, JSON.stringify(odiff(e.oldValue, e.newValue))); 105 + /* 106 + e.key; 107 + e.oldValue; 108 + e.newValue; 109 + e.url; 110 + JSON.stringify( 111 + e.storageArea 112 + ); 113 + */ 114 + items().forEach(initFeature); 114 115 }; 116 + 117 + window.addEventListener('storage', onStorageChange); 115 118 116 119 const init = () => { 117 120 log('settings: init');
+4 -2
features/core/config.js
··· 90 90 shortcutKey: 'Option+,', 91 91 height: 600, 92 92 width: 800, 93 + openDefaultFeature: 'Settings', 94 + showTrayIcon: true, 93 95 }, 94 96 items: [ 95 97 { title: 'Cmd', ··· 105 107 { title: 'Peeks', 106 108 address: 'features/peeks/background.html', 107 109 settingsAddress: 'features/peeks/settings.html', 108 - enabled: false 110 + enabled: true 109 111 }, 110 112 { title: 'Scripts', 111 113 address: 'features/scripts/background.html', ··· 115 117 { title: 'Slides', 116 118 address: 'features/slides/background.html', 117 119 settingsAddress: 'features/slides/settings.html', 118 - enabled: false 120 + enabled: true 119 121 }, 120 122 ] 121 123 };
+5 -3
features/core/settings.js
··· 4 4 if (!DEBUG) { 5 5 return; 6 6 } 7 + //const str = args.map(JSON.stringify).join(', '); 7 8 const str = args.join(', '); 8 9 console.log(str); 9 - window.app.log(labels.featureType, args.map(JSON.stringify).join(', ')); 10 + window.app.log(labels.featureType, str); 10 11 }; 11 12 12 13 const init = () => { ··· 24 25 25 26 const onChange = newData => { 26 27 log('onChange', JSON.stringify(newData)); 28 + 27 29 if (newData.prefs) { 28 30 const key = 'prefs'; 29 31 localStorage.setItem(key, JSON.stringify(newData[key])); ··· 62 64 63 65 const fillPaneFromSchema = (pane, labels, schema, data, onChange, disabled) => { 64 66 const props = schema.properties; 67 + 65 68 Object.keys(props).forEach(k => { 66 69 // schema for property 67 70 const s = props[k]; ··· 146 149 147 150 log('folder level update for', labels.featureDisplay, paneData); 148 151 149 - let updated = { 150 - }; 152 + let updated = {}; 151 153 152 154 // TODO: make this right, ugh 153 155 if (prefs) {
+47 -1
index.js
··· 3 3 4 4 console.log('main'); 5 5 6 - 7 6 const DEBUG = process.env.DEBUG; 8 7 9 8 // Modules to control application life and create native browser window ··· 18 17 Tray 19 18 } = require('electron'); 20 19 20 + const fs = require('fs'); 21 21 const path = require('path'); 22 + 23 + // script loaded into every app window 22 24 const preloadPath = path.join(__dirname, 'preload.js'); 23 25 26 + // app hidden window to load 27 + // core application logic is here 24 28 const webCoreAddress = 'features/core/background.html'; 29 + 30 + const p = process.env.PROFILE; 31 + console.log('env prof?', p, p != undefined, typeof p, p.length) 32 + const profileIsLegit = p => p != undefined && typeof p == 'string' && p.length > 0; 33 + 34 + const PROFILE = 35 + profileIsLegit(process.env.PROFILE) 36 + ? process.env.PROFILE 37 + : (DEBUG ? 'debug' : 'default'); 38 + 39 + console.log('PROFILE', PROFILE); 40 + 41 + // Profile dirs are subdir of userData dir 42 + // ..................................... ↓ we set this per profile 43 + // 44 + // {home} / {appData} / {userData} / {profileDir} 45 + // 46 + // Chromium's data in a subfolder of profile folder 47 + // 48 + // ................................................. ↓ we set this per profile 49 + // 50 + // {home} / {appData} / {userData} / {profileDir} / {sessionData} 51 + 52 + 53 + // specify various app data paths and make if not exist 54 + const defaultUserDataPath = app.getPath('userData'); 55 + const profileDataPath = path.join(defaultUserDataPath, PROFILE); 56 + const sessionDataPath = path.join(profileDataPath, 'chromium'); 57 + 58 + console.log('udp', defaultUserDataPath); 59 + console.log('pdp', profileDataPath); 60 + console.log('sdp', sessionDataPath); 61 + 62 + // create filesystem 63 + if (!fs.existsSync(sessionDataPath)){ 64 + fs.mkdirSync(sessionDataPath, { recursive: true }); 65 + } 66 + 67 + // configure Electron with these paths 68 + app.setPath('userData', profileDataPath); 69 + app.setPath('sessionData', sessionDataPath); 25 70 26 71 // ***** Developer / Error handling / Etc ***** 27 72 const isDev = require('electron-is-dev'); ··· 128 173 feature: 'Core', 129 174 file: webCoreAddress, 130 175 show: true, 176 + keepLive: true, 131 177 debug: DEBUG 132 178 }) 133 179