Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice for IFTTT change of feature #177

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/app/info/info.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ export class InfoComponent {
renewScript(): void {
this.modalService.open(RenewScriptComponent, {
size: 'lg',
// scrollable: true,
scrollable: true,
injector: Injector.create({
providers: [{provide: 'device', useValue: this.device}]
providers: [
{provide: 'device', useValue: this.device},
{provide: 'devMode', useValue: this.devModeInfo},
]
})
});
}
Expand Down
54 changes: 35 additions & 19 deletions src/app/info/renew-script/renew-script.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,42 @@ <h5 class="modal-title">Automatic Developer Mode Renewal</h5>
<div class="modal-body">
<div class="d-flex">
<ul ngbNav #nav="ngbNav" class="nav-pills me-4" orientation="vertical">
<li ngbNavItem="ifttt" *ngIf="devModeToken">
<li ngbNavItem="manual">
<a class="text-nowrap" ngbNavLink>Manual Setup</a>
<ng-template ngbNavContent>
<p>Following is the URL to renew developer mode session. You can make request to it periodically to keep
developer mode session alive.</p>
<div class="overflow-auto bg-panel p-2">
<code
class="text-nowrap">https://developer.lge.com/secure/ResetDevModeSession.dev?sessionToken={{ devMode.token }}</code>
</div>
</ng-template>
</li>
<li ngbNavItem="script">
<a class="text-nowrap" ngbNavLink>Shell Script</a>
<ng-template ngbNavContent>
<ng-container *ngIf="renewScriptContent as script">
<p>Following is a shell script. It can be executed anywhere in your local area network.</p>
<div class="position-relative">
<pre class="pre-scrollable bg-panel p-3">{{ script }}</pre>
<div class="position-absolute top-0 right-0 my-2 mx-4">
<button type="button" class="btn btn-primary me-2" (click)="copyScript(script)">
<i class="bi bi-clipboard"></i>
</button>
<button type="button" class="btn btn-primary" (click)="saveScript(script)">
<i class="bi bi-save"></i>
</button>
</div>
</div>
</ng-container>
</ng-template>
</li>
<li ngbNavItem="ifttt">
<a class="text-nowrap" ngbNavLink>IFTTT Applet</a>
<ng-template ngbNavContent>
<div class="alert alert-warning" role="alert">
IFTTT does not offer webhook feature for free anymore.
</div>
<ul>
<li>Create an applet in <a href="https://ifttt.com/create" appExternalLink>ifttt.com/create</a>.</li>
<li>Select <strong>Date & Time</strong> as trigger.</li>
Expand All @@ -18,7 +51,7 @@ <h5 class="modal-title">Automatic Developer Mode Renewal</h5>
<li>Use <strong>URL below</strong>:
<div class="overflow-auto bg-panel p-2">
<code
class="text-nowrap">https://developer.lge.com/secure/ResetDevModeSession.dev?sessionToken={{devModeToken}}</code>
class="text-nowrap">https://developer.lge.com/secure/ResetDevModeSession.dev?sessionToken={{ devMode.token }}</code>
</div>
</li>
<li>Select <strong>Creation action</strong>.</li>
Expand All @@ -30,23 +63,6 @@ <h5 class="modal-title">Automatic Developer Mode Renewal</h5>
</ul>
</ng-template>
</li>
<li ngbNavItem="script" *ngIf="renewScriptContent as script">
<a class="text-nowrap" ngbNavLink>Shell Script</a>
<ng-template ngbNavContent>
<p>Following is a shell script. It can be executed anywhere in your local area network.</p>
<div class="position-relative">
<pre class="pre-scrollable bg-panel p-3">{{script}}</pre>
<div class="position-absolute top-0 right-0 my-2 mx-4">
<button type="button" class="btn btn-primary me-2" (click)="copyScript(script)">
<i class="bi bi-clipboard"></i>
</button>
<button type="button" class="btn btn-primary" (click)="saveScript(script)">
<i class="bi bi-save"></i>
</button>
</div>
</div>
</ng-template>
</li>
</ul>

<div [ngbNavOutlet]="nav" class="flex-fill overflow-hidden"></div>
Expand Down
72 changes: 35 additions & 37 deletions src/app/info/renew-script/renew-script.component.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
import {Component, Inject, OnInit} from '@angular/core';
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
import {Device} from '../../types';
import {DeviceManagerService, DevModeService} from '../../core/services';
import {DeviceManagerService, DevModeStatus} from '../../core/services';
import {noop} from 'rxjs';
import {save as showSaveDialog} from '@tauri-apps/api/dialog'
import {writeTextFile} from '@tauri-apps/api/fs';
import renewScriptTemplate from './renew-script.sh';
import Mustache from 'mustache';

@Component({
selector: 'app-renew-script',
templateUrl: './renew-script.component.html',
styleUrls: ['./renew-script.component.scss']
selector: 'app-renew-script',
templateUrl: './renew-script.component.html',
styleUrls: ['./renew-script.component.scss']
})
export class RenewScriptComponent implements OnInit {

public renewScriptContent?: string;
public devModeToken?: string;
public renewScriptContent?: string;

constructor(
public modal: NgbActiveModal,
private deviceManager: DeviceManagerService,
private devMode: DevModeService,
@Inject('device') public device: Device
) {
}
constructor(
public modal: NgbActiveModal,
private deviceManager: DeviceManagerService,
@Inject('device') public device: Device,
@Inject('devMode') public devMode: DevModeStatus,
) {
}

ngOnInit(): void {
this.devMode.status(this.device).then(({token}) => this.devModeToken = token);
this.deviceManager.readPrivKey(this.device).then(key => {
this.renewScriptContent = Mustache.render(renewScriptTemplate, {
device: this.device,
keyContent: key.trim(),
}, undefined, {
escape: (v) => v,
});
});
}
ngOnInit(): void {
this.deviceManager.readPrivKey(this.device).then(key => {
this.renewScriptContent = Mustache.render(renewScriptTemplate, {
device: this.device,
keyContent: key.trim(),
}, undefined, {
escape: (v) => v,
});
});
}

async copyScript(content: string): Promise<void> {
await navigator.clipboard.writeText(content);
}
async copyScript(content: string): Promise<void> {
await navigator.clipboard.writeText(content);
}

saveScript(content: string): void {
showSaveDialog({
defaultPath: `renew-devmode-${this.device.name}.sh`
}).then(value => {
if (!value) {
return;
}
return writeTextFile(value, content);
}).catch(noop);
}
saveScript(content: string): void {
showSaveDialog({
defaultPath: `renew-devmode-${this.device.name}.sh`
}).then(value => {
if (!value) {
return;
}
return writeTextFile(value, content);
}).catch(noop);
}
}
Loading