Compare commits

...

3 Commits

Author SHA1 Message Date
Jovan Krunić
bb1f596bfc fix: enable starting the app without backend
Closes #223
2024-09-30 11:03:53 +00:00
0c49fd8c34 refactor: update nix dependencies 2024-09-30 13:00:59 +02:00
Thea Schöbl
ce5016a992 fix: text of the feedback form not fully visible
Closes #227
2024-09-18 09:53:50 +00:00
4 changed files with 138 additions and 95 deletions

142
flake.nix
View File

@@ -4,68 +4,86 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { outputs =
self, {
nixpkgs, self,
flake-utils, nixpkgs,
}: let flake-utils,
aapt2buildToolsVersion = "33.0.2"; }:
in let
flake-utils.lib.eachDefaultSystem (system: let aapt2buildToolsVersion = "33.0.2";
pkgs = import nixpkgs { in
inherit system; flake-utils.lib.eachDefaultSystem (
overlays = [ system:
(final: prev: rec { let
fontMin = prev.python311.withPackages (ps: with ps; [brotli fonttools] ++ (with fonttools.optional-dependencies; [woff])); pkgs = import nixpkgs {
android = prev.androidenv.composeAndroidPackages { inherit system;
buildToolsVersions = ["30.0.3" aapt2buildToolsVersion]; overlays = [
platformVersions = ["33"]; (final: prev: rec {
}; fontMin = prev.python311.withPackages (
cypress = prev.cypress.overrideAttrs (cyPrev: rec { ps:
version = "13.2.0"; with ps;
src = prev.fetchzip { [
url = "https://cdn.cypress.io/desktop/${version}/linux-x64/cypress.zip"; brotli
hash = "sha256-9o0nprGcJhudS1LNm+T7Vf0Dwd1RBauYKI+w1FBQ3ZM="; fonttools
]
++ (with fonttools.optional-dependencies; [ woff ])
);
android = prev.androidenv.composeAndroidPackages {
buildToolsVersions = [
"34.0.0"
aapt2buildToolsVersion
];
platformVersions = [ "34" ];
}; };
}); cypress = prev.cypress.overrideAttrs (cyPrev: rec {
nodejs = prev.nodejs_18; version = "13.2.0";
}) src = prev.fetchzip {
]; url = "https://cdn.cypress.io/desktop/${version}/linux-x64/cypress.zip";
config = { hash = "sha256-9o0nprGcJhudS1LNm+T7Vf0Dwd1RBauYKI+w1FBQ3ZM=";
allowUnfree = true; };
android_sdk.accept_license = true; });
nodejs = prev.nodejs_18;
corepack = prev.corepack_18;
})
];
config = {
allowUnfree = true;
android_sdk.accept_license = true;
};
}; };
}; androidFhs = pkgs.buildFHSUserEnv {
androidFhs = pkgs.buildFHSUserEnv { name = "android-env";
name = "android-env"; targetPkgs = pkgs: with pkgs; [ ];
targetPkgs = pkgs: with pkgs; []; runScript = "bash";
runScript = "bash"; profile = ''
profile = '' export ALLOW_NINJA_ENV=true
export ALLOW_NINJA_ENV=true export USE_CCACHE=1
export USE_CCACHE=1 export LD_LIBRARY_PATH=/usr/lib:/usr/lib32
export LD_LIBRARY_PATH=/usr/lib:/usr/lib32 '';
''; };
}; in
in { {
devShell = pkgs.mkShell rec { devShell = pkgs.mkShell rec {
nativeBuildInputs = [androidFhs]; nativeBuildInputs = [ androidFhs ];
buildInputs = with pkgs; [ buildInputs = with pkgs; [
nodejs nodejs
corepack corepack
# tools # tools
curl curl
jq jq
fontMin fontMin
cypress cypress
# android # android
jdk17 jdk17
android.androidsdk android.androidsdk
]; ];
ANDROID_JAVA_HOME = "${pkgs.jdk.home}"; ANDROID_JAVA_HOME = "${pkgs.jdk.home}";
ANDROID_SDK_ROOT = "${pkgs.android.androidsdk}/libexec/android-sdk"; ANDROID_SDK_ROOT = "${pkgs.android.androidsdk}/libexec/android-sdk";
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${aapt2buildToolsVersion}/aapt2"; GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${aapt2buildToolsVersion}/aapt2";
CYPRESS_INSTALL_BINARY = "0"; CYPRESS_INSTALL_BINARY = "0";
CYPRESS_RUN_BINARY = "${pkgs.cypress}/bin/Cypress"; CYPRESS_RUN_BINARY = "${pkgs.cypress}/bin/Cypress";
}; };
}); }
);
} }

