-
-
Notifications
You must be signed in to change notification settings - Fork 85
Add auto-updater API to Electron server #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WINBIGFOX
wants to merge
6
commits into
NativePHP:main
Choose a base branch
from
WINBIGFOX:add-auto-updater-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
16c233e
Add auto-updater API to Electron server
WINBIGFOX 1920ff6
Merge remote-tracking branch 'origin/main' into add-auto-updater-api
WINBIGFOX 00ce033
Add download-progress listener to autoUpdater
WINBIGFOX 1de495c
Update api.test.ts
WINBIGFOX 3b68c51
Refactor electron-updater imports for consistency and clarity
WINBIGFOX 63326ae
Merge remote-tracking branch 'origin/add-auto-updater-api' into add-a…
WINBIGFOX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
resources/js/electron-plugin/dist/server/api/autoUpdater.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import express from "express"; | ||
import { autoUpdater } from "electron-updater"; | ||
import { notifyLaravel } from "../utils.js"; | ||
const router = express.Router(); | ||
router.post("/check-for-updates", (req, res) => { | ||
autoUpdater.checkForUpdates(); | ||
res.sendStatus(200); | ||
}); | ||
router.post("/quit-and-install", (req, res) => { | ||
autoUpdater.quitAndInstall(); | ||
res.sendStatus(200); | ||
}); | ||
autoUpdater.addListener("checking-for-update", () => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\CheckingForUpdate`, | ||
}); | ||
}); | ||
autoUpdater.addListener("update-available", () => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\UpdateAvailable`, | ||
}); | ||
}); | ||
autoUpdater.addListener("update-not-available", () => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\UpdateNotAvailable`, | ||
}); | ||
}); | ||
autoUpdater.addListener("error", (error) => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\Error`, | ||
payload: { | ||
error: error, | ||
}, | ||
}); | ||
}); | ||
autoUpdater.addListener("download-progress", (progressInfo) => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\DownloadProgress`, | ||
payload: { | ||
total: progressInfo.total, | ||
delta: progressInfo.delta, | ||
transferred: progressInfo.transferred, | ||
percent: progressInfo.percent, | ||
bytesPerSecond: progressInfo.bytesPerSecond, | ||
}, | ||
}); | ||
}); | ||
autoUpdater.addListener("update-downloaded", (event) => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\UpdateDownloaded`, | ||
payload: { | ||
version: event.version, | ||
downloadedFile: event.downloadedFile, | ||
releaseDate: event.releaseDate, | ||
releaseNotes: event.releaseNotes, | ||
releaseName: event.releaseName, | ||
}, | ||
}); | ||
}); | ||
export default router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
resources/js/electron-plugin/src/server/api/autoUpdater.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import express from "express"; | ||
import { autoUpdater } from "electron-updater"; | ||
import type { ProgressInfo, UpdateDownloadedEvent } from "electron-updater"; | ||
import { notifyLaravel } from "../utils.js"; | ||
|
||
const router = express.Router(); | ||
|
||
router.post("/check-for-updates", (req, res) => { | ||
autoUpdater.checkForUpdates(); | ||
res.sendStatus(200); | ||
}); | ||
|
||
router.post("/quit-and-install", (req, res) => { | ||
autoUpdater.quitAndInstall(); | ||
res.sendStatus(200); | ||
}); | ||
|
||
autoUpdater.addListener("checking-for-update", () => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\CheckingForUpdate`, | ||
}); | ||
}); | ||
|
||
autoUpdater.addListener("update-available", () => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\UpdateAvailable`, | ||
}); | ||
}); | ||
|
||
autoUpdater.addListener("update-not-available", () => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\UpdateNotAvailable`, | ||
}); | ||
}); | ||
|
||
autoUpdater.addListener("error", (error) => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\Error`, | ||
payload: { | ||
error: error, | ||
}, | ||
}); | ||
}); | ||
|
||
autoUpdater.addListener("download-progress", (progressInfo: ProgressInfo) => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\DownloadProgress`, | ||
payload: { | ||
total: progressInfo.total, | ||
delta: progressInfo.delta, | ||
transferred: progressInfo.transferred, | ||
percent: progressInfo.percent, | ||
bytesPerSecond: progressInfo.bytesPerSecond, | ||
}, | ||
}); | ||
}); | ||
|
||
autoUpdater.addListener("update-downloaded", (event: UpdateDownloadedEvent) => { | ||
notifyLaravel("events", { | ||
event: `\\Native\\Laravel\\Events\\AutoUpdater\\UpdateDownloaded`, | ||
payload: { | ||
version: event.version, | ||
downloadedFile: event.downloadedFile, | ||
releaseDate: event.releaseDate, | ||
releaseNotes: event.releaseNotes, | ||
releaseName: event.releaseName, | ||
}, | ||
}); | ||
}); | ||
|
||
export default router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea: If you add a guard clause here you might be able to prevent the download from happening multiple times.
Set a Boolean & make sure to reset it when the download finishes/fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's such a bad idea, but I don't know how reliably it will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it def needs some manual testing. We can always add it later if we want. What do you think @SRWieZ ?