Skip to content

Commit

Permalink
Move recent projects path parsing into main process to fix display on…
Browse files Browse the repository at this point in the history
… Windows
  • Loading branch information
chrismaltby committed Apr 2, 2024
1 parent 319c46b commit 1a2748c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
19 changes: 3 additions & 16 deletions src/components/app/Splash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,10 @@ import useWindowFocus from "ui/hooks/use-window-focus";
import l10n from "shared/lib/lang/l10n";
import API from "renderer/lib/api";
import { ERR_PROJECT_EXISTS } from "consts";
import type { RecentProjectData } from "renderer/lib/api/setup";

declare const DOCS_URL: string;

type ProjectInfo = {
name: string;
dir: string;
path: string;
};

type TemplateInfo = {
id: string;
name: string;
Expand Down Expand Up @@ -93,7 +88,7 @@ export const Splash = () => {
const [templateId, setTemplateId] = useState("gbs2");
const [section, setSection] = useState<SplashTabSection>();
const [openCredits, setOpenCredits] = useState(false);
const [recentProjects, setRecentProjects] = useState<ProjectInfo[]>([]);
const [recentProjects, setRecentProjects] = useState<RecentProjectData[]>([]);
const [name, setName] = useState<string>(l10n("SPLASH_DEFAULT_PROJECT_NAME"));
const [path, setPath] = useState<string>("");
const [nameError, setNameError] = useState("");
Expand All @@ -103,15 +98,7 @@ export const Splash = () => {

useEffect(() => {
async function fetchData() {
setRecentProjects(
(await API.project.getRecentProjects())
.map((projectPath) => ({
name: Path.basename(projectPath),
dir: Path.dirname(projectPath),
path: projectPath,
}))
.reverse()
);
setRecentProjects((await API.project.getRecentProjects()).reverse());
setPath(await getLastUsedPath());
const urlParams = new URLSearchParams(window.location.search);
const forceTab = urlParams.get("tab");
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/splash/Splash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ export const SplashProjectClearButton = styled.div`
export interface SplashProjectProps {
project: {
name: string;
path: string;
dir: string;
};
onClick: () => void;
}
Expand Down Expand Up @@ -636,7 +636,7 @@ export const SplashProject: FC<SplashProjectProps> = ({ project, onClick }) => (
<img src={projectIcon} alt="" />
<SplashProjectDetails>
<SplashProjectName>{project.name}</SplashProjectName>
<SplashProjectPath>{project.path}</SplashProjectPath>
<SplashProjectPath>{project.dir}</SplashProjectPath>
</SplashProjectDetails>
</SplashProjectWrapper>
);
14 changes: 11 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import open from "open";
import confirmEnableColorDialog from "lib/electron/dialog/confirmEnableColorDialog";
import confirmDeleteCustomEvent from "lib/electron/dialog/confirmDeleteCustomEvent";
import type { ProjectData } from "store/features/project/projectActions";
import type { BuildOptions } from "renderer/lib/api/setup";
import type { BuildOptions, RecentProjectData } from "renderer/lib/api/setup";
import buildProject from "lib/compiler/buildProject";
import copy from "lib/helpers/fsCopy";
import confirmEjectEngineDialog from "lib/electron/dialog/confirmEjectEngineDialog";
Expand Down Expand Up @@ -674,10 +674,18 @@ ipcMain.handle("project:open-project-picker", async (_event, _arg) => {
openProjectPicker();
});

ipcMain.handle("get-recent-projects", async () => {
ipcMain.handle("get-recent-projects", async (): Promise<
RecentProjectData[]
> => {
const recentProjects = settings.get("recentProjects");
if (!isStringArray(recentProjects)) return [];
return recentProjects;
return recentProjects.map((path) => {
return {
name: Path.basename(path),
dir: Path.dirname(path),
path,
};
});
});

ipcMain.handle("clear-recent-projects", async (_event) => {
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/lib/api/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export type BuildOptions = {
debugEnabled?: boolean;
};

export type RecentProjectData = {
name: string;
dir: string;
path: string;
};

const createSubscribeAPI = <
// eslint-disable-next-line @typescript-eslint/no-explicit-any
T extends (event: IpcRendererEvent, ...args: any[]) => void
Expand Down Expand Up @@ -161,7 +167,7 @@ const APISetup = {
ipcRenderer.invoke("dialog:migrate-warning", path),
},
project: {
getRecentProjects: (): Promise<string[]> =>
getRecentProjects: (): Promise<RecentProjectData[]> =>
ipcRenderer.invoke("get-recent-projects"),
clearRecentProjects: () => ipcRenderer.invoke("clear-recent-projects"),
openProjectPicker: () => ipcRenderer.invoke("project:open-project-picker"),
Expand Down

0 comments on commit 1a2748c

Please sign in to comment.