Skip to content

Commit

Permalink
Merge pull request #19 from freekode/fix-static-ui
Browse files Browse the repository at this point in the history
Fix static content serving
  • Loading branch information
freekode authored Feb 21, 2024
2 parents 277b27d + ed412de commit 39c3daf
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 38 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
[![release](https://img.shields.io/github/release/freekode/tp2intervals)](https://github.com/freekode/tp2intervals/releases/latest)

# Third Party to Intervals.icu
Sync workouts and activities between TrainingPeaks and Intervals.icu.
App to sync workouts and activities between TrainingPeaks and Intervals.icu.

Plan workouts for today and tomorrow from Intervals to TrainingPeaks.
* Sync planned workouts between Intervals.icu and TrainingPeaks for today and tomorrow (free TP account)
* Copy planned workouts for date range from TrainingPeaks to Intervals.icu Training Plan

Executables for MacOS (DMG), Windows (EXE installer), Linux (AppImage) are available on [latest release](https://github.com/freekode/tp2intervals/releases/latest) page
Executables for MacOS (DMG), Windows (EXE installer), Linux (AppImage) are available for download [here](https://github.com/freekode/tp2intervals/releases/latest)

**Only for educational purposes**

Expand Down
5 changes: 5 additions & 0 deletions boot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
}

group = "org.freekode"
version = "0.3.3"

java {
sourceCompatibility = JavaVersion.VERSION_21
Expand Down Expand Up @@ -64,3 +65,7 @@ tasks.withType<KotlinCompile> {
tasks.withType<Test> {
useJUnitPlatform()
}

tasks.bootJar {
archiveFileName.set("${project.name}.jar")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package org.freekode.tp2intervals.config

import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.CorsRegistry
import org.springframework.web.servlet.config.annotation.EnableWebMvc
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer


@Configuration
@EnableWebMvc
class WebConfig : WebMvcConfigurer {
override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/**")
registry
.addMapping("/api/**")
.allowedMethods("GET", "POST", "PUT")
}
}
11 changes: 11 additions & 0 deletions boot/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ spring:
jpa:
open-in-view: false
database-platform: org.hibernate.community.dialect.SQLiteDialect

management:
info:
git:
mode: full
endpoints:
web:
exposure:
include: 'health,info'
cors:
allowed-origins: '*'
6 changes: 2 additions & 4 deletions devops/build-jar.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/bin/bash

cd ./ui
npm ci
npm run build
npm ci --prefix ui
npm run build --prefix ui

cd ../
cp -r ui/dist/ui/browser boot/src/main/resources/static

cd ./boot
Expand Down
2 changes: 1 addition & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tp2intervals",
"productName": "tp2intervals",
"version": "0.3.2",
"version": "0.3.3",
"description": "Third Party synchronization with Intervals.icu",
"keywords": [
"trainingpeaks",
Expand Down
14 changes: 8 additions & 6 deletions electron/src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { contextBridge, ipcRenderer } from 'electron';
import { contextBridge } from 'electron';
import {
appVersionSupplier,
bootAddressSupplier,
Expand All @@ -7,8 +7,10 @@ import {
subscriptions
} from "./renderer";

contextBridge.exposeInMainWorld('bootAddress', bootAddressSupplier())
contextBridge.exposeInMainWorld('bootHealthy', bootHealthySupplier());
contextBridge.exposeInMainWorld('appVersion', appVersionSupplier());
contextBridge.exposeInMainWorld('appPlatform', platformSupplier());
contextBridge.exposeInMainWorld('subscriptions', subscriptions);
contextBridge.exposeInMainWorld('electron', {
bootAddress: bootAddressSupplier(),
bootHealthy: bootHealthySupplier(),
appVersion: appVersionSupplier(),
appPlatform: platformSupplier(),
subscriptions: subscriptions,
})
4 changes: 2 additions & 2 deletions ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/favicon.png",
"src/assets"
],
"styles": [
Expand Down Expand Up @@ -88,7 +88,7 @@
"tsConfig": "tsconfig.spec.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/favicon.png",
"src/assets"
],
"styles": [
Expand Down
11 changes: 8 additions & 3 deletions ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { MatCardModule } from "@angular/material/card";
import { MatIconModule } from "@angular/material/icon";
import { MatToolbarModule } from "@angular/material/toolbar";
import { MatButtonModule } from "@angular/material/button";
import { UpdateService } from "app/update.service";
import { UpdateService } from "infrastructure/update.service";
import { EnvironmentService } from "infrastructure/environment.service";


@Component({
Expand All @@ -16,14 +17,18 @@ import { UpdateService } from "app/update.service";
styleUrl: './app.component.scss'
})
export class AppComponent implements OnInit {
appVersion = window.appVersion || 'static'
appVersion: string

constructor(
private updateService: UpdateService
private updateService: UpdateService,
private environmentService: EnvironmentService
) {
}

ngOnInit(): void {
this.updateService.init()
this.environmentService.getVersion().subscribe(version => {
this.appVersion = version
})
}
}
1 change: 0 additions & 1 deletion ui/src/assets/loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta charset="utf-8">
<title>Loading</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="../favicon.ico">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style type="text/css">
Expand Down
Binary file removed ui/src/favicon.ico
Binary file not shown.
Binary file added ui/src/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ui/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>tp2intervals</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="icon" type="image/x-icon" href="favicon.png">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
Expand Down
27 changes: 27 additions & 0 deletions ui/src/infrastructure/environment.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import { HttpClient } from "@angular/common/http";
import { map, Observable, of } from 'rxjs';


@Injectable({
providedIn: 'root'
})
export class EnvironmentService {

constructor(private httpClient: HttpClient) {
}

getBootAddress() {
return window.electron?.bootAddress || ''
}

getVersion(): Observable<string> {
if (window.electron) {
return of(window.electron.appVersion)
} else {
return this.httpClient.get(`/actuator/info`).pipe(
map((response: any) => response.build.version)
)
}
}
}
9 changes: 6 additions & 3 deletions ui/src/infrastructure/http.interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { HttpHandlerFn, HttpInterceptorFn, HttpRequest } from "@angular/common/h
import { inject } from "@angular/core";
import { catchError, throwError } from "rxjs";
import { NotificationService } from "infrastructure/notification.service";

let host = window.bootAddress || ''
import { EnvironmentService } from "infrastructure/environment.service";

export const httpErrorInterceptor: HttpInterceptorFn = (
req: HttpRequest<any>,
Expand All @@ -13,7 +12,8 @@ export const httpErrorInterceptor: HttpInterceptorFn = (

return next(req).pipe(
catchError((err) => {
notificationService.error(err.error.error)
let errorMessage = err.error.error ? err.error.error : err.message
notificationService.error(errorMessage)
return throwError(() => err)
})
);
Expand All @@ -23,6 +23,9 @@ export const httpHostInterceptor: HttpInterceptorFn = (
req: HttpRequest<any>,
next: HttpHandlerFn,
) => {
let environmentService = inject(EnvironmentService)
let host = environmentService.getBootAddress()

const apiReq = req.clone({url: `${host}/${req.url.replace(/^\/|\/$/g, '')}`});
return next(apiReq);
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ export class UpdateService {
}

init() {
window.subscriptions.appUpdateAvailable(updateInfo => {
if (!window.electron) {
console.log("Non-electron environment")
return
}

window.electron.subscriptions.appUpdateAvailable(updateInfo => {
console.log('Update available', updateInfo)
if (window.appPlatform === 'darwin') {
if (window.electron.appPlatform === 'darwin') {
this.notificationService.success(`New version ${updateInfo.version} available for download.\nCheck GitHub page`)
}
})

window.subscriptions.appUpdateDownloaded(updateInfo => {
window.electron.subscriptions.appUpdateDownloaded(updateInfo => {
console.log('Update downloaded', updateInfo)
this.notificationService.success(`New version ${updateInfo.version} will be automatically installed.`)
})
Expand Down
4 changes: 4 additions & 0 deletions ui/src/proxy.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"/api": {
"target": "http://localhost:8080",
"secure": false
},
"/actuator": {
"target": "http://localhost:8080",
"secure": false
}
}
18 changes: 10 additions & 8 deletions ui/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
declare global {
interface Window {
bootAddress: string;
bootHealthy: () => boolean;
appVersion: string;
appPlatform: string;
subscriptions: {
'appUpdateAvailable',
'appUpdateDownloaded'
};
electron: {
bootAddress: string;
bootHealthy: () => boolean;
appVersion: string;
appPlatform: string;
subscriptions: {
'appUpdateAvailable',
'appUpdateDownloaded'
};
}
}
}

Expand Down

0 comments on commit 39c3daf

Please sign in to comment.