Skip to content

Commit

Permalink
start with only custom sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredolx committed Oct 25, 2024
1 parent cb012b9 commit 4df9078
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 22 deletions.
11 changes: 9 additions & 2 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pub fn run() {
add_custom_channel,
get_channel_headers,
edit_custom_channel,
delete_custom_channel
delete_custom_channel,
add_custom_source
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down Expand Up @@ -165,4 +166,10 @@ fn delete_custom_channel(id: i64) -> Result<(), String> {
#[tauri::command(async)]
fn get_channel_headers(id: i64) -> Result<Option<ChannelHttpHeaders>, String> {
sql::get_channel_headers_by_id(id).map_err(map_err_frontend)
}
}

#[tauri::command(async)]
fn add_custom_source() -> Result<(), String> {
sql::create_or_find_source_by_name(&mut sql::get_custom_source()).map_err(map_err_frontend)?;
Ok(())
}
10 changes: 10 additions & 0 deletions src/app/setup/setup.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ button .anim-svg {
button:hover .anim-svg {
transform: scale(125%);
}

button .pen {
width: 1.5rem;
height: 1.5rem;
transition: transform 0.3s ease;
}

button:hover .pen {
transform: scale(125%);
}
63 changes: 43 additions & 20 deletions src/app/setup/setup.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<svg *ngIf="memory.AddingAdditionalSource" (click)="goBack()" class="arrow" fill="currentColor" viewBox="0 0 24 24"><path d="M2,12A10,10 0 0,1 12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12M18,11H10L13.5,7.5L12.08,6.08L6.16,12L12.08,17.92L13.5,16.5L10,13H18V11Z" /></svg>
<svg *ngIf="memory.AddingAdditionalSource" (click)="goBack()" class="arrow" fill="currentColor" viewBox="0 0 24 24">
<path
d="M2,12A10,10 0 0,1 12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12M18,11H10L13.5,7.5L12.08,6.08L6.16,12L12.08,17.92L13.5,16.5L10,13H18V11Z" />
</svg>
<div class="container text-center mt-5">
<ng-container *ngIf="!loading">
<h2 *ngIf="!memory.AddingAdditionalSource">Let's add your first source</h2>
Expand All @@ -12,54 +15,74 @@ <h2 *ngIf="memory.AddingAdditionalSource">Let's add another source</h2>
triggers="hover" [ngClass]="{'active': source.source_type == sourceTypeEnum.M3ULink}">M3U URL</button>
<button (click)="switchMode(sourceTypeEnum.Xtream)" class="btn btn-secondary"
[ngClass]="{'active': source.source_type == sourceTypeEnum.Xtream}">Xtream</button>
<button *ngIf="!memory.AddingAdditionalSource" class="btn btn-secondary" (click)="switchMode(sourceTypeEnum.Custom)"
[ngClass]="{'active': source.source_type == sourceTypeEnum.Custom}">Custom</button>
</div>
<form #form="ngForm" (ngSubmit)="submit()">
<div class="row mt-2 justify-content-center">
<div class="col-lg-6 col-md-8">
<input tabindex="0" autocomplete="off" #name="ngModel" source-name-exists name="name" empty class="form-control" [(ngModel)]="source.name"
placeholder="Nickname for this source">
<ng-container *ngIf="source.source_type != sourceTypeEnum.Custom">
<div class="row mt-2 justify-content-center">
<div class="col-lg-6 col-md-8">
<input tabindex="0" autocomplete="off" #name="ngModel" source-name-exists name="name" empty
class="form-control" [(ngModel)]="source.name" placeholder="Nickname for this source">
</div>
</div>
</div>
<div class="row mt-1 ps-3">
<div *ngIf="name.errors?.['sourceNameExists']" class="col-lg-6 col-md-8 text-danger">
This source name is already taken
<div class="row mt-1 ps-3">
<div *ngIf="name.errors?.['sourceNameExists']" class="col-lg-6 col-md-8 text-danger">
This source name is already taken
</div>
</div>
</div>

<div *ngIf="source.source_type != sourceTypeEnum.M3U">
</ng-container>
<div *ngIf="source.source_type != sourceTypeEnum.M3U && source.source_type != sourceTypeEnum.Custom">
<div class="row justify-content-center mt-2">
<div class="col-lg-6 col-md-8">
<input autocomplete="off" name="url" empty class="form-control" [(ngModel)]="source.url" placeholder="URL">
<input autocomplete="off" name="url" empty class="form-control" [(ngModel)]="source.url"
placeholder="URL">
</div>
</div>
</div>
<div *ngIf="source.source_type == sourceTypeEnum.Xtream">
<div class="row mt-2 justify-content-center">
<div class="col-lg-6 col-md-8">
<input autocomplete="off" name="username" empty class="form-control" [(ngModel)]="source.username"
placeholder="Username">
<input autocomplete="off" name="username" empty class="form-control"
[(ngModel)]="source.username" placeholder="Username">
</div>
</div>
<div class="row mt-2 justify-content-center">
<div class="col-lg-6 col-md-8">
<input autocomplete="off" name="password" empty class="form-control" [(ngModel)]="source.password"
placeholder="Password">
<input autocomplete="off" name="password" empty class="form-control"
[(ngModel)]="source.password" placeholder="Password">
</div>
</div>
</div>
<div class="mt-3">
<button [disabled]="!form.valid" class="btn btn-primary d-inline-flex align-items-center">
<ng-container *ngIf="source.source_type == sourceTypeEnum.M3U">
<span>Select file</span>
<svg class="anim-svg ms-1" viewBox="0 0 24 24" fill="currentColor"><path d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z" /></svg>
<svg class="anim-svg ms-1" viewBox="0 0 24 24" fill="currentColor">
<path
d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z" />
</svg>
</ng-container>
<ng-container *ngIf="source.source_type == sourceTypeEnum.M3ULink">
<span>Fetch</span>
<svg class="anim-svg ms-1" viewBox="0 0 24 24" fill="currentColor"><path d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z" /></svg>
<svg class="anim-svg ms-1" viewBox="0 0 24 24" fill="currentColor">
<path d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z" />
</svg>
</ng-container>
<ng-container *ngIf="source.source_type == sourceTypeEnum.Xtream">
<span>Login</span>
<svg class="anim-svg ms-1" viewBox="0 0 24 24" fill="currentColor"><path d="M19,3H5C3.89,3 3,3.89 3,5V9H5V5H19V19H5V15H3V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3M10.08,15.58L11.5,17L16.5,12L11.5,7L10.08,8.41L12.67,11H3V13H12.67L10.08,15.58Z" /></svg>
<svg class="anim-svg ms-1" viewBox="0 0 24 24" fill="currentColor">
<path
d="M19,3H5C3.89,3 3,3.89 3,5V9H5V5H19V19H5V15H3V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3M10.08,15.58L11.5,17L16.5,12L11.5,7L10.08,8.41L12.67,11H3V13H12.67L10.08,15.58Z" />
</svg>
</ng-container>
<ng-container *ngIf="source.source_type == sourceTypeEnum.Custom">
<span>
Start with only custom channels
</span>
<svg class="pen ms-1" fill="currentColor" viewBox="0 0 24 24">
<path d="M20.7,7C20.4,7.4 20,7.7 20,8C20,8.3 20.3,8.6 20.6,9C21.1,9.5 21.6,9.9 21.5,10.4C21.5,10.9 21,11.4 20.5,11.9L16.4,16L15,14.7L19.2,10.5L18.2,9.5L16.8,10.9L13,7.1L17,3.3C17.4,2.9 18,2.9 18.4,3.3L20.7,5.6C21.1,6 21.1,6.7 20.7,7M3,17.2L12.6,7.6L16.3,11.4L6.8,21H3V17.2M7,2V5H10V7H7V10H5V7H2V5H5V2H7Z" />
</svg>
</ng-container>
</button>
</div>
Expand Down
16 changes: 16 additions & 0 deletions src/app/setup/setup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,23 @@ export class SetupComponent {
break;
case SourceType.Xtream:
await this.getXtream();
break;
case SourceType.Custom:
await this.startWithCustomOnly();
break;
}
}

async startWithCustomOnly() {
this.loading = true;
try {
await invoke('add_custom_source');
this.nav.navigateByUrl("");
}
catch(e) {
this.error.handleError(e, "Invalid URL or credentials. Please try again");
}
this.loading = false;
}

async getM3ULink() {
Expand Down

0 comments on commit 4df9078

Please sign in to comment.