Skip to content

Commit

Permalink
🐛 [desktop-dev] 修复createProcess参数错误
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsword09 committed Oct 18, 2023
1 parent a38392b commit e6819af
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion desktop-dev/scripts/dnt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ await dnt.build({
target: [
{ target: "deb", arch: ["x64", "arm64"] },
// { target: "rpm", arch: ["x64", "arm64"] },
// { target: "tar.xz", arch: ["x64", "arm64"] },
{ target: "tar.xz", arch: ["x64", "arm64"] },
],
},
},
Expand Down
35 changes: 35 additions & 0 deletions desktop-dev/src/browser/jmm/micro-module.js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,29 @@ export class JsMicroModule extends MicroModule {
*/
private _process_id?: string;

static readonly VERSION: number = 1;
static readonly PATCH: number = 0;

/** 每个 JMM 启动都要依赖于某一个js */
async _bootstrap(context: $BootstrapContext) {
console.always("jsmm", `[${this.metadata.config.id} micro-module.js.ct _bootstrap ${this.mmid}]`);
console.always(
"jsmm",
`bootstrap minTarget: ${this.metadata.config.minTarget} maxTarget: ${this.metadata.config.maxTarget}`
);

this.metadata.canSupportTarget(JsMicroModule.VERSION, (minTarget) => {
throw new Error(
`应用${this.mmid}与容器版本不匹配,当前版本:${JsMicroModule.VERSION},应用最低要求:${minTarget}",
${this.short_name} 无法启动`
);
}, (maxTarget) => {
throw new Error(
`应用${this.mmid}与容器版本不匹配,当前版本:${JsMicroModule.VERSION},应用最高兼容到:${maxTarget}",
${this.short_name} 无法启动`
);
});

const pid = Math.ceil(Math.random() * 1000).toString();
this._process_id = pid;
// 这个 streamIpc 专门服务于 file://js.browser.dweb/create-process
Expand Down Expand Up @@ -298,4 +318,19 @@ class JmmIpc extends Native2JsIpc {}

export class JsMMMetadata {
constructor(readonly config: $JmmAppInstallManifest) {}

public canSupportTarget(
version: number,
disMatchMinTarget: (minTarget: number) => boolean,
disMatchMaxTarget: (maxTarget: number) => boolean
): boolean {
if (this.config.minTarget > version) {
return disMatchMinTarget(this.config.minTarget)
}
if (this.config.maxTarget != null && this.config.maxTarget < version) {
return disMatchMaxTarget(this.config.maxTarget!);
}

return true;
}
}
7 changes: 4 additions & 3 deletions desktop-dev/src/browser/js-process/js-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { z, zq } from "../../helper/zodHelper.ts";
import { closeHttpDwebServer, createHttpDwebServer } from "../../std/http/helper/$createHttpDwebServer.ts";
import { saveNative2JsIpcPort } from "./ipc.native2js.ts";
import { jsProcessOpenWindow } from "./js-process.openWindow.ts";
import { JsMicroModule } from "../jmm/micro-module.js.ts";

type $APIS = typeof import("./assets/main/index.ts")["APIS"];

Expand Down Expand Up @@ -323,9 +324,9 @@ export class JsProcessNMM extends NativeMicroModule {
bootstrap_url,
metadata,
env,
// JSON.stringify(metadata),
// JSON.stringify(env),
transfer(channel_for_worker.port2, [channel_for_worker.port2])
transfer(channel_for_worker.port2, [channel_for_worker.port2]),
httpDwebServer.startResult.urlInfo.host,
JSON.stringify({jsMicroModule: `${JsMicroModule.VERSION}.${JsMicroModule.PATCH}`})
);

/**
Expand Down

0 comments on commit e6819af

Please sign in to comment.