Skip to content

Commit

Permalink
Merge pull request #715 from asmsuechan/add-checkbox-for-ama
Browse files Browse the repository at this point in the history
Add checkbox for ama
  • Loading branch information
asmsuechan authored Jul 22, 2017
2 parents d0b835a + 690549b commit 260611f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
8 changes: 4 additions & 4 deletions browser/main/lib/AwsMobileAnalyticsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const AMA = require('aws-sdk-mobile-analytics')
const ConfigManager = require('browser/main/lib/ConfigManager')

AWS.config.region = 'us-east-1'
if (process.env.NODE_ENV === 'production') {
if (process.env.NODE_ENV === 'production' && ConfigManager.default.get().amaEnabled) {
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxx'
})
Expand All @@ -14,7 +14,7 @@ if (process.env.NODE_ENV === 'production') {
}

function initAwsMobileAnalytics () {
if (process.env.NODE_ENV !== 'production') return
if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return
AWS.config.credentials.get((err) => {
if (!err) {
console.log('Cognito Identity ID: ' + AWS.config.credentials.identityId)
Expand All @@ -24,12 +24,12 @@ function initAwsMobileAnalytics () {
}

function recordDynamitCustomEvent (type) {
if (process.env.NODE_ENV !== 'production') return
if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return
mobileAnalyticsClient.recordEvent(type)
}

function recordStaticCustomEvent () {
if (process.env.NODE_ENV !== 'production') return
if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return
mobileAnalyticsClient.recordEvent('UI_COLOR_THEME', {
uiColorTheme: ConfigManager.default.get().ui.theme
})
Expand Down
1 change: 1 addition & 0 deletions browser/main/lib/ConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const DEFAULT_CONFIG = {
navWidth: 200,
sortBy: 'UPDATED_AT', // 'CREATED_AT', 'UPDATED_AT', 'APLHABETICAL'
listStyle: 'DEFAULT', // 'DEFAULT', 'SMALL'
amaEnabled: true,
hotkey: {
toggleFinder: OSX ? 'Cmd + Alt + S' : 'Super + Alt + S',
toggleMain: OSX ? 'Cmd + Alt + L' : 'Super + Alt + E'
Expand Down
38 changes: 38 additions & 0 deletions browser/main/modals/PreferencesModal/InfoTab.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react'
import CSSModules from 'browser/lib/CSSModules'
import styles from './InfoTab.styl'
import ConfigManager from 'browser/main/lib/ConfigManager'
import store from 'browser/main/store'
import AwsMobileAnalyticsConfig from 'browser/main/lib/AwsMobileAnalyticsConfig'

const electron = require('electron')
const { shell, remote } = electron
Expand All @@ -11,6 +14,7 @@ class InfoTab extends React.Component {
super(props)

this.state = {
config: this.props.config
}
}

Expand All @@ -19,6 +23,28 @@ class InfoTab extends React.Component {
e.preventDefault()
}

handleConfigChange (e) {
const newConfig = { amaEnabled: this.refs.amaEnabled.checked }

this.setState({ config: newConfig })
}

handleSaveButtonClick (e) {
let newConfig = {
amaEnabled: this.state.config.amaEnabled
}

ConfigManager.set(newConfig)

store.dispatch({
type: 'SET_CONFIG',
config: newConfig
})
if (!newConfig.amaEnabled) {
AwsMobileAnalyticsConfig.recordDynamitCustomEvent('DISABLE_AMA')
}
}

render () {
return (
<div styleName='root'>
Expand Down Expand Up @@ -68,6 +94,18 @@ class InfoTab extends React.Component {
License: GPL v3
</li>
</ul>
<hr />
<div styleName='policy'>Data collection policy</div>
<p>We collect only the number of users on Boostnote for DAU and any detail information<br />
such as a note's content or title is not collected.</p>
<p>You can see how it works on <a href='https://github.com/BoostIO/Boostnote'>GitHub</a></p>
<input onChange={(e) => this.handleConfigChange(e)}
checked={this.state.config.amaEnabled}
ref='amaEnabled'
type='checkbox'
/>
Enable to send analytics to our servers<br />
<button onClick={(e) => this.handleSaveButtonClick(e)}>Save</button>
</div>
)
}
Expand Down
7 changes: 5 additions & 2 deletions browser/main/modals/PreferencesModal/InfoTab.styl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
a
color #4E8EC6
text-decoration none


.policy
font-size 20px

body[data-theme="dark"]
.root
color alpha($tab--dark-text-color, 80%)
color alpha($tab--dark-text-color, 80%)
7 changes: 6 additions & 1 deletion browser/main/modals/PreferencesModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ class Preferences extends React.Component {

switch (this.state.currentTab) {
case 'INFO':
return <InfoTab />
return (
<InfoTab
dispatch={dispatch}
config={config}
/>
)
case 'HOTKEY':
return (
<HotkeyTab
Expand Down

0 comments on commit 260611f

Please sign in to comment.