diff --git a/arduino-ide-extension/src/browser/contributions/about.ts b/arduino-ide-extension/src/browser/contributions/about.ts index 77af7f39..3e4abb6f 100644 --- a/arduino-ide-extension/src/browser/contributions/about.ts +++ b/arduino-ide-extension/src/browser/contributions/about.ts @@ -1,4 +1,5 @@ import { inject, injectable } from 'inversify'; +import * as moment from 'moment'; import { remote } from 'electron'; import { isOSX, isWindows } from '@theia/core/lib/common/os'; import { ClipboardService } from '@theia/core/lib/browser/clipboard-service'; @@ -34,8 +35,10 @@ export class About extends Contribution { async showAbout(): Promise { const ideStatus = FrontendApplicationConfigProvider.get()['status']; const { version, commit, status: cliStatus } = await this.configService.getVersion(); - const detail = ` + const buildDate = this.buildDate; + const detail = (useAgo: boolean) => ` Version: ${remote.app.getVersion()} +Date: ${buildDate ? buildDate : 'dev build'}${buildDate && useAgo ? ` (${this.ago(buildDate)})` : ''} CLI Version: ${version}${cliStatus ? ` ${cliStatus}` : ''} [${commit}] Copyright © ${new Date().getFullYear()} Arduino SA @@ -47,7 +50,7 @@ Copyright © ${new Date().getFullYear()} Arduino SA message: `${this.applicationName}${ideStatus ? ` – ${ideStatus}` : ''}`, title: `${this.applicationName}${ideStatus ? ` – ${ideStatus}` : ''}`, type: 'info', - detail, + detail: detail(true), buttons, noLink: true, defaultId: buttons.indexOf(ok), @@ -55,7 +58,7 @@ Copyright © ${new Date().getFullYear()} Arduino SA }); if (buttons[response] === copy) { - await this.clipboardService.writeText(detail); + await this.clipboardService.writeText(detail(false)); } } @@ -63,6 +66,37 @@ Copyright © ${new Date().getFullYear()} Arduino SA return FrontendApplicationConfigProvider.get().applicationName; } + protected get buildDate(): string | undefined { + return FrontendApplicationConfigProvider.get().buildDate; + } + + protected ago(isoTime: string): string { + const now = moment(Date.now()); + const other = moment(isoTime); + let result = now.diff(other, 'minute'); + if (result < 60) { + return result === 1 ? `${result} minute ago` : `${result} minute ago`; + } + result = now.diff(other, 'hour'); + if (result < 25) { + return result === 1 ? `${result} hour ago` : `${result} hours ago`; + } + result = now.diff(other, 'day'); + if (result < 8) { + return result === 1 ? `${result} day ago` : `${result} days ago`; + } + result = now.diff(other, 'week'); + if (result < 5) { + return result === 1 ? `${result} week ago` : `${result} weeks ago`; + } + result = now.diff(other, 'month'); + if (result < 13) { + return result === 1 ? `${result} month ago` : `${result} months ago`; + } + result = now.diff(other, 'year'); + return result === 1 ? `${result} year ago` : `${result} years ago`; + } + } export namespace About { diff --git a/electron/packager/config.js b/electron/packager/config.js index 2a02f046..08a78eeb 100644 --- a/electron/packager/config.js +++ b/electron/packager/config.js @@ -95,13 +95,13 @@ function currentCommitish() { // return git('rev-parse --abbrev-ref HEAD'); // } -function generateTemplate() { +function generateTemplate(buildDate) { // do `export PUBLISH=true yarn package` if you want to mimic CI build locally. // const electronPublish = release || (isCI && currentBranch() === 'master') || process.env.PUBLISH === 'true'; const version = getVersion(); const productName = 'Arduino Pro IDE'; const name = 'arduino-pro-ide'; - const customizations = { + let customizations = { name, description: productName, version, @@ -113,6 +113,9 @@ function generateTemplate() { } } }; + if (buildDate) { + customizations = merge(customizations, { theia: { frontend: { config: { buildDate } } } }); + } const template = require('../build/template-package.json'); return merge(template, customizations); } diff --git a/electron/packager/index.js b/electron/packager/index.js index 4bc9a14b..8deba70b 100644 --- a/electron/packager/index.js +++ b/electron/packager/index.js @@ -9,7 +9,7 @@ const isCI = require('is-ci'); shell.env.THEIA_ELECTRON_SKIP_REPLACE_FFMPEG = '1'; // Do not run the ffmpeg validation for the packager. shell.env.NODE_OPTIONS = '--max_old_space_size=4096'; // Increase heap size for the CI - const template = require('./config').generateTemplate(); + const template = require('./config').generateTemplate(new Date().toISOString()); const utils = require('./utils'); const merge = require('deepmerge'); const { isRelease, isElectronPublish } = utils;