ATL-723: Show the build time in the about dialog.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-12-01 13:07:33 +01:00 committed by Akos Kitta
parent 1acf13c397
commit 7696e2c4c9
3 changed files with 43 additions and 6 deletions

View File

@ -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<void> {
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 {

View File

@ -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);
}

View File

@ -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;