-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix outdated mod being installed again, improve updating in general
- Loading branch information
1 parent
0128f73
commit 482760b
Showing
8 changed files
with
131 additions
and
82 deletions.
There are no files selected for viewing
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,94 @@ | ||
import { Tooltip } from "@mantine/core"; | ||
import { | ||
ModLoaderData, | ||
downloadMod, | ||
installMod, | ||
uninstallMod, | ||
} from "@api/bindings"; | ||
import { CommandButton } from "@components/command-button"; | ||
import { IconTool, IconTrash } from "@tabler/icons-react"; | ||
import { UnifiedMod } from "@hooks/use-unified-mods"; | ||
import { getIsOutdated } from "../../util/is-outdated"; | ||
import { OutdatedMarker } from "@components/OutdatedMarker"; | ||
import { ProcessedInstalledGame } from "@hooks/use-processed-installed-games"; | ||
import { useCallback } from "react"; | ||
import { MutedText } from "@components/muted-text"; | ||
|
||
type Props = { | ||
readonly game: ProcessedInstalledGame; | ||
readonly mod: UnifiedMod; | ||
readonly modLoader: ModLoaderData; | ||
}; | ||
|
||
export function GameModButton(props: Props) { | ||
const installedVersion = props.game.installedModVersions[props.mod.common.id]; | ||
const isInstalledModOutdated = getIsOutdated( | ||
installedVersion, | ||
props.mod.remote?.latestVersion?.id, | ||
); | ||
const isLocalModOutdated = getIsOutdated( | ||
props.mod.local?.manifest?.version, | ||
props.mod.remote?.latestVersion?.id, | ||
); | ||
const isInstalled = Boolean(installedVersion); | ||
|
||
const handleClick = useCallback(async () => { | ||
if (isLocalModOutdated) { | ||
await downloadMod(props.mod.common.id); | ||
} else if (isInstalled && !isInstalledModOutdated) { | ||
await uninstallMod(props.game.id, props.mod.common.id); | ||
return; | ||
} | ||
|
||
await installMod(props.game.id, props.mod.common.id); | ||
}, [ | ||
isInstalled, | ||
isLocalModOutdated, | ||
isInstalledModOutdated, | ||
props.game.id, | ||
props.mod.common.id, | ||
]); | ||
|
||
const versionText = | ||
!isInstalled || isInstalledModOutdated | ||
? props.mod.remote?.latestVersion?.id | ||
: installedVersion; | ||
|
||
function getActionText() { | ||
if (isInstalledModOutdated) return "Update"; | ||
if (isInstalled) return "Uninstall"; | ||
if (props.modLoader.kind === "Installable") return "Install"; | ||
return "Run"; | ||
} | ||
|
||
function getIcon() { | ||
if (isInstalledModOutdated) return <OutdatedMarker />; | ||
if (isInstalled) return <IconTrash />; | ||
return <IconTool />; | ||
} | ||
|
||
return ( | ||
<Tooltip | ||
disabled={!isInstalledModOutdated} | ||
label="Mod outdated. Click to update." | ||
key={props.mod.common.id} | ||
> | ||
<CommandButton | ||
leftSection={getIcon()} | ||
confirmationText={ | ||
isInstalled | ||
? undefined | ||
: "Attention: be careful when installing mods on multiplayer games! Anticheat can detect some mods and get you banned, even if the mods seem harmless." | ||
} | ||
confirmationSkipId={isInstalled ? undefined : "install-mod-confirm"} | ||
onClick={handleClick} | ||
> | ||
{getActionText()} {props.mod.remote?.title ?? props.mod.common.id} | ||
{versionText && <MutedText>({versionText})</MutedText>} | ||
{!props.game.executable.engine && ( | ||
<MutedText>({props.mod.common.engine})</MutedText> | ||
)} | ||
</CommandButton> | ||
</Tooltip> | ||
); | ||
} |
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,16 @@ | ||
import { Text } from "@mantine/core"; | ||
|
||
type Props = { | ||
readonly children: React.ReactNode; | ||
}; | ||
|
||
export function MutedText(props: Props) { | ||
return ( | ||
<Text | ||
size="sm" | ||
opacity={0.5} | ||
> | ||
{props.children} | ||
</Text> | ||
); | ||
} |
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