Skip to content

Commit

Permalink
Electron vite built : first working (building) version
Browse files Browse the repository at this point in the history
  • Loading branch information
fxi committed Apr 23, 2024
1 parent e68cc77 commit c4d5dce
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 18 deletions.
Binary file removed electron_vite/build/icon.icns
Binary file not shown.
Binary file removed electron_vite/build/icon.ico
Binary file not shown.
Binary file modified electron_vite/build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion electron_vite/electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ appId: org.accessmod.desktop
productName: AccessMod Desktop
directories:
buildResources: build
lib:
files:
- '!**/.vscode/*'
- '!src/*'
Expand All @@ -14,6 +13,7 @@ asarUnpack:
- resources/**
win:
executableName: AccessMod Desktop
icon: build/icon.png
nsis:
artifactName: ${name}-${version}-setup.${ext}
shortcutName: ${productName}
Expand All @@ -27,6 +27,7 @@ mac:
notarize: false
category: public.app-category.education
type: development
icon: build/icon.png
dmg:
artifactName: ${name}-${version}.${ext}
linux:
Expand All @@ -36,6 +37,7 @@ linux:
- deb
maintainer: accessmod.org
category: Utility
icon: build/icon.png
appImage:
artifactName: ${name}-${version}.${ext}
npmRebuild: false
Expand Down
4 changes: 2 additions & 2 deletions electron_vite/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "accessmod-desktop",
"version": "5.8.1",
"version": "5.8.2",
"description": "AccessMod Desktop : manage accessmod docker images, data and versions.",
"main": "./out/main/index.js",
"author": "Fred Moser",
"author": "accessmod.org",
"license": "MIT",
"type": "module",
"keywords": [
Expand Down
Binary file removed electron_vite/resources/icon.png
Binary file not shown.
38 changes: 38 additions & 0 deletions electron_vite/src/main/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import fetch from "node-fetch";

const cache = {};

/**
* Fetches data from a URL with caching capability.
* If cached data is available and not expired, it returns the cached data.
* Otherwise, it fetches from the network, caches the new data, and returns it.
*
* @param {string} url - The URL to fetch the data from.
* @param {number} ttl - Time to live for the cache in seconds.
* @returns {Promise<any>} The fetched data.
*/
export async function fetchCacheData(url, ttl) {
const now = Date.now();
const item = cache[url];

// Check if item exists and is still valid
if (item && item.expires > now) {
return item.data;
}

// If the item is expired or doesn't exist, fetch new data
const res = await fetch(url);
if (!res.ok) {
throw new Error(
`HTTP error while fetching data. Status: ${res.status} - ${res.statusText}`
);
}

const data = await res.json();
const expires = now + ttl * 1000; // Calculate the expiration time

// Cache the new data with expiration time
cache[url] = { data, expires };

return data;
}
1 change: 0 additions & 1 deletion electron_vite/src/main/modules/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ export class Controller extends Classes([
versionsAdd: true,
versionsForceFetch: true,
});
debugger;

/**
* Test if docker image exists
Expand Down
38 changes: 24 additions & 14 deletions electron_vite/src/main/modules/versions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import semver from "semver";
import fetch from "node-fetch";
import { dialog } from "electron";
import { fetchCacheData } from "../../fetch";

const cache = {
list_local: [],
Expand Down Expand Up @@ -33,7 +33,6 @@ export class Versions {
const vrs = this;
const ctr = vrs._ctr;
const sum = await vrs.summary(force);
debugger;
const out = [];

// has update
Expand Down Expand Up @@ -171,10 +170,7 @@ export class Versions {
const nRes = 100;
const pNum = 1;
const url = `${rUrl}/repositories/${rName}/tags/?page_size=${nRes}&page=${pNum}`;
debugger;
const res = await fetch(url);
debugger;
const data = await res.json();
const data = await fetchCacheData(url, 60 * 30);
const versions = vrs.filterValid(data.results.map((r) => r.name));

if (versions.length > 0) {
Expand Down Expand Up @@ -211,7 +207,6 @@ export class Versions {
async listLocal() {
const vrs = this;
const rTag = await vrs.listRepoTags();
debugger;
return vrs.filterValid(rTag.map((r) => r.split(":")[1]));
}

Expand Down Expand Up @@ -364,17 +359,32 @@ export class Versions {

ref[image_name] = true;

debugger;
const ii = await ctr._docker.listImages();

debugger;

const imgs = await ctr._docker.listImages({
filters: {
reference: ref,
},
});
debugger;
});

/**
* {
* "Containers": -1,
* "Created": 1705928421,
* "Id": "sha256:d317c1318293e7e31935282877a42473783dfa071385f9fe4df85be9adcf5b45",
* "Labels": {
* "maintainer": "email>"
* },
* "ParentId": "",
* "RepoDigests": [
* "fredmoser/accessmod@sha256:1113c8266f88e58b535a9ed9efff57e077749c8c62c33081efd33b0b55ad8e4b"
* ],
* "RepoTags": [
* "fredmoser/accessmod:5.8.2-alpha.2"
* ],
* "SharedSize": -1,
* "Size": 432105534
* }
*/

return imgs;
}

Expand Down

0 comments on commit c4d5dce

Please sign in to comment.