Add starting of local daemon for repositories with no daemon running

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent d0b832fc89
commit 1982790b26

@ -1581,7 +1581,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]] [[package]]
name = "mediarepo-api" name = "mediarepo-api"
version = "0.1.0" 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 = [ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",
@ -2726,6 +2726,15 @@ dependencies = [
"winapi", "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]] [[package]]
name = "siphasher" name = "siphasher"
version = "0.3.7" version = "0.3.7"
@ -3199,7 +3208,9 @@ dependencies = [
"memchr", "memchr",
"mio", "mio",
"num_cpus", "num_cpus",
"once_cell",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry",
"winapi", "winapi",
] ]

@ -30,7 +30,7 @@ features = ["env-filter"]
[dependencies.mediarepo-api] [dependencies.mediarepo-api]
git = "https://github.com/Trivernis/mediarepo-api.git" git = "https://github.com/Trivernis/mediarepo-api.git"
rev = "0b51564a518f4d7301107a83bd74b747b775b4f8" rev = "266b1e7d6e840091b322818517a358fee84b939e"
features = ["tauri-plugin"] features = ["tauri-plugin"]
[features] [features]

@ -2,6 +2,6 @@ export class Repository {
constructor( constructor(
public name: string, public name: string,
public address: string, public address: string,
public secret: string public path: string | undefined
) {} ) {}
} }

@ -5,6 +5,9 @@
</mat-form-field> </mat-form-field>
<mat-form-field appearance="fill" id="path-input"> <mat-form-field appearance="fill" id="path-input">
<mat-label>Path</mat-label> <mat-label>Path</mat-label>
<button class="button-folder-select" mat-button (click)="this.openFolderDialog($event)">
<mat-icon>folder</mat-icon>
</button>
<input type="text" matInput required formControlName="path"> <input type="text" matInput required formControlName="path">
</mat-form-field> </mat-form-field>
<button mat-flat-button color="primary" id="add-button" [disabled]="!repoForm.valid">Add</button> <button mat-flat-button color="primary" id="add-button" [disabled]="!repoForm.valid">Add</button>

@ -9,3 +9,9 @@
mat-form-field, button { mat-form-field, button {
margin: 0.2em margin: 0.2em
} }
.button-folder-select {
position: absolute;
top: -24px;
right: 0;
}

@ -3,6 +3,7 @@ import {FormControl, FormGroup, Validators} from "@angular/forms";
import {RepositoryService} from "../../../../services/repository/repository.service"; import {RepositoryService} from "../../../../services/repository/repository.service";
import {MatSnackBar} from "@angular/material/snack-bar"; import {MatSnackBar} from "@angular/material/snack-bar";
import {ErrorBrokerService} from "../../../../services/error-broker/error-broker.service"; import {ErrorBrokerService} from "../../../../services/error-broker/error-broker.service";
import {dialog} from "@tauri-apps/api";
@Component({ @Component({
selector: 'app-repo-form', selector: 'app-repo-form',
@ -30,4 +31,12 @@ export class RepoFormComponent implements OnInit {
this.errorBroker.showError(err); this.errorBroker.showError(err);
} }
} }
public async openFolderDialog($event: MouseEvent): Promise<void> {
const path = await dialog.open({
directory: true,
multiple: false,
});
this.repoForm.controls.path.setValue(path);
}
} }

@ -1,7 +1,12 @@
<mat-card> <mat-card>
<mat-card-title>{{repository?.name}}</mat-card-title> <mat-card-title>{{repository.name}}</mat-card-title>
<mat-card-content>{{repository?.address}}</mat-card-content> <mat-card-content>
<p class="repository-path" *ngIf="repository.path">{{repository.path!}}</p>
<p class="repository-address" *ngIf="!repository.path">{{repository.address}}</p>
<div *ngIf="daemonRunning" class="daemon-running-info">Running</div>
</mat-card-content>
<mat-action-list> <mat-action-list>
<button mat-flat-button color="primary" (click)="selectRepository()">Open</button> <button *ngIf="!daemonRunning" mat-flat-button color="primary" (click)="startDaemonAndSelectRepository()">Open</button>
<button *ngIf="daemonRunning" mat-flat-button color="primary" (click)="selectRepository()">Connect</button>
</mat-action-list> </mat-action-list>
</mat-card> </mat-card>

@ -1 +1,10 @@
@import "../../../../../styles"; @import "../../../../../styles";
.repository-path {
color: lightgray;
}
.repository-address {
color: lightgray;
font-family: "Fira Code Light", Monospaced, Consolas, monospace;
}

@ -9,14 +9,32 @@ import {ErrorBrokerService} from "../../../../services/error-broker/error-broker
templateUrl: './repository-card.component.html', templateUrl: './repository-card.component.html',
styleUrls: ['./repository-card.component.scss'] 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) {} 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() { async selectRepository() {
if (this.repository) {
try { try {
await this.repoService.setRepository(this.repository); await this.repoService.setRepository(this.repository);
} catch(err) { } catch(err) {
@ -24,4 +42,3 @@ export class RepositoryCardComponent {
} }
} }
} }
}

@ -18,6 +18,7 @@ export class RepositoryService {
this.registerListener() this.registerListener()
} }
/// Registers the info listener
async registerListener() { async registerListener() {
await listen("info", (event: { payload: Info }) => { await listen("info", (event: { payload: Info }) => {
const message = `Connected to ${event.payload.name}, Version: ${event.payload.version}`; 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<void>}
*/
public async loadRepositories() { public async loadRepositories() {
let active_repo = await invoke<Repository | undefined>("plugin:mediarepo|get_active_repository"); let active_repo = await invoke<Repository | undefined>("plugin:mediarepo|get_active_repository");
this.selectedRepository.next(active_repo); this.selectedRepository.next(active_repo);
@ -33,14 +38,43 @@ export class RepositoryService {
this.repositories.next(repos); this.repositories.next(repos);
} }
/**
* Sets the active repository
* @param {Repository} repo
* @returns {Promise<void>}
*/
public async setRepository(repo: Repository) { public async setRepository(repo: Repository) {
await invoke("plugin:mediarepo|select_repository", {name: repo.name}); await invoke("plugin:mediarepo|select_repository", {name: repo.name});
this.selectedRepository.next(repo); this.selectedRepository.next(repo);
await this.dataloaderService.loadData(); await this.dataloaderService.loadData();
} }
/**
* Adds a respository to the repository list in the settings
* @param {string} name
* @param {string} path
* @returns {Promise<void>}
*/
public async addRepository(name: string, path: string) { public async addRepository(name: string, path: string) {
let repos = await invoke<Repository[]>("plugin:mediarepo|add_repository", {name, path}); let repos = await invoke<Repository[]>("plugin:mediarepo|add_repository", {name, path});
this.repositories.next(repos); this.repositories.next(repos);
} }
/**
* Checks if a daemon is running for the specified address
* @param {string} address
* @returns {Promise<boolean>}
*/
public async checkDaemonRunning(address: string): Promise<boolean> {
return await invoke<boolean>("plugin:mediarepo|check_daemon_running", {address});
}
/**
* Starts a daemon for the given repository path
* @param {string} repoPath
* @returns {Promise<void>}
*/
public async startDaemon(repoPath: string): Promise<void> {
await invoke("plugin:mediarepo|start_daemon", {repoPath})
}
} }

Loading…
Cancel
Save