Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
hschneider committed Jan 4, 2024
1 parent 7815995 commit 21bef2b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 73 deletions.
28 changes: 7 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ The update keys point to the following fields:

## Update-Server Setup

Copy all content from the **_server/demo** folder to your update server. Don't forget the **.htaccess-file.** The update zip-files are placed in the same folder as the manifest.
Copy all content from the **_server/demo** folder to your update server. The update zip-files are placed in the same folder as the manifest.

If you are already live with autoupdate-enabled apps in the wild, disable the manifest by setting

Expand All @@ -162,19 +162,6 @@ shasum -a 256 FILE.zip
certutil -hashfile FILE.zip SHA256
```

Make sure, that the **.htaccess-file** is located in the same folder as the manifest as well. This is necessary to allow CORS-requests from the Neutralino app to the update server.

If you run a **NGINX** proxy server, you'll have to add this to your NGINX config:

```bash
location /path/to/your/update/folder {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET';
add_header 'Access-Control-Allow-Headers' 'Content-Type,X-Auth-App';
add_header 'Access-Control-Expose-Headers' 'Content-Length,X-Auth-App';
}
```

Next create a **secret security token** with some password generator of your choice and enter it in **manifest.php**:

```php
Expand Down Expand Up @@ -317,13 +304,12 @@ The **URL** can either point to **manifest.json** or the more secure PHP wrapper

### Methods

| Method | Description |
| --------------------- | ------------------------------------------------------------ |
| addHeader(key, value) | Add an additional header to all fetch requests. This can be used for custom authentication, e.g. when you generate the manifest with a PHP script. |
| async check() | Check the update manifest's version against the app's version. If an update exists, the update-dialog pops up. |
| async checkSilent() | Does the same as .check() but without dialog. If an update exists, it returns true. |
| async update() | Starts the update process. Returns false in case of an error or quits the app if the update was successful. This is either called from the update-dialog's install-button or directly after .checkSilent(). |
| log(msg) | The internal log function. msg can be a string or an object. This logs msg to the app's console. |
| Method | Description |
| ------------------- | ------------------------------------------------------------ |
| async check() | Check the update manifest's version against the app's version. If an update exists, the update-dialog pops up. |
| async checkSilent() | Does the same as .check() but without dialog. If an update exists, it returns true. |
| async update() | Starts the update process. Returns false in case of an error or quits the app if the update was successful. This is either called from the update-dialog's install-button or directly after .checkSilent(). |
| log(msg) | The internal log function. msg can be a string or an object. This logs msg to the app's console. |

## More about Neutralino

Expand Down
14 changes: 0 additions & 14 deletions _server/demo/.htaccess

This file was deleted.

2 changes: 1 addition & 1 deletion _server/demo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"file": "AutoupdateDemo_macos-x64.zip",
"start": "start.dmg",
"checksum": "fc37472674da4e978ebec2eaf66abb5d1d9c1e033f3d11f1b1d2eec03e0eb612",
"checksum": "8b3a18106dc403dcf91669da79f5d0ed85f74cbf5c854f16ef1eb42c23520686",
"notes": "release-notes.html"
},
"updateDarwinARM64":
Expand Down
48 changes: 11 additions & 37 deletions resources/js/neutralino-autoupdate/autoupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NeutralinoAutoupdate {
// opt lang: Dialog language, defaults to en
// opt customLang: A custom language dict

this.version = '1.1.9';
this.version = '1.2.0';
this.debug = opt.debug || true;

this.urlManifest = urlManifest; // Manifest URL
Expand All @@ -34,14 +34,9 @@ class NeutralinoAutoupdate {
this.appVersion = NL_APPVERSION; // App current version

this.appRoot = NL_PATH; // App root path
this.appReources = this.appRoot + '/resources'; // App resources path
this.appReourcesJS = this.appReources + '/js'; // App JS resources
this.appResourcesBIN = this.appReources + '/bin'; // App BIN resources

this.headers = new Headers(); // Custom request headers
if(this.token !== '') {
this.addHeader('X-Auth-App', this.token);
}
this.appResources = this.appRoot + '/resources'; // App resources path
this.appReourcesJS = this.appResources + '/js'; // App JS resources
this.appResourcesBIN = this.appResources + '/bin'; // App BIN resources

this.updKey = 'update' + this.os + this.arch.toUpperCase(); // Manifest update-key: updateOsARCH
this.updating = false; // True while .update() is running
Expand Down Expand Up @@ -122,12 +117,9 @@ class NeutralinoAutoupdate {
// Import Release notes
//
let url = this.urlManifest.replace(/manifest.*$/, this.manifest[this.updKey]['notes']);
const response = await fetch(url, {
method: 'GET',
cache: 'no-store',
headers: this.headers
});
let notes = await response.text();
let cmd = this.appResourcesBIN + '/curl -k -H "X-Auth-App: ' + this.token + '" -X GET ' + url;
let res = await Neutralino.os.execCommand(cmd);
let notes = res.stdOut;
d = d.replace('{notes}', notes);

// Build modal
Expand Down Expand Up @@ -164,14 +156,6 @@ class NeutralinoAutoupdate {
this._alertClose();
});
}
addHeader(key, val) {
//
// Add custom request-headers

this.headers.append(key, val);
console.log(this.headers)

}
_modalClose() {
//
// Close modal dialog.
Expand Down Expand Up @@ -246,20 +230,10 @@ class NeutralinoAutoupdate {
// Get manifest and check, if an update is available.

try {
const response = await fetch(this.urlManifest, {
method: 'GET',
cache: 'no-store',
headers: this.headers
});
if (!response.ok) {
this.log('ERROR: check() response not OK.');
return false;
}

this.manifest = await response.json();

const cmd = this.appResourcesBIN + '/curl -k -H "Accept: application/json" -H "X-Auth-App: ' + this.token + '" -X GET ' + this.urlManifest;
const res = await Neutralino.os.execCommand(cmd);
this.manifest = JSON.parse(res.stdOut);
this.log('check(): Received manifest:');
this.log(this.manifest);

if(this.manifest.enabled === false) {
this.log("check(): Manifest is disabled.");
Expand Down Expand Up @@ -318,7 +292,7 @@ class NeutralinoAutoupdate {
}
await Neutralino.os.execCommand(cmd);

cmd = this.appReourcesBIN + '/curl -k -o ' + this.pathDownload + f + ' -JL ' + url;
cmd = this.appResourcesBIN + '/curl -k -o ' + this.pathDownload + f + ' -JL ' + url;
let res = await Neutralino.os.execCommand(cmd);

// -- Validate
Expand Down

0 comments on commit 21bef2b

Please sign in to comment.