From 1982790b2684755765ecd5d7d48926c93dc35175 Mon Sep 17 00:00:00 2001 From: trivernis Date: Mon, 1 Nov 2021 21:42:22 +0100 Subject: [PATCH] Add starting of local daemon for repositories with no daemon running Signed-off-by: trivernis --- mediarepo-ui/src-tauri/Cargo.lock | 13 ++++++- mediarepo-ui/src-tauri/Cargo.toml | 2 +- mediarepo-ui/src/app/models/Repository.ts | 2 +- .../repo-form/repo-form.component.html | 3 ++ .../repo-form/repo-form.component.scss | 6 ++++ .../repo-form/repo-form.component.ts | 9 +++++ .../repository-card.component.html | 11 ++++-- .../repository-card.component.scss | 9 +++++ .../repository-card.component.ts | 25 +++++++++++--- .../services/repository/repository.service.ts | 34 +++++++++++++++++++ 10 files changed, 104 insertions(+), 10 deletions(-) diff --git a/mediarepo-ui/src-tauri/Cargo.lock b/mediarepo-ui/src-tauri/Cargo.lock index 741ce03..59ae7d9 100644 --- a/mediarepo-ui/src-tauri/Cargo.lock +++ b/mediarepo-ui/src-tauri/Cargo.lock @@ -1581,7 +1581,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "mediarepo-api" version = "0.1.0" -source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=0b51564a518f4d7301107a83bd74b747b775b4f8#0b51564a518f4d7301107a83bd74b747b775b4f8" +source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=266b1e7d6e840091b322818517a358fee84b939e#266b1e7d6e840091b322818517a358fee84b939e" dependencies = [ "async-trait", "chrono", @@ -2726,6 +2726,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + [[package]] name = "siphasher" version = "0.3.7" @@ -3199,7 +3208,9 @@ dependencies = [ "memchr", "mio", "num_cpus", + "once_cell", "pin-project-lite", + "signal-hook-registry", "winapi", ] diff --git a/mediarepo-ui/src-tauri/Cargo.toml b/mediarepo-ui/src-tauri/Cargo.toml index 8a9eb52..527c16d 100644 --- a/mediarepo-ui/src-tauri/Cargo.toml +++ b/mediarepo-ui/src-tauri/Cargo.toml @@ -30,7 +30,7 @@ features = ["env-filter"] [dependencies.mediarepo-api] git = "https://github.com/Trivernis/mediarepo-api.git" -rev = "0b51564a518f4d7301107a83bd74b747b775b4f8" +rev = "266b1e7d6e840091b322818517a358fee84b939e" features = ["tauri-plugin"] [features] diff --git a/mediarepo-ui/src/app/models/Repository.ts b/mediarepo-ui/src/app/models/Repository.ts index acdce38..4eb972c 100644 --- a/mediarepo-ui/src/app/models/Repository.ts +++ b/mediarepo-ui/src/app/models/Repository.ts @@ -2,6 +2,6 @@ export class Repository { constructor( public name: string, public address: string, - public secret: string + public path: string | undefined ) {} } diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.html b/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.html index fbef0d7..aefbfb9 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.html +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.html @@ -5,6 +5,9 @@ Path + diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.scss b/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.scss index 05a76f3..04bf1a3 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.scss +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.scss @@ -9,3 +9,9 @@ mat-form-field, button { margin: 0.2em } + +.button-folder-select { + position: absolute; + top: -24px; + right: 0; +} diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.ts b/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.ts index 9778447..b2009b9 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.ts +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/repo-form/repo-form.component.ts @@ -3,6 +3,7 @@ import {FormControl, FormGroup, Validators} from "@angular/forms"; import {RepositoryService} from "../../../../services/repository/repository.service"; import {MatSnackBar} from "@angular/material/snack-bar"; import {ErrorBrokerService} from "../../../../services/error-broker/error-broker.service"; +import {dialog} from "@tauri-apps/api"; @Component({ selector: 'app-repo-form', @@ -30,4 +31,12 @@ export class RepoFormComponent implements OnInit { this.errorBroker.showError(err); } } + + public async openFolderDialog($event: MouseEvent): Promise { + const path = await dialog.open({ + directory: true, + multiple: false, + }); + this.repoForm.controls.path.setValue(path); + } } diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.html b/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.html index 1c37d9e..25a7e20 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.html +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.html @@ -1,7 +1,12 @@ - {{repository?.name}} - {{repository?.address}} + {{repository.name}} + +

