Skip to content

Commit

Permalink
fix: auto apply blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
std-microblock committed Feb 15, 2024
1 parent d4ea504 commit 9e2770b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
Binary file modified resources/dist.rc
Binary file not shown.
1 change: 1 addition & 0 deletions src/celemod-ui/src/context/blacklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const createBlacklistContext = () => {

const ctx = {
switchProfile: (name: string) => {
console.log('switch to profile', name);
callRemote('apply_blacklist_profile', gamePath, name, JSON.stringify(alwaysOnMods));
setCurrentProfileName(name);
},
Expand Down
51 changes: 25 additions & 26 deletions src/celemod-ui/src/routes/Manage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,20 @@ const ModMissing = ({ name, version, optional }: MissingModDepInfo) => {
onClick={
gbFileID !== null
? async () => {
setState(_i18n.t('下载中'));
download.downloadMod(name, gbFileID, {
onProgress: (task, progress) => {
setState(`${progress}% (${task.subtasks.length})`);
},
onFinished: () => {
setState(_i18n.t('下载完成'));
ctx?.reloadMods();
},
onFailed: () => {
setState(_i18n.t('下载失败'));
},
});
}
setState(_i18n.t('下载中'));
download.downloadMod(name, gbFileID, {
onProgress: (task, progress) => {
setState(`${progress}% (${task.subtasks.length})`);
},
onFinished: () => {
setState(_i18n.t('下载完成'));
ctx?.reloadMods();
},
onFailed: () => {
setState(_i18n.t('下载失败'));
},
});
}
: undefined
}
>
Expand Down Expand Up @@ -208,9 +208,8 @@ const ModLocal = ({
return (
<div className={`m-mod ${enabled && 'enabled'}`}>
<span
className={`expandBtn ${expanded && 'expanded'} ${
hasDeps && 'clickable'
}`}
className={`expandBtn ${expanded && 'expanded'} ${hasDeps && 'clickable'
}`}
onClick={() => setExpanded(!expanded)}
>
{hasDeps && (!optional || ctx?.fullTree) ? (
Expand All @@ -236,8 +235,8 @@ const ModLocal = ({
{isAlwaysOn
? _i18n.t('始终开启')
: enabled
? _i18n.t('已启用')
: _i18n.t('已禁用')}
? _i18n.t('已启用')
: _i18n.t('已禁用')}
</ModBadge>

{enabled &&
Expand Down Expand Up @@ -361,7 +360,7 @@ let lastApplyReq = -1;
export const Manage = () => {
const noEverest = enforceEverest();
if (noEverest) return noEverest;

const [alwaysOnMods, setAlwaysOnMods] = useAlwaysOnMods();
const [gamePath] = useGamePath();
const modPath = gamePath + '/Mods';

Expand Down Expand Up @@ -536,6 +535,7 @@ export const Manage = () => {
.toLowerCase()
.trim();

// console.log(name, nameFilter);
if (!name.includes(nameFilter)) return false;

const checkSpecialFilter = (arg: string) => {
Expand All @@ -545,9 +545,9 @@ export const Manage = () => {

if (!('_missing' in mod)) {
if (arg.startsWith('enable')) {
return mod.enabled;
return mod.enabled || alwaysOnMods.includes(mod.name);
} else if (arg.startsWith('disable')) {
return !mod.enabled;
return !checkSpecialFilter('enable');
}

if (arg.startsWith('hasdep') || arg.startsWith('havedep')) {
Expand Down Expand Up @@ -622,8 +622,6 @@ export const Manage = () => {
// @ts-ignore
modsTreeRef.current?.scrollTo(0, 0);
}, [excludeDependents]);

const [alwaysOnMods, setAlwaysOnMods] = useAlwaysOnMods();
const globalCtx = useGlobalContext();
const manageCtx = useMemo(
() => ({
Expand Down Expand Up @@ -666,9 +664,10 @@ export const Manage = () => {
setHasUnsavedChanges(true);

lastApplyReq = Date.now();
let thisReq = lastApplyReq;
setTimeout(() => {
if (lastApplyReq === Date.now()) {
manageCtx.switchProfile(manageCtx.currentProfileName);
if (lastApplyReq === thisReq) {
globalCtx.blacklist.switchProfile(manageCtx.currentProfileName);
setHasUnsavedChanges(false);
}
}, 600);
Expand Down

0 comments on commit 9e2770b

Please sign in to comment.