Skip to content

Commit

Permalink
fix/add-context-menu: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
guibzo committed May 23, 2024
1 parent 440cf70 commit aa6be6b
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 124 deletions.
6 changes: 2 additions & 4 deletions src/locales/pl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"delete_installation_files": "Usuń pliki instalacyjne",
"change_exe_path": "Zmień ścieżkę wykonywalną",
"open_archive_path": "Otwórz lokalizację pliku",
"game_executable": "Plik wykonywalny gry"
"home": "Główna",
"game_executable": "Plik wykonywalny gry",
"discord": "Dołącz nasz Discord",
"telegram": "Dołącz nasz Telegram",
"x": "Śledź na X",
Expand Down Expand Up @@ -92,7 +91,6 @@
"change": "Zmień",
"repacks_modal_description": "Wybierz repack, który chcesz pobrać",
"select_folder_hint": "Aby zmienić domyślny folder, przejdź do",
"download_now": "Pobierz teraz",
"installation_instructions": "Instrukcja instalacji",
"installation_instructions_description": "Do zainstalowania tej gry wymagane są dodatkowe kroki",
"online_fix_instruction": "Gry OnlineFix wymagają hasła do wyodrębnienia. W razie potrzeby użyj następującego hasła:",
Expand All @@ -107,7 +105,7 @@
"previous_screenshot": "Poprzedni zrzut ekranu",
"next_screenshot": "Następny zrzut ekranu",
"screenshot": "Zrzut ekranu {{number}}",
"open_screenshot": "Otwórz zrzut ekranu {{number}}"
"open_screenshot": "Otwórz zrzut ekranu {{number}}",
"settings": "Ustawienia Hydra",
"download_now": "Pobierz teraz",
"game_executable": "Plik wykonywalny gry"
Expand Down
2 changes: 1 addition & 1 deletion src/locales/ru/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"behavior": "Поведение",
"enable_real_debrid": "Включить Real Debrid",
"real_debrid": "Real Debrid",
"real_debrid_api_token_hint": "API ключ можно получить <0>здесь</0>.",,
"real_debrid_api_token_hint": "API ключ можно получить <0>здесь</0>.",
"save_changes": "Сохранить изменения"
},
"notifications": {
Expand Down
4 changes: 1 addition & 3 deletions src/main/events/library/change-executable-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ const changeExecutablePath = async (
);
};

registerEvent(changeExecutablePath, {
name: "changeExecutablePath",
});
registerEvent("changeExecutablePath", changeExecutablePath);
4 changes: 1 addition & 3 deletions src/main/events/library/open-game-folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,4 @@ const openGameFolder = async (
shell.openPath(gamePath);
};

registerEvent(openGameFolder, {
name: "openGameFolder",
});
registerEvent("openGameFolder", openGameFolder);
1 change: 1 addition & 0 deletions src/renderer/src/assets/discord-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions src/renderer/src/components/sidebar/sidebar.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,36 @@ export const contextMenuItemIcon = style({
width: "14px",
height: "14px",
});

export const sidebarFooter = style({
marginTop: "auto",
padding: `${SPACING_UNIT * 2}px`,
display: "flex",
alignItems: "center",
justifyContent: "space-between",
});

export const footerSocialsContainer = style({
display: "flex",
alignItems: "center",
gap: `${SPACING_UNIT * 1.5}px`,
});

export const footerSocialsItem = style({
color: vars.color.bodyText,
backgroundColor: vars.color.darkBackground,
width: "16px",
height: "16px",
display: "flex",
alignItems: "center",
transition: "all ease 0.2s",
cursor: "pointer",
":hover": {
opacity: "0.75",
},
});

export const footerText = style({
color: vars.color.bodyText,
fontSize: "12px",
});
173 changes: 68 additions & 105 deletions src/renderer/src/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,71 @@ import { useDownload, useLibrary } from "@renderer/hooks";

