1
1
import { inject , injectable } from 'inversify' ;
2
+ import * as moment from 'moment' ;
2
3
import { remote } from 'electron' ;
3
4
import { isOSX , isWindows } from '@theia/core/lib/common/os' ;
4
5
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service' ;
@@ -34,8 +35,10 @@ export class About extends Contribution {
34
35
async showAbout ( ) : Promise < void > {
35
36
const ideStatus = FrontendApplicationConfigProvider . get ( ) [ 'status' ] ;
36
37
const { version, commit, status : cliStatus } = await this . configService . getVersion ( ) ;
37
- const detail = `
38
+ const buildDate = this . buildDate ;
39
+ const detail = ( useAgo : boolean ) => `
38
40
Version: ${ remote . app . getVersion ( ) }
41
+ Date: ${ buildDate ? buildDate : 'dev build' } ${ buildDate && useAgo ? ` (${ this . ago ( buildDate ) } )` : '' }
39
42
CLI Version: ${ version } ${ cliStatus ? ` ${ cliStatus } ` : '' } [${ commit } ]
40
43
41
44
Copyright © ${ new Date ( ) . getFullYear ( ) } Arduino SA
@@ -47,22 +50,53 @@ Copyright © ${new Date().getFullYear()} Arduino SA
47
50
message : `${ this . applicationName } ${ ideStatus ? ` – ${ ideStatus } ` : '' } ` ,
48
51
title : `${ this . applicationName } ${ ideStatus ? ` – ${ ideStatus } ` : '' } ` ,
49
52
type : 'info' ,
50
- detail,
53
+ detail : detail ( true ) ,
51
54
buttons,
52
55
noLink : true ,
53
56
defaultId : buttons . indexOf ( ok ) ,
54
57
cancelId : buttons . indexOf ( ok )
55
58
} ) ;
56
59
57
60
if ( buttons [ response ] === copy ) {
58
- await this . clipboardService . writeText ( detail ) ;
61
+ await this . clipboardService . writeText ( detail ( false ) ) ;
59
62
}
60
63
}
61
64
62
65
protected get applicationName ( ) : string {
63
66
return FrontendApplicationConfigProvider . get ( ) . applicationName ;
64
67
}
65
68
69
+ protected get buildDate ( ) : string | undefined {
70
+ return FrontendApplicationConfigProvider . get ( ) . buildDate ;
71
+ }
72
+
73
+ protected ago ( isoTime : string ) : string {
74
+ const now = moment ( Date . now ( ) ) ;
75
+ const other = moment ( isoTime ) ;
76
+ let result = now . diff ( other , 'minute' ) ;
77
+ if ( result < 60 ) {
78
+ return result === 1 ? `${ result } minute ago` : `${ result } minute ago` ;
79
+ }
80
+ result = now . diff ( other , 'hour' ) ;
81
+ if ( result < 25 ) {
82
+ return result === 1 ? `${ result } hour ago` : `${ result } hours ago` ;
83
+ }
84
+ result = now . diff ( other , 'day' ) ;
85
+ if ( result < 8 ) {
86
+ return result === 1 ? `${ result } day ago` : `${ result } days ago` ;
87
+ }
88
+ result = now . diff ( other , 'week' ) ;
89
+ if ( result < 5 ) {
90
+ return result === 1 ? `${ result } week ago` : `${ result } weeks ago` ;
91
+ }
92
+ result = now . diff ( other , 'month' ) ;
93
+ if ( result < 13 ) {
94
+ return result === 1 ? `${ result } month ago` : `${ result } months ago` ;
95
+ }
96
+ result = now . diff ( other , 'year' ) ;
97
+ return result === 1 ? `${ result } year ago` : `${ result } years ago` ;
98
+ }
99
+
66
100
}
67
101
68
102
export namespace About {
0 commit comments