View File

@@ -67,7 +67,8 @@ describe('ConfigProvider', () => {
it('should fetch app configuration', async () => { it('should fetch app configuration', async () => {
spyOn(configProvider.client, 'handshake').and.returnValue(Promise.resolve(sampleIndexResponse)); spyOn(configProvider.client, 'handshake').and.returnValue(Promise.resolve(sampleIndexResponse));
const result = await configProvider.fetch(); await configProvider.fetch();
const result = configProvider.config;
expect(result).toEqual(sampleIndexResponse); expect(result).toEqual(sampleIndexResponse);
}); });
@@ -110,7 +111,7 @@ describe('ConfigProvider', () => {
expect(storageProviderSpy.has).toHaveBeenCalled(); expect(storageProviderSpy.has).toHaveBeenCalled();
expect(storageProviderSpy.get).toHaveBeenCalledTimes(0); expect(storageProviderSpy.get).toHaveBeenCalledTimes(0);
expect(configProvider.client.handshake).toHaveBeenCalled(); expect(configProvider.client.handshake).toHaveBeenCalled();
expect(await configProvider.getValue('name')).toEqual(sampleIndexResponse.app.name); expect(configProvider.getValue('name')).toEqual(sampleIndexResponse.app.name);
}); });
it('should throw error on failed initialisation', async () => { it('should throw error on failed initialisation', async () => {
@@ -192,4 +193,31 @@ describe('ConfigProvider', () => {
expect(configProvider.getValue('name')).toEqual(sampleIndexResponse.app.name); expect(configProvider.getValue('name')).toEqual(sampleIndexResponse.app.name);
}); });
it('should fetch new config from remote on init', async () => {
storageProviderSpy.has.and.returnValue(Promise.resolve(true));
storageProviderSpy.get.and.returnValue(Promise.resolve(sampleIndexResponse));
spyOn(configProvider, 'fetch');
await configProvider.init();
expect(configProvider.fetch).toHaveBeenCalled();
});
it('should update the local config with the one from remote', async () => {
storageProviderSpy.has.and.returnValue(Promise.resolve(true));
storageProviderSpy.get.and.returnValue(Promise.resolve(sampleIndexResponse));
const newConfig = structuredClone(sampleIndexResponse);
newConfig.app.name = 'New app name';
spyOn(configProvider.client, 'handshake').and.returnValue(Promise.resolve(newConfig));
await configProvider.init();
// Validate that the initial configuration is loaded
expect(configProvider.getValue('name')).toEqual(sampleIndexResponse.app.name);
// Fetch the new configuration from the remote
await configProvider.fetch();
// Validate that the new configuration is now set
expect(configProvider.getValue('name')).toEqual(newConfig.app.name);
});
}); });

View File

