Commit ca44a0a40e4d24c2b6b42467fac6072170073817
add "default settings" so that theres a clear default selected for websharemetrics (and others)
mix irving committed on 5/8/2018, 7:48:19 AMParent: a3612acadbe16fef26a6e9762e666a8f8e68128f
Files changed
app/index.js | ||
---|---|---|
@@ -20,12 +20,12 @@ | ||
20 | 20 | sideNav: { |
21 | 21 | addressBook: require('./html/sideNav/sideNavAddressBook'), |
22 | 22 | discovery: require('./html/sideNav/sideNavDiscovery') |
23 | 23 | }, |
24 | - warning: require('./html/warning'), | |
24 | + warning: require('./html/warning') | |
25 | 25 | }, |
26 | 26 | obs: { |
27 | - pluginsOk: require('./obs/pluginsOk'), | |
27 | + pluginsOk: require('./obs/pluginsOk') | |
28 | 28 | }, |
29 | 29 | page: { |
30 | 30 | addressBook: require('./page/addressBook'), |
31 | 31 | blogIndex: require('./page/blogIndex'), |
@@ -53,8 +53,9 @@ | ||
53 | 53 | }, |
54 | 54 | sync: { |
55 | 55 | initialize: { |
56 | 56 | clickHandler: require('./sync/initialize/clickHandler'), |
57 | + settings: require('./sync/initialize/settings'), | |
57 | 58 | styles: require('./sync/initialize/styles'), |
58 | 59 | suggests: require('./sync/initialize/suggests'), |
59 | 60 | zoomMemory: require('./sync/initialize/zoomMemory') |
60 | 61 | } |
app/page/settings.js | ||
---|---|---|
@@ -21,18 +21,12 @@ | ||
21 | 21 | }) |
22 | 22 | |
23 | 23 | const LANGUAGES = ['zh', 'en'] |
24 | 24 | |
25 | -// TODO - this needs moving somewhere upstream | |
26 | -// const DEFAULT_SETTINGS = { | |
27 | -// onboarded: false, | |
28 | -// language: 'zh' | |
29 | -// } | |
30 | - | |
31 | 25 | exports.create = (api) => { |
32 | 26 | return nest('app.page.settings', settings) |
33 | 27 | |
34 | - function settings(location) { | |
28 | + function settings (location) { | |
35 | 29 | // RESET the app when the settings are changed |
36 | 30 | api.settings.obs.get('language')(() => { |
37 | 31 | console.log('language changed, resetting view') |
38 | 32 | |
@@ -42,14 +36,13 @@ | ||
42 | 36 | ]) |
43 | 37 | api.history.sync.push({ page: 'settings' }) |
44 | 38 | }) |
45 | 39 | |
46 | - const webSharingMetricsOption = api.settings.obs.get('websharemetrics') | |
40 | + const webSharingMetricsOption = api.settings.obs.get('ticktack.websharemetrics') | |
47 | 41 | const feed = api.keys.sync.id() |
48 | 42 | const strings = api.translations.sync.strings() |
49 | 43 | const currentLanguage = api.settings.sync.get('language') |
50 | 44 | |
51 | - | |
52 | 45 | const editProfile = () => api.history.sync.push({ |
53 | 46 | page: 'userEdit', |
54 | 47 | feed, |
55 | 48 | callback: (err, didEdit) => { |
@@ -102,9 +95,9 @@ | ||
102 | 95 | ]) |
103 | 96 | ]) |
104 | 97 | ]) |
105 | 98 | |
106 | - function Language(lang) { | |
99 | + function Language (lang) { | |
107 | 100 | const selectLang = () => api.settings.sync.set({ language: lang }) |
108 | 101 | const className = currentLanguage === lang ? '-strong' : '' |
109 | 102 | |
110 | 103 | return h('Button -language', |
@@ -115,28 +108,28 @@ | ||
115 | 108 | strings.languages[lang] |
116 | 109 | ) |
117 | 110 | } |
118 | 111 | |
119 | - function zoomButton(increment, symbol) { | |
112 | + function zoomButton (increment, symbol) { | |
120 | 113 | const { getCurrentWebContents } = electron.remote |
121 | 114 | return h('Button -zoom', |
122 | 115 | { |
123 | 116 | 'ev-click': () => { |
124 | 117 | var zoomFactor = api.settings.sync.get('ticktack.electron.zoomFactor', 1) |
125 | 118 | var newZoomFactor = zoomFactor + increment |
126 | - var zoomFactor = api.settings.sync.set('ticktack.electron.zoomFactor', newZoomFactor) | |
119 | + api.settings.sync.set('ticktack.electron.zoomFactor', newZoomFactor) | |
127 | 120 | getCurrentWebContents().setZoomFactor(newZoomFactor) |
128 | 121 | } |
129 | 122 | }, |
130 | 123 | symbol |
131 | 124 | ) |
132 | 125 | } |
133 | 126 | |
134 | - function webSharingOption(v, label) { | |
127 | + function webSharingOption (v, label) { | |
135 | 128 | let myOption = computed(webSharingMetricsOption, opt => opt === v) |
136 | 129 | |
137 | 130 | const selectWebSharingOption = () => { |
138 | - api.settings.sync.set({ websharemetrics: v }) | |
131 | + webSharingMetricsOption.set(v) | |
139 | 132 | } |
140 | 133 | |
141 | 134 | return h('Button -websharingmetrics', |
142 | 135 | { |
@@ -145,7 +138,6 @@ | ||
145 | 138 | }, |
146 | 139 | label |
147 | 140 | ) |
148 | 141 | } |
149 | - | |
150 | 142 | } |
151 | 143 | } |
app/sync/initialize/clickHandler.js | ||
---|---|---|
@@ -10,8 +10,9 @@ | ||
10 | 10 | |
11 | 11 | exports.create = (api) => { |
12 | 12 | return nest({ |
13 | 13 | 'app.sync.initialize': function initializeClickHandling () { |
14 | + console.log('> initialise: clickHandler') | |
14 | 15 | const target = document.body |
15 | 16 | |
16 | 17 | api.app.async.catchLinkClick(target, (link, { isExternal }) => { |
17 | 18 | if (isExternal) return openExternal(link) |
app/sync/initialize/styles.js | ||
---|---|---|
@@ -10,8 +10,9 @@ | ||
10 | 10 | |
11 | 11 | exports.create = (api) => { |
12 | 12 | return nest({ |
13 | 13 | 'app.sync.initialize': function initializeStyles () { |
14 | + console.log('> initialise: styles') | |
14 | 15 | const css = values(api.styles.css()).join('\n') |
15 | 16 | insertCss(css) |
16 | 17 | } |
17 | 18 | }) |
app/sync/initialize/suggests.js | ||
---|---|---|
@@ -12,8 +12,9 @@ | ||
12 | 12 | var nav = null |
13 | 13 | |
14 | 14 | return nest({ |
15 | 15 | 'app.sync.initialize': function initializeSuggests () { |
16 | + console.log('> initialise: suggest-mentions') | |
16 | 17 | api.about.async.suggest() |
17 | 18 | api.channel.async.suggest() |
18 | 19 | // api.channel.obs.recent()() TODO - figure out how to initialise this store |
19 | 20 | } |
app/sync/initialize/zoomMemory.js | ||
---|---|---|
@@ -11,8 +11,9 @@ | ||
11 | 11 | exports.create = (api) => { |
12 | 12 | return nest('app.sync.initialize', zoomMemory) |
13 | 13 | |
14 | 14 | function zoomMemory () { |
15 | + console.log('> initialise: window form') | |
15 | 16 | const { getCurrentWebContents, getCurrentWindow } = electron.remote |
16 | 17 | |
17 | 18 | window.addEventListener('resize', () => { |
18 | 19 | var wc = getCurrentWebContents() |
app/sync/initialize/settings.js | ||
---|---|---|
@@ -1,0 +1,33 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const merge = require('lodash/merge') | |
3 | + | |
4 | +exports.gives = nest('app.sync.initialize') | |
5 | + | |
6 | +exports.needs = nest({ | |
7 | + 'settings.sync.set': 'first', | |
8 | + 'settings.sync.get': 'first' | |
9 | +}) | |
10 | + | |
11 | +const defaults = { | |
12 | + onboarded: false, | |
13 | + language: 'en', | |
14 | + ticktack: { | |
15 | + websharemetrics: 'public', | |
16 | + electron: { | |
17 | + zoomFactor: 1 | |
18 | + } | |
19 | + } | |
20 | +} | |
21 | + | |
22 | +exports.create = function (api) { | |
23 | + return nest('app.sync.initialize', initialiseSettings) | |
24 | + | |
25 | + function initialiseSettings () { | |
26 | + console.log('> initialise: default settings') | |
27 | + const { get, set } = api.settings.sync | |
28 | + const settings = merge({}, defaults, get()) | |
29 | + | |
30 | + console.log('dog', settings) | |
31 | + set(settings) | |
32 | + } | |
33 | +} |
Built with git-ssb-web