From 4f161c2307f5126c3391c0c48b72440e20bb3ac4 Mon Sep 17 00:00:00 2001 From: Daniel Eichhorn Date: Mon, 24 Jun 2024 18:57:52 +0200 Subject: [PATCH] Add versions to app object, add build time --- createBuildDate.js | 10 --- package.json | 2 +- src/app/app.component.html | 8 +- src/app/app.component.scss | 26 ++++++ src/app/app.component.ts | 17 +++- src/app/flasher/flasher.component.html | 2 +- src/app/flasher/flasher.component.ts | 9 +- src/app/models/app-version.ts | 6 ++ src/app/models/app.ts | 3 +- src/app/models/environment.ts | 3 + src/app/services/environment.service.ts | 20 +++++ src/assets/apps.json | 104 ++++++++++++++---------- src/assets/buildDate.json | 3 - src/assets/environment.json | 3 + updateEnvironmentInfo.js | 10 +++ 15 files changed, 161 insertions(+), 65 deletions(-) delete mode 100644 createBuildDate.js create mode 100644 src/app/models/app-version.ts create mode 100644 src/app/models/environment.ts create mode 100644 src/app/services/environment.service.ts delete mode 100644 src/assets/buildDate.json create mode 100644 src/assets/environment.json create mode 100644 updateEnvironmentInfo.js diff --git a/createBuildDate.js b/createBuildDate.js deleted file mode 100644 index 68ee8da..0000000 --- a/createBuildDate.js +++ /dev/null @@ -1,10 +0,0 @@ -const { writeFileSync } = require('fs') -const { join } = require('path') - -const TIME_STAMP_PATH = join(__dirname, 'src/assets/buildDate.json'); - -const createBuildDate = { - year: new Date() -} - -writeFileSync(TIME_STAMP_PATH, JSON.stringify(createBuildDate, null, 2)); \ No newline at end of file diff --git a/package.json b/package.json index 9f163b7..afbc417 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "scripts": { "ng": "ng", "start": "ng serve --proxy-config proxy.conf.json", - "build": "node createBuildDate.js && ng build", + "build": "node updateEnvironmentInfo.js && ng build", "watch": "ng build --watch --configuration development", "test": "ng test" }, diff --git a/src/app/app.component.html b/src/app/app.component.html index b4856f9..6d245c3 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -11,5 +11,11 @@ \ No newline at end of file diff --git a/src/app/app.component.scss b/src/app/app.component.scss index f77748e..04a1efb 100644 --- a/src/app/app.component.scss +++ b/src/app/app.component.scss @@ -34,3 +34,29 @@ a, a:visited { padding: 16px; } +.tooltip { + position: relative; + display: inline-block; + border-bottom: 1px dotted black; /* If you want dots under the hoverable text */ + } + + /* Tooltip text */ + .tooltip .tooltiptext { + visibility: hidden; + width: 120px; + background-color: black; + color: #fff; + text-align: center; + padding: 5px 0; + border-radius: 6px; + + /* Position the tooltip text - see examples below! */ + position: absolute; + z-index: 1; + } + + /* Show the tooltip text when you mouse over the tooltip container */ + .tooltip:hover .tooltiptext { + visibility: visible; + } + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 741084a..be886e9 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,4 +1,6 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; +import { EnvironmentService } from './services/environment.service'; +import { Environment } from './models/environment'; @@ -7,12 +9,23 @@ import { Component } from '@angular/core'; templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) -export class AppComponent { +export class AppComponent implements OnInit { + + environment: Environment | undefined = undefined + + constructor(public environmentService: EnvironmentService) { } + + ngOnInit(): void { + this.environmentService.getEnvironment().subscribe((environment) => { + this.environment = environment; + }); + } getCurrentYear(): number { return new Date().getFullYear(); } + } diff --git a/src/app/flasher/flasher.component.html b/src/app/flasher/flasher.component.html index c7fcc1e..af27e34 100644 --- a/src/app/flasher/flasher.component.html +++ b/src/app/flasher/flasher.component.html @@ -22,7 +22,7 @@
{{flasherConsole}}
-
+
{{ partition.name }} {{progresses[i].progress}}% diff --git a/src/app/flasher/flasher.component.ts b/src/app/flasher/flasher.component.ts index af15388..a4ebab2 100644 --- a/src/app/flasher/flasher.component.ts +++ b/src/app/flasher/flasher.component.ts @@ -7,6 +7,7 @@ import { App } from '../models/app'; import { EspPortService } from '../services/esp-port.service'; import { PartitionProgress } from '../services/utils.service'; import { Subscription } from 'rxjs'; +import { AppVersion } from '../models/app-version'; @Component({ selector: 'app-flasher', @@ -28,6 +29,7 @@ export class FlasherComponent implements OnInit{ messageArea: string = ""; messageCount = 0; flasherConsole: string; + selectedVersion: AppVersion | undefined; progresses: PartitionProgress[] = new Array(); constructor(private route: ActivatedRoute, @@ -44,6 +46,7 @@ export class FlasherComponent implements OnInit{ console.log(this.device); this.appService.findById(this.appId).subscribe((app) => { this.app = app; + this.selectedVersion = this.app?.versions[0]; }); const portStateStreamSubscription = this.portService.portStateStream.subscribe(isConnected => { console.log("isConnected: ", isConnected); @@ -80,7 +83,7 @@ export class FlasherComponent implements OnInit{ this.messageArea = "" this.messageCount = 0; this.flasherConsole = "Ready"; - this.progresses = new Array(this.app?.partitions.length); + this.progresses = new Array(this.selectedVersion?.partitions.length); } connect() { @@ -118,7 +121,7 @@ export class FlasherComponent implements OnInit{ async flash() { console.log("Flashing"); this.resetState(); - if (this.app && this.app.partitions) { + if (this.app && this.selectedVersion?.partitions) { try { await this.portService.connect(); console.log("Connected"); @@ -128,7 +131,7 @@ export class FlasherComponent implements OnInit{ return; } console.log("Flashing"); - await this.portService.flash(this.app.partitions); + await this.portService.flash(this.selectedVersion.partitions); } else { console.log("No app selected"); } diff --git a/src/app/models/app-version.ts b/src/app/models/app-version.ts new file mode 100644 index 0000000..8eaa7ed --- /dev/null +++ b/src/app/models/app-version.ts @@ -0,0 +1,6 @@ +import { Partition } from "../services/utils.service"; + +export interface AppVersion { + name: string; + partitions: Partition[]; +} \ No newline at end of file diff --git a/src/app/models/app.ts b/src/app/models/app.ts index 84d3205..2dd89dd 100644 --- a/src/app/models/app.ts +++ b/src/app/models/app.ts @@ -1,4 +1,5 @@ import { Partition } from "../services/utils.service"; +import { AppVersion } from "./app-version"; export interface App { id: string; @@ -9,6 +10,6 @@ export interface App { appIcon: string; instructions: string; supportedDevices: string[]; - partitions: Partition[]; + versions: AppVersion[]; tags: string[]; } \ No newline at end of file diff --git a/src/app/models/environment.ts b/src/app/models/environment.ts new file mode 100644 index 0000000..41fa378 --- /dev/null +++ b/src/app/models/environment.ts @@ -0,0 +1,3 @@ +export interface Environment { + buildDate: string; +} \ No newline at end of file diff --git a/src/app/services/environment.service.ts b/src/app/services/environment.service.ts new file mode 100644 index 0000000..3aca826 --- /dev/null +++ b/src/app/services/environment.service.ts @@ -0,0 +1,20 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { App } from '../models/app'; +import { Observable, map } from 'rxjs'; +import { Environment } from '../models/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class EnvironmentService { + + constructor(public httpClient: HttpClient) { + + } + + getEnvironment(): Observable { + return this.httpClient.get('/assets/environment.json'); + } + +} diff --git a/src/assets/apps.json b/src/assets/apps.json index af8d4e9..791c264 100644 --- a/src/assets/apps.json +++ b/src/assets/apps.json @@ -9,12 +9,16 @@ "supportedDevices": [ "tp-pendrive-s3" ], - "partitions": [{ - "name": "Firmware", - "data": [], - "offset": 0, - "url": "./assets/apps/super-wifi-duck/app-firmware.bin" + "versions": [{ + "name": "1.0.0", + "partitions": [{ + "name": "Firmware", + "data": [], + "offset": 0, + "url": "./assets/apps/super-wifi-duck/app-firmware.bin" + }] }], + "tags": ["badusb", "keystroke-injection", "wifi-duck", "hid", "usb-rubber-ducky", "keyboard", "mouse"] }, { @@ -28,12 +32,16 @@ "supportedDevices": [ "tp-pendrive-s3" ], - "partitions": [{ - "name": "Firmware", - "data": [], - "offset": 0, - "url": "./assets/apps/circuitpython/circuit-python-bootloader.bin" + "versions": [{ + "name": "1.0.0", + "partitions": [{ + "name": "Firmware", + "data": [], + "offset": 0, + "url": "./assets/apps/circuitpython/circuit-python-bootloader.bin" + }] }], + "tags": ["circuit-python", "adafruit", "microcontroller", "embedded"] }, { @@ -47,22 +55,25 @@ "supportedDevices": [ "tp-pendrive-s3" ], - "partitions": [{ - "name": "Bootloader", - "data": [], - "offset": "0x0", - "url": "./assets/apps/esp32-u2f/bootloader.bin" - }, - { - "name": "Partition Table", - "data": [], - "offset": "0x8000", - "url": "./assets/apps/esp32-u2f/partition-table.bin"}, - { - "name": "Firmware", - "data": [], - "offset": "0x10000", - "url": "./assets/apps/esp32-u2f/esp32_u2f.bin" + "versions": [{ + "name": "1.0.0", + "partitions": [{ + "name": "Bootloader", + "data": [], + "offset": "0x0", + "url": "./assets/apps/esp32-u2f/bootloader.bin" + }, + { + "name": "Partition Table", + "data": [], + "offset": "0x8000", + "url": "./assets/apps/esp32-u2f/partition-table.bin"}, + { + "name": "Firmware", + "data": [], + "offset": "0x10000", + "url": "./assets/apps/esp32-u2f/esp32_u2f.bin" + }] }], "tags": ["fido2", "u2f", "security", "authentication", "webauthn"] }, @@ -77,22 +88,25 @@ "supportedDevices": [ "tp-pendrive-s3" ], - "partitions": [{ - "name": "Bootloader", - "data": [], - "offset": "0x0", - "url": "./assets/apps/wifi-dongle/bootloader.bin" - }, - { - "name": "Partition Table", - "data": [], - "offset": "0x8000", - "url": "./assets/apps/wifi-dongle/partition-table.bin"}, - { - "name": "Firmware", - "data": [], - "offset": "0x10000", - "url": "./assets/apps/wifi-dongle/usb_dongle.bin" + "versions": [{ + "name": "1.0.0", + "partitions": [{ + "name": "Bootloader", + "data": [], + "offset": "0x0", + "url": "./assets/apps/wifi-dongle/bootloader.bin" + }, + { + "name": "Partition Table", + "data": [], + "offset": "0x8000", + "url": "./assets/apps/wifi-dongle/partition-table.bin"}, + { + "name": "Firmware", + "data": [], + "offset": "0x10000", + "url": "./assets/apps/wifi-dongle/usb_dongle.bin" + }] }], "tags": ["network", "wifi", "wifi-dongle"] }, @@ -106,6 +120,10 @@ "supportedDevices": [ "tp-default-device" ], - "partitions": [] + "versions": [{ + "name": "1.0.0", + "partitions": [] + }] + } ] \ No newline at end of file diff --git a/src/assets/buildDate.json b/src/assets/buildDate.json deleted file mode 100644 index 5ffddaf..0000000 --- a/src/assets/buildDate.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "year": "test" -} \ No newline at end of file diff --git a/src/assets/environment.json b/src/assets/environment.json new file mode 100644 index 0000000..ea6ac6a --- /dev/null +++ b/src/assets/environment.json @@ -0,0 +1,3 @@ +{ + "buildDate": "TEST" +} \ No newline at end of file diff --git a/updateEnvironmentInfo.js b/updateEnvironmentInfo.js new file mode 100644 index 0000000..920eadc --- /dev/null +++ b/updateEnvironmentInfo.js @@ -0,0 +1,10 @@ +const { writeFileSync } = require('fs') +const { join } = require('path') + +const ENV_PATH = join(__dirname, 'src/assets/environment.json'); + +const environment = { + buildDate: new Date() +} + +writeFileSync(ENV_PATH, JSON.stringify(environment, null, 2)); \ No newline at end of file