Skip to content

Commit 5566f3a

Browse files
authored
Merge pull request #50 from CodeDead/feature/update-api
Feature/update api
2 parents a2cc7fa + b7cb2aa commit 5566f3a

File tree

9 files changed

+86
-73
lines changed

9 files changed

+86
-73
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "advanced-portchecker",
33
"private": true,
4-
"version": "2.1.0",
4+
"version": "2.2.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
@@ -24,7 +24,7 @@
2424
"@tauri-apps/plugin-os": "^2.2.1",
2525
"react": "^19.1.0",
2626
"react-dom": "^19.1.0",
27-
"react-router-dom": "^7.5.0"
27+
"react-router-dom": "^7.5.1"
2828
},
2929
"devDependencies": {
3030
"@eslint/js": "^9.24.0",

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "advanced-portchecker"
3-
version = "2.1.0"
3+
version = "2.2.0"
44
description = "A lightweight TCP/IP port scanner with an intuitive UI."
55
authors = ["CodeDead <admin@codedead.com>"]
66
license = "GPL-3.0-only"

src-tauri/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::sync::{Arc, Mutex};
99
use std::thread::available_parallelism;
1010
use std::time::Duration;
1111
use std::{fs, thread};
12+
use tauri::Manager;
1213

1314
mod result;
1415

@@ -26,6 +27,15 @@ fn main() {
2627
};
2728

2829
tauri::Builder::default()
30+
.setup(|app| {
31+
#[cfg(debug_assertions)] // only include this code on debug builds
32+
{
33+
let window = app.get_webview_window("main").unwrap();
34+
window.open_devtools();
35+
window.close_devtools();
36+
}
37+
Ok(())
38+
})
2939
.plugin(tauri_plugin_os::init())
3040
.plugin(tauri_plugin_dialog::init())
3141
.manage(shared_state)

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"productName": "advanced-portchecker",
4444
"mainBinaryName": "advanced-portchecker",
45-
"version": "2.1.0",
45+
"version": "2.2.0",
4646
"identifier": "com.codedead.advancedportchecker",
4747
"plugins": {},
4848
"app": {

src/components/Layout/index.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React, { Suspense, useContext, useEffect } from 'react';
22
import Box from '@mui/material/Box';
33
import CssBaseline from '@mui/material/CssBaseline';
44
import { createTheme, ThemeProvider } from '@mui/material/styles';
5-
import { platform } from '@tauri-apps/plugin-os';
5+
import { getVersion } from '@tauri-apps/api/app';
6+
import { platform, arch } from '@tauri-apps/plugin-os';
67
import { Outlet } from 'react-router-dom';
7-
import packageJson from '../../../package.json';
88
import { MainContext } from '../../contexts/MainContextProvider';
99
import {
1010
getNumberOfThreads,
@@ -49,7 +49,7 @@ const Layout = () => {
4949
/**
5050
* Check for updates
5151
*/
52-
const checkForUpdates = () => {
52+
const checkForUpdates = async () => {
5353
if (loading) {
5454
return;
5555
}
@@ -59,7 +59,10 @@ const Layout = () => {
5959

6060
try {
6161
const res = platform();
62-
Updater(res.toLowerCase(), packageJson.version)
62+
const archRes = arch();
63+
const ver = 'v' + (await getVersion());
64+
65+
Updater(res.toLowerCase(), archRes.toLowerCase(), ver)
6366
.then((up) => {
6467
d1(setUpdate(up));
6568
})

src/routes/Settings/index.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import RadioGroup from '@mui/material/RadioGroup';
3535
import Select from '@mui/material/Select';
3636
import TextField from '@mui/material/TextField';
3737
import Typography from '@mui/material/Typography';
38-
import { platform } from '@tauri-apps/plugin-os';
39-
import packageJson from '../../../package.json';
38+
import { getVersion } from '@tauri-apps/api/app';
39+
import { platform, arch } from '@tauri-apps/plugin-os';
4040
import AlertDialog from '../../components/AlertDialog';
4141
import GridList from '../../components/GridList';
4242
import Theme from '../../components/Theme';
@@ -146,7 +146,7 @@ const Settings = () => {
146146
/**
147147
* Check for updates
148148
*/
149-
const checkForUpdates = () => {
149+
const checkForUpdates = async () => {
150150
if (loading) {
151151
return;
152152
}
@@ -156,7 +156,10 @@ const Settings = () => {
156156

157157
try {
158158
const res = platform();
159-
Updater(res.toLowerCase(), packageJson.version)
159+
const archRes = arch();
160+
const ver = 'v' + (await getVersion());
161+
162+
Updater(res.toLowerCase(), archRes.toLowerCase(), ver)
160163
.then((up) => {
161164
d1(setUpdate(up));
162165
d1(setCheckedForUpdates(true));

src/utils/Updater/index.js

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,62 @@
1-
const Updater = (os, currentVersion) => {
1+
const Updater = (os, architectureName, currentVersion) => {
22
/**
3-
* Check whether version b is newer than version a
4-
* @param a Version a
5-
* @param b Version b
6-
* @returns {boolean} True if version b is newer than version a, otherwise false
3+
* Compare two semantic versions
4+
* @param ver1 Version 1
5+
* @param ver2 Version 2
6+
* @returns {number} 1 if ver1 > ver2, -1 if ver1 < ver2, 0 if equal
77
*/
8-
const isNewer = (a, b) => {
9-
const partsA = a.split('.');
10-
const partsB = b.split('.');
11-
const numParts =
12-
partsA.length > partsB.length ? partsA.length : partsB.length;
8+
const semverCompare = (ver1, ver2) => {
9+
const v1Parts = ver1.slice(1).split('.').map(Number);
10+
const v2Parts = ver2.slice(1).split('.').map(Number);
1311

14-
for (let i = 0; i < numParts; i += 1) {
15-
if ((parseInt(partsB[i], 10) || 0) !== (parseInt(partsA[i], 10) || 0)) {
16-
return (parseInt(partsB[i], 10) || 0) > (parseInt(partsA[i], 10) || 0);
17-
}
12+
for (let i = 0; i < 3; i++) {
13+
if (v1Parts[i] > v2Parts[i]) return 1;
14+
if (v1Parts[i] < v2Parts[i]) return -1;
1815
}
19-
20-
return false;
16+
return 0;
2117
};
2218

2319
/**
24-
* Parse the information inside an external update
25-
* @param update The update data
26-
* @returns {{infoUrl: null, updateUrl: boolean, downloadUrl: null, version: null}}
20+
* Parse the update data
21+
* @param data The update data
22+
* @returns {{updateUrl, infoUrl: *, version: SemVer, updateAvailable: boolean}} The parsed update data
2723
*/
28-
const parseUpdate = (update) => {
29-
const platform = update.platforms[os];
30-
const data = {
31-
updateUrl: false,
32-
downloadUrl: null,
33-
infoUrl: null,
34-
version: null,
35-
};
24+
const parseUpdate = (data) => {
25+
const platform = data.platforms.find(
26+
(p) => p.platformName.toLowerCase() === os.toLowerCase(),
27+
);
28+
if (!platform) {
29+
throw new Error(`Platform ${os} not found`);
30+
}
3631

37-
if (
38-
isNewer(
39-
currentVersion,
40-
`${platform.version.majorVersion}.${platform.version.minorVersion}.${platform.version.buildVersion}.${platform.version.revisionVersion}`,
41-
)
42-
) {
43-
data.updateAvailable = true;
32+
// Find the architecture
33+
const architecture = platform.architectures.find(
34+
(a) => a.name === architectureName,
35+
);
36+
if (!architecture) {
37+
throw new Error(
38+
`Architecture ${architectureName} not found for platform ${os}`,
39+
);
4440
}
4541

46-
data.updateUrl = platform.updateUrl;
47-
data.infoUrl = platform.infoUrl;
48-
data.version = `${platform.version.majorVersion}.${platform.version.minorVersion}.${platform.version.buildVersion}.${platform.version.revisionVersion}`;
42+
// Sort releases by semver in descending order
43+
const sortedReleases = architecture.releases.sort((a, b) => {
44+
return semverCompare(b.semver, a.semver);
45+
});
4946

50-
return data;
47+
return {
48+
updateUrl: sortedReleases[0].downloadUrl,
49+
infoUrl: sortedReleases[0].infoUrl,
50+
version: sortedReleases[0].semver,
51+
updateAvailable:
52+
semverCompare(currentVersion, sortedReleases[0].semver) < 0,
53+
};
5154
};
5255

5356
return new Promise((resolve, reject) => {
54-
fetch('https://codedead.com/Software/Advanced%20PortChecker/version.json')
57+
fetch(
58+
'https://api.codedead.com/api/v1/applications/47cd7e8f-2744-443c-850e-619df5d5c43f',
59+
)
5560
.then((res) => {
5661
if (!res.ok) {
5762
throw Error(res.statusText);

yarn.lock

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,13 +2727,6 @@ __metadata:
27272727
languageName: node
27282728
linkType: hard
27292729

2730-
"@types/cookie@npm:^0.6.0":
2731-
version: 0.6.0
2732-
resolution: "@types/cookie@npm:0.6.0"
2733-
checksum: 10c0/5b326bd0188120fb32c0be086b141b1481fec9941b76ad537f9110e10d61ee2636beac145463319c71e4be67a17e85b81ca9e13ceb6e3bb63b93d16824d6c149
2734-
languageName: node
2735-
linkType: hard
2736-
27372730
"@types/eslint@npm:^8.4.5":
27382731
version: 8.56.12
27392732
resolution: "@types/eslint@npm:8.56.12"
@@ -3013,7 +3006,7 @@ __metadata:
30133006
prettier: "npm:^3.5.3"
30143007
react: "npm:^19.1.0"
30153008
react-dom: "npm:^19.1.0"
3016-
react-router-dom: "npm:^7.5.0"
3009+
react-router-dom: "npm:^7.5.1"
30173010
vite: "npm:^6.3.1"
30183011
vite-plugin-eslint: "npm:^1.8.1"
30193012
vite-plugin-svgr: "npm:^4.3.0"
@@ -3712,9 +3705,9 @@ __metadata:
37123705
linkType: hard
37133706

37143707
"electron-to-chromium@npm:^1.5.73":
3715-
version: 1.5.137
3716-
resolution: "electron-to-chromium@npm:1.5.137"
3717-
checksum: 10c0/678613e0a3d023563a1acca4d8103a69d389168efeb3b78c1fcc683ed0778d81bfb00c6f621d6535f3fa9530664fc948fc8f2ed27e7548d46cd3987d4b0add6a
3708+
version: 1.5.138
3709+
resolution: "electron-to-chromium@npm:1.5.138"
3710+
checksum: 10c0/f8e8b334857c3f858bb9ba1fa78b211e4174682fcc62316669a7cad6c86bbd01883a6433841b32effec694f90542bc439f28926826bb7e48d285ba951b4772ec
37183711
languageName: node
37193712
linkType: hard
37203713

@@ -5900,23 +5893,22 @@ __metadata:
59005893
languageName: node
59015894
linkType: hard
59025895

5903-
"react-router-dom@npm:^7.5.0":
5904-
version: 7.5.0
5905-
resolution: "react-router-dom@npm:7.5.0"
5896+
"react-router-dom@npm:^7.5.1":
5897+
version: 7.5.1
5898+
resolution: "react-router-dom@npm:7.5.1"
59065899
dependencies:
5907-
react-router: "npm:7.5.0"
5900+
react-router: "npm:7.5.1"
59085901
peerDependencies:
59095902
react: ">=18"
59105903
react-dom: ">=18"
5911-
checksum: 10c0/30fccb394869cf316d005367d55162401e650fdd146c53273e218ca7c7e42e539130ee663d0c5fbf546005bea6ee9bc5ce91b6698fd24b9282a2d13c6d951609
5904+
checksum: 10c0/52446158f883b599385f4feb2e11491440b350bc67e3b39b9eb79f76c20706075c813c3f9383b24a56a24dc2f22e9ee1c9910019b775248aa99485bcb6933e0e
59125905
languageName: node
59135906
linkType: hard
59145907

5915-
"react-router@npm:7.5.0":
5916-
version: 7.5.0
5917-
resolution: "react-router@npm:7.5.0"
5908+
"react-router@npm:7.5.1":
5909+
version: 7.5.1
5910+
resolution: "react-router@npm:7.5.1"
59185911
dependencies:
5919-
"@types/cookie": "npm:^0.6.0"
59205912
cookie: "npm:^1.0.1"
59215913
set-cookie-parser: "npm:^2.6.0"
59225914
turbo-stream: "npm:2.4.0"
@@ -5926,7 +5918,7 @@ __metadata:
59265918
peerDependenciesMeta:
59275919
react-dom:
59285920
optional: true
5929-
checksum: 10c0/fc1b4ed3eeb615f40727b81dfab7469429a0b662bff5f91434966751d48ce4b470d9627dcbc93dad9b1a535a0f9bd1b2267d8ff88ca4e636535bcbfe7d76cea3
5921+
checksum: 10c0/54e9f77ede0bf36c12685a59c5d965f77f2223d01cd922ce7b6ef4f8fa5435e66c796f9f5da3487bde0cb98dadd64f5a406696d4f52e031af812857aaab0f76b
59305922
languageName: node
59315923
linkType: hard
59325924

0 commit comments

Comments
 (0)