{{repository.path!}}

+

{{repository.address}}

+
Running
+
- + +
diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.scss b/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.scss index d3eb924..b7020e6 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.scss +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.scss @@ -1 +1,10 @@ @import "../../../../../styles"; + +.repository-path { + color: lightgray; +} + +.repository-address { + color: lightgray; + font-family: "Fira Code Light", Monospaced, Consolas, monospace; +} diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.ts b/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.ts index ee92528..b2f37ef 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.ts +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/repository-card/repository-card.component.ts @@ -9,19 +9,36 @@ import {ErrorBrokerService} from "../../../../services/error-broker/error-broker templateUrl: './repository-card.component.html', styleUrls: ['./repository-card.component.scss'] }) -export class RepositoryCardComponent { +export class RepositoryCardComponent implements OnInit { - @Input() repository?: Repository; + @Input() repository!: Repository; + + public daemonRunning: boolean = false; constructor(private repoService: RepositoryService, private router: Router, private errorBroker: ErrorBrokerService) {} + public async ngOnInit() { + this.daemonRunning = await this.repoService.checkDaemonRunning(this.repository.address); + } + + async startDaemonAndSelectRepository() { + try { + await this.repoService.startDaemon(this.repository.path!); + this.daemonRunning = true; + await new Promise((res, _) => { + setTimeout(res, 2000) // wait for the daemon to start + }); + await this.selectRepository(); + } catch (err) { + this.errorBroker.showError(err); + } + } + async selectRepository() { - if (this.repository) { try { await this.repoService.setRepository(this.repository); } catch(err) { this.errorBroker.showError(err); } - } } } diff --git a/mediarepo-ui/src/app/services/repository/repository.service.ts b/mediarepo-ui/src/app/services/repository/repository.service.ts index 16f44c8..b061e65 100644 --- a/mediarepo-ui/src/app/services/repository/repository.service.ts +++ b/mediarepo-ui/src/app/services/repository/repository.service.ts @@ -18,6 +18,7 @@ export class RepositoryService { this.registerListener() } + /// Registers the info listener async registerListener() { await listen("info", (event: { payload: Info }) => { const message = `Connected to ${event.payload.name}, Version: ${event.payload.version}`; @@ -25,6 +26,10 @@ export class RepositoryService { }); } + /** + * Loads all repositories stored in the settings + * @returns {Promise} + */ public async loadRepositories() { let active_repo = await invoke("plugin:mediarepo|get_active_repository"); this.selectedRepository.next(active_repo); @@ -33,14 +38,43 @@ export class RepositoryService { this.repositories.next(repos); } + /** + * Sets the active repository + * @param {Repository} repo + * @returns {Promise} + */ public async setRepository(repo: Repository) { await invoke("plugin:mediarepo|select_repository", {name: repo.name}); this.selectedRepository.next(repo); await this.dataloaderService.loadData(); } + /** + * Adds a respository to the repository list in the settings + * @param {string} name + * @param {string} path + * @returns {Promise} + */ public async addRepository(name: string, path: string) { let repos = await invoke("plugin:mediarepo|add_repository", {name, path}); this.repositories.next(repos); } + + /** + * Checks if a daemon is running for the specified address + * @param {string} address + * @returns {Promise} + */ + public async checkDaemonRunning(address: string): Promise { + return await invoke("plugin:mediarepo|check_daemon_running", {address}); + } + + /** + * Starts a daemon for the given repository path + * @param {string} repoPath + * @returns {Promise} + */ + public async startDaemon(repoPath: string): Promise { + await invoke("plugin:mediarepo|start_daemon", {repoPath}) + } }