@@ -83,17 +83,20 @@ export class ConfigProvider {
/** /**
* Fetches configuration from backend * Fetches configuration from backend
*/ */
async fetch(): Promise<SCIndexResponse> { async fetch(): Promise<void> {
try { try {
const isOffline = await firstValueFrom(this.internetConnectionService.offline$); const isOffline = await firstValueFrom(this.internetConnectionService.offline$);
if (isOffline) { if (isOffline) {
throw new Error('Device is offline.'); throw new Error('Device is offline.');
} else { } else {
return await this.client.handshake(this.scVersion); const fetchedConfig: SCIndexResponse = await this.client.handshake(this.scVersion);
await this.set(fetchedConfig);
this.logger.log(`Configuration updated from remote`);
} }
} catch (error) { } catch (error) {
const error_ = error instanceof Error ? new ConfigFetchError(error.message) : new ConfigFetchError(); const error_ = error instanceof Error ? new ConfigFetchError(error.message) : new ConfigFetchError();
throw error_; this.logger.warn(`Failed to fetch remote configuration:`, error_);
throw error_; // Rethrow the error to handle it in init()
} }
} }
@@ -121,40 +124,33 @@ export class ConfigProvider {
/** /**
* Initialises the ConfigProvider * Initialises the ConfigProvider
* @throws ConfigInitError if no configuration could be loaded. * @throws ConfigInitError if no configuration could be loaded both locally and remote.
* @throws WrongConfigVersionInStorage if fetch failed and saved config has wrong SCVersion
*/ */
async init(): Promise<void> { async init(): Promise<void> {
let loadError;
let fetchError;
// load saved configuration
try { try {
// Attempt to load the configuration from local storage
this.config = await this.loadLocal(); this.config = await this.loadLocal();
this.firstSession = false; this.firstSession = false;
this.logger.log(`initialised configuration from storage`); this.logger.log(`initialised configuration from storage`);
// Check if the stored configuration has the correct version
if (this.config.backend.SCVersion.split('.')[0] !== this.scVersion.split('.')[0]) { if (this.config.backend.SCVersion.split('.')[0] !== this.scVersion.split('.')[0]) {
loadError = new WrongConfigVersionInStorage(this.scVersion, this.config.backend.SCVersion); throw new WrongConfigVersionInStorage(this.scVersion, this.config.backend.SCVersion);
} }
} catch (error) {
loadError = error; // Fetch the remote configuration in a non-blocking manner
} void this.fetch();
// fetch remote configuration from backend } catch (loadError) {
try {
const fetchedConfig: SCIndexResponse = await this.fetch();
await this.set(fetchedConfig);
this.logger.log(`initialised configuration from remote`);
} catch (error) {
fetchError = error;
}
// check for occurred errors and throw them
if (loadError !== undefined && fetchError !== undefined) {
throw new ConfigInitError();
}
if (loadError !== undefined) {
this.logger.warn(loadError); this.logger.warn(loadError);
}
if (fetchError !== undefined) { try {
this.logger.warn(fetchError); // If local loading fails, immediately try to fetch the configuration from remote
await this.fetch();
} catch (fetchError) {
this.logger.warn(`Failed to fetch remote configuration:`, fetchError);
// If both local loading and remote fetching fail, throw ConfigInitError
throw new ConfigInitError();
}
} }
} }

View File

@@ -80,13 +80,12 @@
</ion-item> </ion-item>
<ion-item> <ion-item>
<ion-checkbox <ion-checkbox
class="ion-text-wrap"
color="primary" color="primary"
label-placement="end" label-placement="end"
justify="start" justify="start"
[(ngModel)]="termsAgree" [(ngModel)]="termsAgree"
name="termsAgree" name="termsAgree"
>{{ 'feedback.form.termsAgree.0' | translate }}</ion-checkbox ><span class="ion-text-wrap">{{ 'feedback.form.termsAgree.0' | translate }}</span></ion-checkbox
> >
</ion-item> </ion-item>
<ion-item lines="none"> <ion-item lines="none">
@@ -104,7 +103,9 @@
justify="start" justify="start"
[(ngModel)]="protocolDataAgree" [(ngModel)]="protocolDataAgree"
name="protocolDataAgree" name="protocolDataAgree"
>{{ 'feedback.form.protocolDataAgree' | translate }}</ion-checkbox ><span class="ion-text-wrap">{{
'feedback.form.protocolDataAgree' | translate
}}</span></ion-checkbox
> >
</ion-item> </ion-item>
<ion-card> <ion-card>