import { routes } from "./routes";


import {
FileDirectoryIcon,
FileDirectorySymlinkIcon,
MarkGithubIcon,
TrashIcon,
} from "@primer/octicons-react";
import { GameStatus, GameStatusHelper } from "@shared";
import { DeleteModal } from "./delete-modal";
import * as styles from "./sidebar.css";

import DiscordLogo from "@renderer/assets/discord-icon.svg?react";
import SteamLogo from "@renderer/assets/steam-logo.svg?react";
import XLogo from "@renderer/assets/x-icon.svg?react";

const SIDEBAR_MIN_WIDTH = 200;
const SIDEBAR_INITIAL_WIDTH = 250;
const SIDEBAR_MAX_WIDTH = 450;

const initialSidebarWidth = window.localStorage.getItem("sidebarWidth");

export function Sidebar() {
const navigate = useNavigate();
const location = useLocation();
const { t } = useTranslation("sidebar");
const { library, updateLibrary } = useLibrary();
const navigate = useNavigate();
const { game: gameDownloading, progress } = useDownload();

const [filteredLibrary, setFilteredLibrary] = useState<Game[]>([]);

const [isResizing, setIsResizing] = useState(false);
const [sidebarWidth, setSidebarWidth] = useState(
initialSidebarWidth ? Number(initialSidebarWidth) : SIDEBAR_INITIAL_WIDTH
);

const [isContextMenuOpen, setIsContextMenuOpen] = useState(false);
const [axisCoordinates, setAxisCoordinates] = useState({
x: 0,
y: 0,
});

const [showDeleteModal, setShowDeleteModal] = useState(false);
const [currentGame, setCurrentGame] = useState<Game>();

const location = useLocation();

const { game: gameDownloading, progress } = useDownload();
const sidebarRef = useRef<HTMLElement>(null);
const cursorPos = useRef({ x: 0 });
const sidebarInitialWidth = useRef(0);

const isDownloading = library.some((game) =>
GameStatusHelper.isDownloading(game.status)
);

const sidebarRef = useRef<HTMLElement>(null);

const cursorPos = useRef({ x: 0 });
const sidebarInitialWidth = useRef(0);
const socials = [
{
url: "https://discord.gg/hydralauncher",
icon: <DiscordLogo />,
label: t("discord"),
},
{
url: "https://twitter.com/hydralauncher",
icon: <XLogo />,
label: t("x"),
},
{
url: "https://github.com/hydralauncher/hydra",
icon: <MarkGithubIcon size={16} />,
label: t("github"),
},
];

const selectGameExecutable = async () => {
const { filePaths } = await window.electron.showOpenDialog({
Expand Down Expand Up @@ -97,6 +119,28 @@ export function Sidebar() {
updateLibrary();
});

const getGameTitle = (game: Game) => {
if (game.status === GameStatus.Paused)
return t("paused", { title: game.title });

if (gameDownloading?.id === game.id) {
const isVerifying = GameStatusHelper.isVerifying(gameDownloading.status);

if (isVerifying)
return t(gameDownloading.status!, {
title: game.title,
percentage: progress,
});

return t("downloading", {
title: game.title,
percentage: progress,
});
}

return game.title;
};

const handleMouseDown: React.MouseEventHandler<HTMLButtonElement> = (
event
) => {
Expand All @@ -121,29 +165,6 @@ export function Sidebar() {
setIsContextMenuOpen(false);
};

const getGameTitle = (game: Game) => {
if (game.status === "paused") return t("paused", { title: game.title });

if (gameDownloading?.id === game.id) {
const isVerifying = ["downloading_metadata", "checking_files"].includes(
gameDownloading?.status
);

if (isVerifying)
return t(gameDownloading.status, {
title: game.title,
percentage: progress,
});

return t("downloading", {
title: game.title,
percentage: progress,
});
}

return game.title;
};

const handleSidebarItemClick = (path: string) => {
if (path !== location.pathname) {
navigate(path);
Expand Down Expand Up @@ -193,33 +214,6 @@ export function Sidebar() {
window.removeEventListener("click", handleClick);
};
}, []);
const getGameTitle = (game: Game) => {
if (game.status === GameStatus.Paused)
return t("paused", { title: game.title });

if (gameDownloading?.id === game.id) {
const isVerifying = GameStatusHelper.isVerifying(gameDownloading.status);

if (isVerifying)
return t(gameDownloading.status!, {
title: game.title,
percentage: progress,
});

return t("downloading", {
title: game.title,
percentage: progress,
});
}

return game.title;
};

const handleSidebarItemClick = (path: string) => {
if (path !== location.pathname) {
navigate(path);
}
};

return (
<>
Expand Down Expand Up @@ -300,11 +294,16 @@ export function Sidebar() {
)
}
>
<img
className={styles.gameIcon}
src={game.iconUrl}
alt={game.title}
/>
{game.iconUrl ? (
<img
className={styles.gameIcon}
src={game.iconUrl}
alt={game.title}
/>
) : (
<SteamLogo className={styles.gameIcon} />
)}

<span className={styles.menuItemButtonLabel}>
{getGameTitle(game)}
</span>
Expand Down Expand Up @@ -384,42 +383,6 @@ export function Sidebar() {
/>
</section>
</div>
<ul className={styles.menu}>
{filteredLibrary.map((game) => (
<li
key={game.id}
className={styles.menuItem({
active:
location.pathname === `/game/${game.shop}/${game.objectID}`,
muted: game.status === GameStatus.Cancelled,
})}
>
<button
type="button"
className={styles.menuItemButton}
onClick={() =>
handleSidebarItemClick(buildGameDetailsPath(game))
}
>
{game.iconUrl ? (
<img
className={styles.gameIcon}
src={game.iconUrl}
alt={game.title}
/>
) : (
<SteamLogo className={styles.gameIcon} />
)}

<span className={styles.menuItemButtonLabel}>
{getGameTitle(game)}
</span>
</button>
</li>
))}
</ul>
</section>
</div>

<button
type="button"
Expand Down Expand Up @@ -447,12 +410,12 @@ export function Sidebar() {
</span>
</footer>
</aside>
</>

<button
type="button"
className={styles.handle}
onMouseDown={handleMouseDown}
/>
</aside>
</>
);
}
2 changes: 1 addition & 1 deletion src/renderer/src/declaration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ declare global {
executablePath: string | null
) => Promise<void>;
getLibrary: () => Promise<Game[]>;
openGameFolder: (gameId: number) => Promise<boolean>;
openGameFolder: (gameId: number) => Promise<void | boolean>;
openGameInstaller: (gameId: number) => Promise<boolean>;
openGame: (gameId: number, executablePath: string) => Promise<void>;
changeExecutablePath: (
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/hooks/use-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import {
setLastPacket,
} from "@renderer/features";
import { formatDownloadProgress } from "@renderer/helpers";
import { formatBytes } from "@renderer/utils";
import { GameStatus, GameStatusHelper, formatBytes } from "@shared";
import type { GameShop, TorrentProgress } from "@types";
import { useAppDispatch, useAppSelector } from "./redux";
import { useDate } from "./use-date";
import { useLibrary } from "./use-library";

export function useDownload() {
const { updateLibrary } = useLibrary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ export function HeroPanelActions({

const { t } = useTranslation("game_details");

const getDownloadsPath = async () => {
const userPreferences = await window.electron.getUserPreferences();
if (userPreferences?.downloadsPath) return userPreferences.downloadsPath;
return window.electron.getDefaultDownloadsPath();
};

const selectGameExecutable = async () => {
const { filePaths } = await window.electron.showOpenDialog({
properties: ["openFile"],
Expand Down

0 comments on commit aa6be6b

Please sign in to comment.