1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Add checkbox for ama

This commit is contained in:
asmsuechan
2017-07-22 08:59:27 +09:00
parent d0b835a825
commit 275e3317a3
4 changed files with 40 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ const AMA = require('aws-sdk-mobile-analytics')
const ConfigManager = require('browser/main/lib/ConfigManager') const ConfigManager = require('browser/main/lib/ConfigManager')
AWS.config.region = 'us-east-1' 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({ AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxx' IdentityPoolId: 'us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxx'
}) })
@@ -14,7 +14,7 @@ if (process.env.NODE_ENV === 'production') {
} }
function initAwsMobileAnalytics () { 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) => { AWS.config.credentials.get((err) => {
if (!err) { if (!err) {
console.log('Cognito Identity ID: ' + AWS.config.credentials.identityId) console.log('Cognito Identity ID: ' + AWS.config.credentials.identityId)
@@ -24,12 +24,12 @@ function initAwsMobileAnalytics () {
} }
function recordDynamitCustomEvent (type) { function recordDynamitCustomEvent (type) {
if (process.env.NODE_ENV !== 'production') return if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return
mobileAnalyticsClient.recordEvent(type) mobileAnalyticsClient.recordEvent(type)
} }
function recordStaticCustomEvent () { 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', { mobileAnalyticsClient.recordEvent('UI_COLOR_THEME', {
uiColorTheme: ConfigManager.default.get().ui.theme uiColorTheme: ConfigManager.default.get().ui.theme
}) })

View File

@@ -14,6 +14,7 @@ export const DEFAULT_CONFIG = {
navWidth: 200, navWidth: 200,
sortBy: 'UPDATED_AT', // 'CREATED_AT', 'UPDATED_AT', 'APLHABETICAL' sortBy: 'UPDATED_AT', // 'CREATED_AT', 'UPDATED_AT', 'APLHABETICAL'
listStyle: 'DEFAULT', // 'DEFAULT', 'SMALL' listStyle: 'DEFAULT', // 'DEFAULT', 'SMALL'
amaEnabled: true,
hotkey: { hotkey: {
toggleFinder: OSX ? 'Cmd + Alt + S' : 'Super + Alt + S', toggleFinder: OSX ? 'Cmd + Alt + S' : 'Super + Alt + S',
toggleMain: OSX ? 'Cmd + Alt + L' : 'Super + Alt + E' toggleMain: OSX ? 'Cmd + Alt + L' : 'Super + Alt + E'

View File

@@ -1,6 +1,8 @@
import React from 'react' import React from 'react'
import CSSModules from 'browser/lib/CSSModules' import CSSModules from 'browser/lib/CSSModules'
import styles from './InfoTab.styl' import styles from './InfoTab.styl'
import ConfigManager from 'browser/main/lib/ConfigManager'
import store from 'browser/main/store'
const electron = require('electron') const electron = require('electron')
const { shell, remote } = electron const { shell, remote } = electron
@@ -11,6 +13,7 @@ class InfoTab extends React.Component {
super(props) super(props)
this.state = { this.state = {
config: this.props.config
} }
} }
@@ -19,6 +22,25 @@ class InfoTab extends React.Component {
e.preventDefault() 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
})
}
render () { render () {
return ( return (
<div styleName='root'> <div styleName='root'>
@@ -68,6 +90,13 @@ class InfoTab extends React.Component {
License: GPL v3 License: GPL v3
</li> </li>
</ul> </ul>
<input onChange={(e) => this.handleConfigChange(e)}
checked={this.state.config.amaEnabled}
ref='amaEnabled'
type='checkbox'
/>
Enable to send analytics to our servers
<button onClick={(e) => this.handleSaveButtonClick(e)}>Save</button>
</div> </div>
) )
} }

View File

@@ -44,7 +44,12 @@ class Preferences extends React.Component {
switch (this.state.currentTab) { switch (this.state.currentTab) {
case 'INFO': case 'INFO':
return <InfoTab /> return (
<InfoTab
dispatch={dispatch}
config={config}
/>
)
case 'HOTKEY': case 'HOTKEY':
return ( return (
<HotkeyTab <HotkeyTab