Skip to content

Commit

Permalink
- fix for stack overflow when logging joyride onboarding data
Browse files Browse the repository at this point in the history
- fix for mod update time not being tracked regression
  • Loading branch information
Shazbot committed Apr 8, 2024
1 parent d3fb6fe commit 7c162f0
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wh3mm",
"productName": "wh3mm",
"version": "2.3.0",
"version": "2.3.1",
"description": "WH3 Mod Manager",
"main": ".webpack/main",
"scripts": {
Expand Down
51 changes: 45 additions & 6 deletions src/appConfigFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { copy, move } from "fs-extra";
import appData from "./appData";
import * as nodePath from "path";
import { version } from "../package.json";
import { diff } from "deep-object-diff";

let writeConfigTimeout: NodeJS.Timeout;
let dataToWrite: AppStateToWrite | undefined;
let isWriting = false;
let hasConfigBeenRead = false;

const appStateToConfigAppState = (appState: AppState): AppStateToWrite => {
const gameToCurrentPreset = deepClone(appData.gameToCurrentPreset);
Expand Down Expand Up @@ -47,22 +49,59 @@ export function setStartingAppState(startingAppState: AppStateToWrite) {
dataToWrite = deepClone(startingAppState);
}

export function writeAppConfig(data: AppState) {
const toWrite: AppStateToWrite = appStateToConfigAppState(data);
// we don't care about saving this since we want to fetch or calculate the real time state of these anyway
toWrite.gameToCurrentPreset[toWrite.currentGame]?.mods.forEach((mod) => {
const removeModDataWeDontSave = (mods: Mod[] | undefined) => {
if (!mods) return;

// we don't care about saving these since we want to fetch or calculate the real time state of them anyway
for (const mod of mods) {
mod.lastChanged = undefined;
mod.lastChangedLocal = undefined;
mod.reqModIdToName = [];
mod.isDeleted = false;
});
mod.isMovie = false;
mod.dependencyPacks = [];
}
};

if (!appData.hasReadConfig) return;
export function writeAppConfig(data: AppState) {
const toWrite: AppStateToWrite = appStateToConfigAppState(data);

if (!appData.hasReadConfig) {
return;
}

// remove mod data we don't want to save from
removeModDataWeDontSave(toWrite.gameToCurrentPreset[toWrite.currentGame]?.mods);

const onLastGameLaunchPreset = toWrite.gameToPresets[toWrite.currentGame]?.find(
(preset) => preset.name == "On Last Game Launch"
);
removeModDataWeDontSave(onLastGameLaunchPreset?.mods);

const onAppStartPreset = toWrite.gameToPresets[toWrite.currentGame]?.find(
(preset) => preset.name == "On App Start"
);
removeModDataWeDontSave(onAppStartPreset?.mods);

if (!data.hasConfigBeenRead) {
dataToWrite = deepClone(toWrite, true);
console.log("config yet to be read, skip writing new config");
return;
}
if (!hasConfigBeenRead && data.hasConfigBeenRead) {
console.log("CONFIG HAS BEEN READ IN THIS WRITE REQUEST");
hasConfigBeenRead = true;
dataToWrite = deepClone(toWrite, true);
return;
}

if (equal(dataToWrite, toWrite)) {
console.log("same appConfig, don't save it");
return;
}

if (dataToWrite) console.log("diff in config:", JSON.stringify(diff(dataToWrite, toWrite), null, 2));

dataToWrite = deepClone(toWrite, true);

if (writeConfigTimeout) {
Expand Down
7 changes: 6 additions & 1 deletion src/appSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ const appSlice = createSlice({
mod.reqModIdToName = data.reqModIdToName;
}

// if (data.lastChanged && mod.lastChanged != data.lastChanged) mod.lastChanged = data.lastChanged;
if (data.lastChanged && mod.lastChanged != data.lastChanged) mod.lastChanged = data.lastChanged;
}
},
setPackHeaderData: (state: AppState, action: PayloadAction<PackHeaderData | PackHeaderData[]>) => {
Expand Down Expand Up @@ -596,6 +596,7 @@ const appSlice = createSlice({
setFromConfig: (state: AppState, action: PayloadAction<AppStateToRead>) => {
const fromConfigAppState = action.payload;

state.hasConfigBeenRead = true;
state.dataFromConfig = fromConfigAppState;

fromConfigAppState.currentPreset.mods
Expand Down Expand Up @@ -849,6 +850,9 @@ const appSlice = createSlice({
setIsOnboardingToRun: (state: AppState, action: PayloadAction<boolean>) => {
state.isOnboardingToRun = action.payload;
},
setHasConfigBeenRead: (state: AppState, action: PayloadAction<boolean>) => {
state.hasConfigBeenRead = action.payload;
},
setWasOnboardingEverRun: (state: AppState, action: PayloadAction<boolean>) => {
state.wasOnboardingEverRun = action.payload;
},
Expand Down Expand Up @@ -1084,6 +1088,7 @@ export const {
setPacksDataRead,
setPackCollisions,
setAppFolderPaths,
setHasConfigBeenRead,
setWarhammer3Folder,
setContentFolder,
setOverwrittenDataPackedFiles,
Expand Down
44 changes: 22 additions & 22 deletions src/components/Onboarding.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useCallback, useContext, useMemo, useRef } from "react";
import React, { memo, useCallback, useContext, useMemo } from "react";
import Joyride, { Placement, CallBackProps } from "react-joyride";
import { faGrip } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
Expand All @@ -23,100 +23,100 @@ const Onboarding = memo(() => {
[
{
target: "body",
content: localized.onbWelcome,
content: <span className="font-medium">{localized.onbWelcome}</span>,
disableBeacon: true,
placement: "center" as Placement | "auto" | "center",
},
{
target: "#presetSection",
content: localized.onbPresets,
content: <span className="font-medium">{localized.onbPresets}</span>,
},
{
target: "#createOrSelectPreset",
content: (
<>
<span className="font-medium">
<p>{localized.onbPresets1}</p>
<p className="mt-2">{localized.onbPresets2}</p>
<p className="mt-2">{localized.onbPresets3}</p>
</>
</span>
),
},
{
target: "#replacePreset",
content: localized.onbReplacePreset,
content: <span className="font-medium">{localized.onbReplacePreset}</span>,
},
{
target: "#deletePreset",
content: localized.onbDeletePreset,
content: <span className="font-medium">{localized.onbDeletePreset}</span>,
},

{
target: "#sortHeader",
content: (
<>
<span className="font-medium">
<p>{localized.onbSorting1}</p>
<p className="mt-2">{localized.onbSorting2}</p>
</>
</span>
),
},
{
target: "#sortHeader",
content: (
<>
<span className="font-medium">
<p>{localized.onbSorting3}</p>
</>
</span>
),
},
{
target: "#sortHeader",
content: (
<>
<span className="font-medium">
<p>
<FontAwesomeIcon icon={faGrip} /> {localized.onbSorting4}
</p>
<p className="mt-2">{localized.onbSorting5}</p>
<p className="mt-2">{localized.onbSorting6}</p>
</>
</span>
),
},
{
target: "#enabledHeader",
content: (
<>
<span className="font-medium">
<p>{localized.onbSorting7}</p>
<p className="mt-2">{localized.onbSorting8}</p>
<p className="mt-2">{localized.onbSorting9}</p>
</>
</span>
),
},
{
target: "#playGame",
isFixed: true,
placement: "left" as Placement | "auto" | "center",
content: (
<>
<span className="font-medium">
<p>{localized.onbPlay}</p>
</>
</span>
),
},
{
target: "#continueGame",
isFixed: true,
placement: "left" as Placement | "auto" | "center",
content: (
<>
<span className="font-medium">
<p>{localized.onbContinue}</p>
</>
</span>
),
},
{
target: "#showSaves",
isFixed: true,
placement: "left" as Placement | "auto" | "center",
content: (
<>
<span className="font-medium">
<p>{localized.onbSaves}</p>
</>
</span>
),
},
].map((step) => {
Expand All @@ -127,7 +127,7 @@ const Onboarding = memo(() => {
);

const onJoyrideStateChange = useCallback((data: CallBackProps) => {
console.log(data);
console.log("joyride:", data.action);
if (data.action === "reset" || data.action === "skip") {
dispatch(setIsOnboardingToRun(false));
dispatch(setWasOnboardingEverRun(true));
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ declare global {
hiddenMods: Mod[];
saves: GameSave[];
isOnboardingToRun: boolean;
hasConfigBeenRead: boolean;
wasOnboardingEverRun: boolean;
areThumbnailsEnabled: boolean;
isClosedOnPlay: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ declare const VIEWER_PRELOAD_WEBPACK_ENTRY: string;
const gotTheLock = app.requestSingleInstanceLock();

if (!gotTheLock) {
console.log("ONLY ONE INSTANCE ALLOWED!");
app.quit();
} else {
console.log("ARGVS:", process.argv);
Expand Down
1 change: 1 addition & 0 deletions src/initialAppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const initialState = {
hiddenMods: [],
saves: [],
isOnboardingToRun: false,
hasConfigBeenRead: false,
wasOnboardingEverRun: false,
isDev: false,
isAdmin: false,
Expand Down
4 changes: 3 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
setCustomizableMods,
setCurrentGame,
importSteamCollection,
setHasConfigBeenRead,
} from "./appSlice";
import store from "./store";
import { PackCollisions } from "./packFileTypes";
Expand Down Expand Up @@ -160,10 +161,11 @@ window.api?.setAppFolderPaths((event, appFolderPaths: GameFolderPaths) => {
});

window.api?.failedReadingConfig(() => {
console.log("INVOKED: FROM API CONFIG");
console.log("INVOKED: failedReadingConfig");
if (!isSubscribedToStoreChanges) {
store.dispatch(setIsOnboardingToRun(true));
}
store.dispatch(setHasConfigBeenRead(true));

subscribeToStoreChanges();
});
Expand Down

0 comments on commit 7c162f0

Please sign in to comment.