|
@@ -1,9 +1,8 @@
|
|
|
-import {NormMsg, decodeNormMsg, encodeNormMsg} from "./entity/message";
|
|
|
-import { Controller } from "../core/controller";
|
|
|
-//@ts-ignore
|
|
|
import { saveAs } from "file-saver";
|
|
|
+import { Base64 } from "js-base64";
|
|
|
+import { Controller } from "../core/controller";
|
|
|
+import { NormMsg, decodeNormMsg, encodeNormMsg } from "./entity/message";
|
|
|
|
|
|
-import {Base64 } from "js-base64"
|
|
|
type UploadItem = {
|
|
|
id: string;
|
|
|
fpath: string;
|
|
@@ -22,7 +21,7 @@ export type FileInfo = {
|
|
|
export class DeviceController extends Controller {
|
|
|
ipc: any;
|
|
|
|
|
|
- profile = {wsPort: "", appGuid: ""}
|
|
|
+ profile = { wsPort: "", appGuid: "" };
|
|
|
|
|
|
isEnvOk = false;
|
|
|
|
|
@@ -34,7 +33,6 @@ export class DeviceController extends Controller {
|
|
|
//@ts-ignore
|
|
|
this.ipc = window.ipc;
|
|
|
this.isEnvOk = true;
|
|
|
-
|
|
|
} else {
|
|
|
this.ipc = {
|
|
|
emit(name: string, ...args: any[]) {
|
|
@@ -54,16 +52,16 @@ export class DeviceController extends Controller {
|
|
|
this.ipc.on("OnDragEnter", function (files: string[]) {
|
|
|
scope.emit("onDragEnter", files);
|
|
|
});
|
|
|
- this.ipc.on("downloadsucc", (fpath:string, size:number)=>{
|
|
|
- scope.emit("downloadsucc", fpath, size);
|
|
|
- })
|
|
|
+ this.ipc.on("downloadsucc", (fpath: string, size: number) => {
|
|
|
+ scope.emit("downloadsucc", fpath, size);
|
|
|
+ });
|
|
|
|
|
|
- this.ipc.emit("GetSocketUri", [], (uri:string) => {
|
|
|
+ this.ipc.emit("GetSocketUri", [], (uri: string) => {
|
|
|
let conn = new WebSocket(uri);
|
|
|
- conn.onopen = (e)=>{
|
|
|
- console.log("bus socket connected!!!")
|
|
|
- }
|
|
|
- conn.onclose = (evt)=>{
|
|
|
+ conn.onopen = (e) => {
|
|
|
+ console.log("bus socket connected!!!");
|
|
|
+ };
|
|
|
+ conn.onclose = (evt) => {
|
|
|
console.log("app bus socket conn closed", evt);
|
|
|
|
|
|
setTimeout(() => {
|
|
@@ -72,30 +70,32 @@ export class DeviceController extends Controller {
|
|
|
};
|
|
|
conn.onmessage = function (evt) {
|
|
|
if (!evt.data || evt.data == "") return;
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
const blob = evt.data as Blob;
|
|
|
- blob.arrayBuffer().then(buff=>{
|
|
|
- const msg = decodeNormMsg(new Uint8Array(buff))
|
|
|
+ blob.arrayBuffer().then((buff) => {
|
|
|
+ const msg = decodeNormMsg(new Uint8Array(buff));
|
|
|
scope.emit("on" + msg.sub, msg);
|
|
|
- })
|
|
|
+ });
|
|
|
} catch (error) {
|
|
|
- console.error(evt.data, typeof evt.data, error);
|
|
|
+ console.error(evt.data, typeof evt.data, error);
|
|
|
}
|
|
|
};
|
|
|
this._conn = conn;
|
|
|
});
|
|
|
-
|
|
|
}
|
|
|
|
|
|
async onReady() {
|
|
|
- if (!this.isEnvOk) return;
|
|
|
+ if (!this.isEnvOk) return;
|
|
|
|
|
|
- this.profile = await this.GetLocalAppProfile() || {wsPort:"", appGuid: ""};
|
|
|
+ this.profile = (await this.GetLocalAppProfile()) || {
|
|
|
+ wsPort: "",
|
|
|
+ appGuid: "",
|
|
|
+ };
|
|
|
|
|
|
- console.log("current app profile=>", this.profile);
|
|
|
+ console.log("current app profile=>", this.profile);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//选择磁盘文件夹
|
|
|
SelectDir(): Promise<string> {
|
|
|
const sid = Date.now();
|
|
@@ -154,7 +154,7 @@ export class DeviceController extends Controller {
|
|
|
const cbname = "copy" + sid;
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.on(cbname, function (ok:boolean) {
|
|
|
+ ipc.on(cbname, function (ok: boolean) {
|
|
|
r(ok);
|
|
|
});
|
|
|
ipc.emit("CopyFile", [cbname, srcFile, targetFile]);
|
|
@@ -236,14 +236,18 @@ export class DeviceController extends Controller {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
const cbname = "c" + sid;
|
|
|
- ipc.emit("SelectOneFilePath", [sid, title, filters], function (ok:boolean) {
|
|
|
- if (!ok) {
|
|
|
- r("");
|
|
|
+ ipc.emit(
|
|
|
+ "SelectOneFilePath",
|
|
|
+ [sid, title, filters],
|
|
|
+ function (ok: boolean) {
|
|
|
+ if (!ok) {
|
|
|
+ r("");
|
|
|
+ }
|
|
|
+ ipc.on(cbname, function (dir: string) {
|
|
|
+ r(dir);
|
|
|
+ });
|
|
|
}
|
|
|
- ipc.on(cbname, function (dir: string) {
|
|
|
- r(dir);
|
|
|
- });
|
|
|
- });
|
|
|
+ );
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -267,11 +271,9 @@ export class DeviceController extends Controller {
|
|
|
): Promise<boolean> {
|
|
|
const sid = "d" + Date.now();
|
|
|
return new Promise((r) => {
|
|
|
-
|
|
|
- console.log(url, "==>", fpath)
|
|
|
+ console.log(url, "==>", fpath);
|
|
|
const cancel = this.OnMsg(sid, (data) => {
|
|
|
-
|
|
|
- cb && cb(data.type as any, data);
|
|
|
+ cb && cb(data.type as any, data);
|
|
|
if (data.type == "succ") {
|
|
|
r(true);
|
|
|
cancel.unbind();
|
|
@@ -298,13 +300,16 @@ export class DeviceController extends Controller {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- Unzip(fpath:string, distDir:string, cb?: (event: "progress" | "error" | "succ", p1: NormMsg) => void) {
|
|
|
+ Unzip(
|
|
|
+ fpath: string,
|
|
|
+ distDir: string,
|
|
|
+ cb?: (event: "progress" | "error" | "succ", p1: NormMsg) => void
|
|
|
+ ) {
|
|
|
const sid = "unzip" + Date.now();
|
|
|
|
|
|
return new Promise((r) => {
|
|
|
-
|
|
|
const cancel = this.OnMsg(sid, (data) => {
|
|
|
- cb && cb(data.type as any, data);
|
|
|
+ cb && cb(data.type as any, data);
|
|
|
if (data.type == "succ") {
|
|
|
r(true);
|
|
|
cancel.unbind();
|
|
@@ -352,7 +357,7 @@ export class DeviceController extends Controller {
|
|
|
1280,
|
|
|
960,
|
|
|
],
|
|
|
- function (ok:boolean) {
|
|
|
+ function (ok: boolean) {
|
|
|
r(ok);
|
|
|
}
|
|
|
);
|
|
@@ -365,7 +370,7 @@ export class DeviceController extends Controller {
|
|
|
console.error("应用socket异常");
|
|
|
return;
|
|
|
}
|
|
|
- conn.send(encodeNormMsg({sub: subject, msg: msg}));
|
|
|
+ conn.send(encodeNormMsg({ sub: subject, msg: msg }));
|
|
|
}
|
|
|
|
|
|
OnMsg(subject: string, cb: (msg: NormMsg) => any) {
|
|
@@ -376,7 +381,7 @@ export class DeviceController extends Controller {
|
|
|
UploadSync(files: UploadItem[]): Promise<UploadItem[]> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("UploadSync", [files], function (ret:any) {
|
|
|
+ ipc.emit("UploadSync", [files], function (ret: any) {
|
|
|
r(ret);
|
|
|
});
|
|
|
});
|
|
@@ -387,12 +392,12 @@ export class DeviceController extends Controller {
|
|
|
const sid = "u" + Date.now();
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("UploadASync", [sid, files], function (ok:boolean) {
|
|
|
+ ipc.emit("UploadASync", [sid, files], function (ok: boolean) {
|
|
|
if (!ok) {
|
|
|
r([]);
|
|
|
return;
|
|
|
}
|
|
|
- ipc.on(sid, (items:any) => {
|
|
|
+ ipc.on(sid, (items: any) => {
|
|
|
r(items);
|
|
|
});
|
|
|
});
|
|
@@ -404,66 +409,66 @@ export class DeviceController extends Controller {
|
|
|
const sid = "u" + Date.now();
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("UploadDir", [sid, dir, targetDir], function (ok:any) {
|
|
|
+ ipc.emit("UploadDir", [sid, dir, targetDir], function (ok: any) {
|
|
|
if (!ok) {
|
|
|
r([]);
|
|
|
return;
|
|
|
}
|
|
|
- ipc.on(sid, (items:any) => {
|
|
|
+ ipc.on(sid, (items: any) => {
|
|
|
r(items);
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- GetFilesInDir(dir:string, filter:string): Promise<FileInfo[]>{
|
|
|
+ GetFilesInDir(dir: string, filter: string): Promise<FileInfo[]> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("GetFilesInDir", [ dir, filter], function (ret:any) {
|
|
|
+ ipc.emit("GetFilesInDir", [dir, filter], function (ret: any) {
|
|
|
r(ret);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- GetSubDirNames(dir:string):Promise<string[]>{
|
|
|
+ GetSubDirNames(dir: string): Promise<string[]> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("GetSubDirNames", [ dir], function (ret:any) {
|
|
|
+ ipc.emit("GetSubDirNames", [dir], function (ret: any) {
|
|
|
r(ret);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- RemoveFile(fpath: string) : Promise<boolean>{
|
|
|
+ RemoveFile(fpath: string): Promise<boolean> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("RemoveFile", [fpath], function (ok:boolean) {
|
|
|
+ ipc.emit("RemoveFile", [fpath], function (ok: boolean) {
|
|
|
r(ok);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- GetSaveFile(title:string, filter= "图片(*.png;*.jpg)") :Promise<string> {
|
|
|
- const sid = "sf"+Date.now();
|
|
|
+ GetSaveFile(title: string, filter = "图片(*.png;*.jpg)"): Promise<string> {
|
|
|
+ const sid = "sf" + Date.now();
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("GetSaveFile", [sid, title, filter], function (ok:boolean) {
|
|
|
- if(ok) {
|
|
|
- ipc.on(sid, (ret:any)=>{
|
|
|
- r(ret);
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- r("");
|
|
|
+ ipc.emit("GetSaveFile", [sid, title, filter], function (ok: boolean) {
|
|
|
+ if (ok) {
|
|
|
+ ipc.on(sid, (ret: any) => {
|
|
|
+ r(ret);
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ r("");
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- OpenOneFile(title:string, filter= "图片(*.png;*.jpg)") :Promise<string> {
|
|
|
- const sid = "sf"+Date.now();
|
|
|
+ OpenOneFile(title: string, filter = "图片(*.png;*.jpg)"): Promise<string> {
|
|
|
+ const sid = "sf" + Date.now();
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("OpenOneFile", [sid, title, filter], function (file:any) {
|
|
|
+ ipc.emit("OpenOneFile", [sid, title, filter], function (file: any) {
|
|
|
setTimeout(() => {
|
|
|
r(file);
|
|
|
}, 0);
|
|
@@ -471,15 +476,14 @@ export class DeviceController extends Controller {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- GetImageMeta(fpath:string): Promise<{Width: number, Height: number, Size:number}> {
|
|
|
-
|
|
|
-
|
|
|
+ GetImageMeta(
|
|
|
+ fpath: string
|
|
|
+ ): Promise<{ Width: number; Height: number; Size: number }> {
|
|
|
return new Promise((r) => {
|
|
|
-
|
|
|
const img = new Image();
|
|
|
- img.onload=()=>{
|
|
|
- r({Width: img.width, Height: img.height, Size: 0})
|
|
|
- }
|
|
|
+ img.onload = () => {
|
|
|
+ r({ Width: img.width, Height: img.height, Size: 0 });
|
|
|
+ };
|
|
|
img.src = fpath;
|
|
|
|
|
|
// const ipc = this.ipc;
|
|
@@ -488,66 +492,66 @@ export class DeviceController extends Controller {
|
|
|
// });
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- SetMainTitle(title :string):Promise<boolean> {
|
|
|
+
|
|
|
+ SetMainTitle(title: string): Promise<boolean> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("SetMainTitle", [title], function (ok:any) {
|
|
|
- r(ok)
|
|
|
+ ipc.emit("SetMainTitle", [title], function (ok: any) {
|
|
|
+ r(ok);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- SaveFile(fpath: string, buff:any) :Promise<string>{
|
|
|
+ SaveFile(fpath: string, buff: any): Promise<string> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("SaveFile", [fpath, Array.from(buff)], function (err:string) {
|
|
|
- r(err)
|
|
|
+ ipc.emit("SaveFile", [fpath, Array.from(buff)], function (err: string) {
|
|
|
+ r(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- OpenQueen5(url: string, title:any) :Promise<boolean>{
|
|
|
+
|
|
|
+ OpenQueen5(url: string, title: any): Promise<boolean> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("OpenQueen5", [url, title], function (err:any) {
|
|
|
- r(err)
|
|
|
+ ipc.emit("OpenQueen5", [url, title], function (err: any) {
|
|
|
+ r(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
- OpenQueen5Play(url: string, title:any) :Promise<boolean>{
|
|
|
+ OpenQueen5Play(url: string, title: any): Promise<boolean> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("OpenQueen5Play", [url, title], function (err:any) {
|
|
|
- r(err)
|
|
|
+ ipc.emit("OpenQueen5Play", [url, title], function (err: any) {
|
|
|
+ r(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- SaveBlobFile(url:string, fbase64path:string) :Promise<boolean> {
|
|
|
+ SaveBlobFile(url: string, fbase64path: string): Promise<boolean> {
|
|
|
console.log("save blob to ", fbase64path);
|
|
|
|
|
|
return new Promise((r) => {
|
|
|
- const cancel = this.on("downloadsucc", (dpath:string)=>{
|
|
|
- console.log("fpath=>", dpath)
|
|
|
- if (fbase64path == Base64.encode(dpath)) {
|
|
|
+ const cancel = this.on("downloadsucc", (dpath: string) => {
|
|
|
+ console.log("fpath=>", dpath);
|
|
|
+ if (fbase64path == Base64.encode(dpath)) {
|
|
|
cancel.unbind();
|
|
|
- r(true)
|
|
|
+ r(true);
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
saveAs(url, fbase64path);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- SaveClipboard(blob:Blob) {
|
|
|
- return navigator.clipboard.write([
|
|
|
+ SaveClipboard(blob: Blob) {
|
|
|
+ return navigator.clipboard.write([
|
|
|
new ClipboardItem({
|
|
|
- "image/png": blob
|
|
|
- })
|
|
|
- ])
|
|
|
+ "image/png": blob,
|
|
|
+ }),
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
- GetNatsProfile(): Promise<{ apiPort: string, wsPort: string , ip:string}> {
|
|
|
+ GetNatsProfile(): Promise<{ apiPort: string; wsPort: string; ip: string }> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
ipc.emit("NatsProfile", [], function (data: any) {
|
|
@@ -556,16 +560,21 @@ export class DeviceController extends Controller {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- GetLocalAppProfile(): Promise<{wsPort:string, appGuid:string}> {
|
|
|
+ GetLocalAppProfile(): Promise<{ wsPort: string; appGuid: string }> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
ipc.emit("LocalAppProfile", [], function (data: any) {
|
|
|
- r(data || {wsPort:"", appGuid: ""});
|
|
|
+ r(data || { wsPort: "", appGuid: "" });
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- OpenWeb(url:string, title:string, width = 1280, height = 720) :Promise<boolean>{
|
|
|
+ OpenWeb(
|
|
|
+ url: string,
|
|
|
+ title: string,
|
|
|
+ width = 1280,
|
|
|
+ height = 720
|
|
|
+ ): Promise<boolean> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
ipc.emit("OpenWeb", [url, title, width, height], function (data: any) {
|
|
@@ -574,27 +583,36 @@ export class DeviceController extends Controller {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- RunNativeApp(guid:string, entry:string, params:string[]) :Promise<string> {
|
|
|
+ RunNativeApp(guid: string, entry: string, params: string[]): Promise<string> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
ipc.emit("RunNativeApp", [guid, entry, params], function (err: string) {
|
|
|
- console.log("xxxx", err)
|
|
|
+ console.log("xxxx", err);
|
|
|
r(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- RunCmdSvcApp(guid:string, webUrl:string, entry:string, params:string[]) :Promise<string> {
|
|
|
+ RunCmdSvcApp(
|
|
|
+ guid: string,
|
|
|
+ webUrl: string,
|
|
|
+ entry: string,
|
|
|
+ params: string[]
|
|
|
+ ): Promise<string> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
- ipc.emit("RunCmdSvcApp", [guid, webUrl, entry, params], function (err: string) {
|
|
|
- console.log("xxxx", err)
|
|
|
- r(err);
|
|
|
- });
|
|
|
+ ipc.emit(
|
|
|
+ "RunCmdSvcApp",
|
|
|
+ [guid, webUrl, entry, params],
|
|
|
+ function (err: string) {
|
|
|
+ console.log("xxxx", err);
|
|
|
+ r(err);
|
|
|
+ }
|
|
|
+ );
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- StopNativeApp(guid:string) :Promise<boolean> {
|
|
|
+ StopNativeApp(guid: string): Promise<boolean> {
|
|
|
return new Promise((r) => {
|
|
|
const ipc = this.ipc;
|
|
|
ipc.emit("StopNativeApp", [guid], function (ok: boolean) {
|