forked from blib-la/captain
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: resources are updated automatically once a new version is relea…
…sed (blib-la#224) ## Motivation * Provides an automated way to handle version updates of Captain * When the resources (like embedded-python) are updated in the manifest, it will show the installer * If no resource changed with an update of Captain, Captain will just open ## Issues closed closes blib-la#216 --------- Co-authored-by: Gregor Adams <1148334+pixelass@users.noreply.github.com>
- Loading branch information
1 parent
e3a5de0
commit 2aab5fb
Showing
47 changed files
with
1,036 additions
and
350 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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,36 @@ | ||
import type { ElectronApplication, Page } from "@playwright/test"; | ||
import { test, expect } from "@playwright/test"; | ||
import { _electron as electron } from "playwright"; | ||
|
||
let electronApp: ElectronApplication; | ||
let page: Page; | ||
|
||
test.beforeAll(async () => { | ||
electronApp = await electron.launch({ | ||
args: ["."], | ||
env: { | ||
...process.env, | ||
TEST_ENV: "test", | ||
TEST_APP_STATUS: "UPDATE", | ||
}, | ||
}); | ||
const isPackaged = await electronApp.evaluate(async ({ app }) => app.isPackaged); | ||
|
||
expect(isPackaged).toBe(false); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await electronApp.close(); | ||
}); | ||
|
||
test("Renders the update page", async () => { | ||
page = await electronApp.firstWindow(); | ||
const title = await page.title(); | ||
expect(title).toBe("Captain"); | ||
}); | ||
|
||
test("Shows the update button", async () => { | ||
page = await electronApp.firstWindow(); | ||
|
||
await expect(page.getByTestId("installer-02-start")).toBeVisible(); | ||
}); |
This file contains 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
This file contains 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
This file contains 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,79 @@ | ||
import { DownloadState } from "@captn/utils/constants"; | ||
import type { Progress } from "electron-dl"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
|
||
import { buildKey } from "#/build-key"; | ||
import { ID } from "#/enums"; | ||
|
||
export function useInstallProgress({ state }: { state: DownloadState }) { | ||
const [status, setStatus] = useState(state); | ||
const [error, setError] = useState(""); | ||
const [name, setName] = useState(""); | ||
const [size, setSize] = useState(""); | ||
const [progress, setProgress] = useState<Progress>({ | ||
percent: 0, | ||
transferredBytes: 0, | ||
totalBytes: 0, | ||
}); | ||
const reset = useCallback(() => { | ||
setProgress({ | ||
percent: 0, | ||
transferredBytes: 0, | ||
totalBytes: 0, | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const unsubscribeStarted = window.ipc.on( | ||
buildKey([ID.INSTALL], { suffix: ":started" }), | ||
({ name, size }) => { | ||
setStatus(DownloadState.ACTIVE); | ||
setName(name); | ||
setSize(size); | ||
setError(""); | ||
} | ||
); | ||
const unsubscribeProgress = window.ipc.on( | ||
buildKey([ID.INSTALL], { suffix: ":progress" }), | ||
(progress: Progress) => { | ||
setStatus(DownloadState.ACTIVE); | ||
setProgress(progress); | ||
} | ||
); | ||
const unsubscribeCancelled = window.ipc.on( | ||
buildKey([ID.INSTALL], { suffix: ":canceled" }), | ||
() => { | ||
setStatus(DownloadState.CANCELED); | ||
} | ||
); | ||
const unsubscribeCompleted = window.ipc.on( | ||
buildKey([ID.INSTALL], { suffix: ":completed" }), | ||
() => { | ||
setStatus(DownloadState.DONE); | ||
} | ||
); | ||
const unsubscribeUnpacking = window.ipc.on( | ||
buildKey([ID.INSTALL], { suffix: ":unpacking" }), | ||
() => { | ||
setStatus(DownloadState.UNPACKING); | ||
} | ||
); | ||
const unsubscribeFailed = window.ipc.on( | ||
buildKey([ID.INSTALL], { suffix: ":failed" }), | ||
message => { | ||
setStatus(DownloadState.FAILED); | ||
setError(message); | ||
} | ||
); | ||
|
||
return () => { | ||
unsubscribeStarted(); | ||
unsubscribeProgress(); | ||
unsubscribeCancelled(); | ||
unsubscribeCompleted(); | ||
unsubscribeUnpacking(); | ||
unsubscribeFailed(); | ||
}; | ||
}, []); | ||
return { status, progress, name, size, error, reset }; | ||
} |
This file contains 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,35 @@ | ||
import Box from "@mui/joy/Box"; | ||
import Typography from "@mui/joy/Typography"; | ||
import type { ReactNode } from "react"; | ||
|
||
import { Illustration } from "@/organisms/illustration"; | ||
|
||
export function InstallStep({ | ||
illustration, | ||
heading, | ||
children, | ||
}: { | ||
illustration: string; | ||
heading: string; | ||
children?: ReactNode; | ||
}) { | ||
return ( | ||
<> | ||
<Illustration height={200} path={illustration} /> | ||
<Typography level="h1" sx={{ my: 2, textAlign: "center" }}> | ||
{heading} | ||
</Typography> | ||
<Box | ||
sx={{ | ||
flex: 1, | ||
display: "flex", | ||
flexDirection: "column", | ||
justifyContent: "center", | ||
mx: 8, | ||
}} | ||
> | ||
{children} | ||
</Box> | ||
</> | ||
); | ||
} |
This file contains 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
This file contains 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.