From 9069c71f1805e0148e455755abd12e0faa91e710 Mon Sep 17 00:00:00 2001
From: Mariotaku
Date: Sun, 19 Feb 2023 01:43:23 +0900
Subject: [PATCH] fixed #72
---
src-tauri/src/plugins/devmode.rs | 62 ++++++++++++-------
src/app/core/services/dev-mode.service.ts | 4 ++
.../core/services/device-manager.service.ts | 40 ++++++++----
src/app/core/services/remote-luna.service.ts | 21 ++++++-
src/app/debug/debug.component.html | 6 ++
src/app/debug/debug.module.ts | 4 +-
.../debug/messages/messages.component.html | 3 +
.../debug/messages/messages.component.scss | 0
.../debug/messages/messages.component.spec.ts | 25 ++++++++
src/app/debug/messages/messages.component.ts | 49 +++++++++++++++
src/app/info/info.component.html | 5 +-
src/app/info/info.component.ts | 31 +++++++++-
12 files changed, 212 insertions(+), 38 deletions(-)
create mode 100644 src/app/debug/messages/messages.component.html
create mode 100644 src/app/debug/messages/messages.component.scss
create mode 100644 src/app/debug/messages/messages.component.spec.ts
create mode 100644 src/app/debug/messages/messages.component.ts
diff --git a/src-tauri/src/plugins/devmode.rs b/src-tauri/src/plugins/devmode.rs
index 547a0254..c07de3b2 100644
--- a/src-tauri/src/plugins/devmode.rs
+++ b/src-tauri/src/plugins/devmode.rs
@@ -4,7 +4,7 @@ use tauri::plugin::{Builder, TauriPlugin};
use tauri::regex::Regex;
use tauri::{Runtime, State};
-use crate::device_manager::Device;
+use crate::device_manager::{Device, DeviceManager};
use crate::error::Error;
use crate::session_manager::SessionManager;
@@ -23,6 +23,17 @@ struct DevModeSession {
error_msg: Option,
}
+#[tauri::command]
+async fn token(manager: State<'_, SessionManager>, device: Device) -> Result {
+ if device.username != "prisoner" {
+ return Err(Error::Unsupported);
+ }
+ if let Some(token) = valid_token(&manager, device).await? {
+ return Ok(token);
+ }
+ return Err(Error::Unsupported);
+}
+
#[tauri::command]
async fn status(
manager: State<'_, SessionManager>,
@@ -31,6 +42,31 @@ async fn status(
if device.username != "prisoner" {
return Err(Error::Unsupported);
}
+ if let Some(token) = valid_token(&manager, device).await? {
+ let url = Url::parse_with_params(
+ "https://developer.lge.com/secure/CheckDevModeSession.dev",
+ &[("sessionToken", token.clone())],
+ )
+ .expect("should be valid url");
+ let session: DevModeSession = reqwest::get(url).await?.json().await?;
+ if session.result == "success" {
+ return Ok(DevModeStatus {
+ token: Some(token),
+ remaining: Some(session.error_msg.unwrap_or(String::from(""))),
+ });
+ }
+ return Ok(DevModeStatus {
+ token: Some(token),
+ remaining: None,
+ });
+ }
+ return Ok(DevModeStatus {
+ token: None,
+ remaining: None,
+ });
+}
+
+async fn valid_token(manager: &SessionManager, device: Device) -> Result
+
+
+
@@ -19,7 +22,7 @@
Dev Mode
Remaining duration: {{devModeRemaining | async}}
Remaining time displaying on your TV will only update on boot.
-
+
diff --git a/src/app/info/info.component.ts b/src/app/info/info.component.ts
index e0e30fe8..88ea8338 100644
--- a/src/app/info/info.component.ts
+++ b/src/app/info/info.component.ts
@@ -2,9 +2,9 @@ import {Component, Injector} from '@angular/core';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import * as moment from 'moment';
import 'moment-duration-format';
-import {Observable, of, timer} from 'rxjs';
+import {noop, Observable, of, timer} from 'rxjs';
import {map} from 'rxjs/operators';
-import {Device, RawPackageInfo} from '../types';
+import {Device, FileSession, RawPackageInfo} from '../types';
import {
AppManagerService,
AppsRepoService,
@@ -16,6 +16,10 @@ import {
import {ProgressDialogComponent} from '../shared/components/progress-dialog/progress-dialog.component';
import {RenewScriptComponent} from './renew-script/renew-script.component';
import {HomebrewChannelConfiguration, SystemInfo} from "../types/luna-apis";
+import {MessageDialogComponent} from "../shared/components/message-dialog/message-dialog.component";
+import {LunaResponseError} from "../core/services/remote-luna.service";
+import {RemoteFileService} from "../core/services/remote-file.service";
+import {open as openPath} from "@tauri-apps/api/shell";
@Component({
selector: 'app-info',
@@ -36,6 +40,7 @@ export class InfoComponent {
constructor(
private modalService: NgbModal,
private deviceManager: DeviceManagerService,
+ private files: RemoteFileService,
private appManager: AppManagerService,
private appsRepo: AppsRepoService,
private devMode: DevModeService
@@ -70,6 +75,28 @@ export class InfoComponent {
});
}
+ async takeScreenshot(): Promise
{
+ // TODO: unify root check
+ const device = this.device;
+ if (!device || device.username !== 'root') return;
+ const progress = ProgressDialogComponent.open(this.modalService);
+ try {
+ const imgPath = await this.deviceManager.takeScreenshot(device);
+ const tempPath = await this.files.getTemp(device, imgPath)
+ .finally(() => this.files.rm(device, imgPath, false).catch(noop));
+ await openPath(tempPath);
+ } catch (e) {
+ console.log(JSON.stringify(e));
+ MessageDialogComponent.open(this.modalService, {
+ message: 'Failed to take screenshot',
+ error: e as Error,
+ positive: 'OK'
+ })
+ } finally {
+ progress.dismiss();
+ }
+ }
+
private async loadDeviceInfo(): Promise {
if (!this.device) return;
this.infoError = null;