Skip to content

Commit

Permalink
Electron : restart after local image importation
Browse files Browse the repository at this point in the history
  • Loading branch information
fxi committed Apr 25, 2024
1 parent bd44ae8 commit e6b1754
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
10 changes: 8 additions & 2 deletions electron/src/main/modules/controller/docker_tools.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Docker from "dockerode";
import process from "node:process";
import { homedir } from "os";
import { existsSync } from "fs";
import { createReadStream, existsSync } from "fs";
import http from "http";
import { meta } from "./../../docker/index.js";

export class DockerTools {
constructor() {}
Expand Down Expand Up @@ -76,7 +77,12 @@ export class DockerTools {
if (!exists) {
throw new Error(`No image found. Path: ${imagePath}`);
}
await ctr._docker.loadImage(imagePath);
const data = createReadStream(imagePath);
await ctr._docker.loadImage(data, {
repo: meta.image_name,
tag: meta.tag,
});
return meta;
}

async isContainerReady(name) {
Expand Down
7 changes: 5 additions & 2 deletions electron/src/main/modules/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export class Controller extends Classes([
*/
async start() {
const ctr = this;
const versions = ctr._versions;
const language = ctr.getState("language");

try {
Expand Down Expand Up @@ -278,7 +279,10 @@ export class Controller extends Classes([
if (!hasV) {
ctr.sendMessageCodeClient("msg-info", "docker_load_file");
await ctr.wait(2000, "start docker_load_file");
await ctr.loadImage();
const meta = await ctr.loadImage();
ctr.sendMessageCodeClient("msg-info", "docker_reload_version");
await ctr.wait(2000, "start docker_load_file");
await versions.setVersion(meta.tag);
}

ctr.sendMessageCodeClient("msg-info", "data_loc_check");
Expand Down Expand Up @@ -512,7 +516,6 @@ export class Controller extends Classes([
});
}


/**
* Misc helpers;
*/
Expand Down
9 changes: 8 additions & 1 deletion electron/src/main/modules/translate/json/dict.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@
},
{
"id": "docker_load_file",
"en": "Unpacking local files...",
"en": "Registering AccessMod image in Docker...",
"fr": "",
"es": "",
"de": ""
},
{
"id": "docker_reload_version",
"en": "Restarting, please wait...",
"fr": "",
"es": "",
"de": ""
Expand Down
4 changes: 3 additions & 1 deletion electron/src/main/modules/versions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ export class Versions {
message: `Are you sure you want to restart and use version ${version} ? `,
});

if (!choice) await vrs.setVersion(version);
if (!choice) {
await vrs.setVersion(version);
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions version_manager/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export class VersionManager {
);
return;
}
if (debug) {
debugger;
}
await fs.writeFile(this.file_version, version, "utf8");
}

Expand Down

0 comments on commit e6b1754

Please sign in to comment.