Skip to content

Commit dcf5031

Browse files
SRWieZgwleuverink
andauthored
feat: add support for Cloudflare R2 updater (#54)
* feat: add support for public URL in updater configuration * Build plugin --------- Co-authored-by: Willem Leuverink <willem@leuver.ink>
1 parent b7fd944 commit dcf5031

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

config/nativephp.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
/**
103103
* The updater provider to use.
104104
* Supported: "github", "s3", "spaces"
105+
* Note: The "s3" provider is compatible with S3-compatible services like Cloudflare R2.
105106
*/
106107
'default' => env('NATIVEPHP_UPDATER_PROVIDER', 'spaces'),
107108

@@ -125,6 +126,13 @@
125126
'bucket' => env('AWS_BUCKET'),
126127
'endpoint' => env('AWS_ENDPOINT'),
127128
'path' => env('NATIVEPHP_UPDATER_PATH', null),
129+
/**
130+
* Optional public URL for serving updates (e.g., CDN or custom domain).
131+
* When set, updates will be downloaded from this URL instead of the S3 endpoint.
132+
* Useful for S3 with CloudFront or Cloudflare R2 with public access
133+
* Example: 'https://updates.yourdomain.com'
134+
*/
135+
'public_url' => env('AWS_PUBLIC_URL'),
128136
],
129137

130138
'spaces' => [

resources/electron/electron-plugin/dist/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,16 @@ class NativePHP {
158158
}
159159
}
160160
startAutoUpdater(config) {
161-
var _a;
161+
var _a, _b, _c, _d, _e;
162162
if (((_a = config === null || config === void 0 ? void 0 : config.updater) === null || _a === void 0 ? void 0 : _a.enabled) === true) {
163+
const defaultProvider = (_b = config === null || config === void 0 ? void 0 : config.updater) === null || _b === void 0 ? void 0 : _b.default;
164+
const publicUrl = (_e = (_d = (_c = config === null || config === void 0 ? void 0 : config.updater) === null || _c === void 0 ? void 0 : _c.providers) === null || _d === void 0 ? void 0 : _d[defaultProvider]) === null || _e === void 0 ? void 0 : _e.public_url;
165+
if (publicUrl) {
166+
autoUpdater.setFeedURL({
167+
provider: 'generic',
168+
url: publicUrl
169+
});
170+
}
163171
autoUpdater.checkForUpdatesAndNotify();
164172
}
165173
}

resources/electron/electron-plugin/src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class NativePHP {
3434
cert: string,
3535
appPath: string
3636
) {
37-
3837
initialize();
3938

4039
state.icon = icon;
@@ -216,6 +215,17 @@ class NativePHP {
216215

217216
private startAutoUpdater(config) {
218217
if (config?.updater?.enabled === true) {
218+
// If a public URL is configured for the current provider, use it for updates
219+
const defaultProvider = config?.updater?.default;
220+
const publicUrl = config?.updater?.providers?.[defaultProvider]?.public_url;
221+
222+
if (publicUrl) {
223+
autoUpdater.setFeedURL({
224+
provider: 'generic',
225+
url: publicUrl
226+
});
227+
}
228+
219229
autoUpdater.checkForUpdatesAndNotify();
220230
}
221231
}

0 commit comments

Comments
 (0)