@@ -4,6 +4,9 @@ import keygen from 'boost/keygen'
44import dataStore from 'boost/dataStore'
55import { request , WEB_URL } from 'boost/api'
66
7+ const electron = require ( 'electron' )
8+ const version = electron . remote . app . getVersion ( )
9+
710function isSameDate ( a , b ) {
811 a = moment ( a ) . utcOffset ( + 540 ) . format ( 'YYYYMMDD' )
912 b = moment ( b ) . utcOffset ( + 540 ) . format ( 'YYYYMMDD' )
@@ -81,7 +84,7 @@ export function postRecords (data) {
8184 } )
8285}
8386
84- export function emit ( type , data ) {
87+ export function emit ( type , data = { } ) {
8588 let records = getAllRecords ( )
8689
8790 let index = _ . findIndex ( records , record => {
@@ -94,7 +97,6 @@ export function emit (type, data) {
9497 records . push ( todayRecord )
9598 }
9699 else todayRecord = records [ index ]
97- console . log ( type )
98100 switch ( type ) {
99101 case 'ARTICLE_CREATE' :
100102 case 'ARTICLE_UPDATE' :
@@ -104,16 +106,34 @@ export function emit (type, data) {
104106 case 'FOLDER_DESTROY' :
105107 case 'FINDER_OPEN' :
106108 case 'FINDER_COPY' :
109+ case 'MAIN_DETAIL_COPY' :
107110 todayRecord [ type ] = todayRecord [ type ] == null
108111 ? 1
109112 : todayRecord [ type ] + 1
110113
111114 break
112115 }
113116
117+ // Count ARTICLE_CREATE and ARTICLE_UPDATE again by syntax
118+ if ( ( type === 'ARTICLE_CREATE' || type === 'ARTICLE_UPDATE' ) && data . mode != null ) {
119+ let recordKey = type + '_BY_SYNTAX'
120+ if ( todayRecord [ recordKey ] == null ) todayRecord [ recordKey ] = { }
121+
122+ todayRecord [ recordKey ] [ data . mode ] = todayRecord [ recordKey ] [ data . mode ] == null
123+ ? 1
124+ : todayRecord [ recordKey ] [ data . mode ] + 1
125+ }
126+
114127 let storeData = dataStore . getData ( )
115128 todayRecord . FOLDER_COUNT = _ . isArray ( storeData . folders ) ? storeData . folders . length : 0
116129 todayRecord . ARTICLE_COUNT = _ . isArray ( storeData . articles ) ? storeData . articles . length : 0
130+ todayRecord . CLIENT_VERSION = version
131+
132+ todayRecord . SYNTAX_COUNT = storeData . articles . reduce ( ( sum , article ) => {
133+ if ( sum [ article . mode ] == null ) sum [ article . mode ] = 1
134+ else sum [ article . mode ] ++
135+ return sum
136+ } , { } )
117137
118138 saveAllRecords ( records )
119139}
0 commit comments