feat: add option to disable NSFW warning

This commit is contained in:
Hachi-R 2024-11-06 02:57:52 -03:00
parent b09e91a1cf
commit 2f8fe67f9f
6 changed files with 34 additions and 1 deletions

View File

@ -38,6 +38,9 @@ export class UserPreferences {
@Column("boolean", { default: false })
startMinimized: boolean;
@Column("boolean", { default: false })
disableNsfwPopup: boolean;
@CreateDateColumn()
createdAt: Date;

View File

@ -12,6 +12,7 @@ import { CreateUserSubscription } from "./migrations/20241015235142_create_user_
import { AddBackgroundImageUrl } from "./migrations/20241016100249_add_background_image_url";
import { AddWinePrefixToGame } from "./migrations/20241019081648_add_wine_prefix_to_game";
import { AddStartMinimizedColumn } from "./migrations/20241030171454_add_start_minimized_column";
import { AddDisableNsfwPopupColumn } from "./migrations/20241106053733_add_disable_nsfw_popup_column";
export type HydraMigration = Knex.Migration & { name: string };
class MigrationSource implements Knex.MigrationSource<HydraMigration> {
@ -28,6 +29,7 @@ class MigrationSource implements Knex.MigrationSource<HydraMigration> {
AddBackgroundImageUrl,
AddWinePrefixToGame,
AddStartMinimizedColumn,
AddDisableNsfwPopupColumn,
]);
}
getMigrationName(migration: HydraMigration): string {

View File

@ -0,0 +1,17 @@
import type { HydraMigration } from "@main/knex-client";
import type { Knex } from "knex";
export const AddDisableNsfwPopupColumn: HydraMigration = {
name: "AddDisableNsfwPopupColumn",
up: (knex: Knex) => {
return knex.schema.alterTable("user_preferences", (table) => {
return table.boolean("disableNsfwPopup").notNullable().defaultTo(0);
});
},
down: async (knex: Knex) => {
return knex.schema.alterTable("user_preferences", (table) => {
return table.dropColumn("disableNsfwPopup");
});
},
};

View File

@ -147,7 +147,7 @@ export function GameDetailsContextProvider({
if (
result?.content_descriptors.ids.includes(
SteamContentDescriptor.AdultOnlySexualContent
)
) && !userPreferences?.disableNsfwPopup
) {
setHasNSFWContentBlocked(true);
}

View File

@ -18,6 +18,7 @@ export function SettingsBehavior() {
preferQuitInsteadOfHiding: false,
runAtStartup: false,
startMinimized: false,
disableNsfwPopup: false,
});
const { t } = useTranslation("settings");
@ -28,6 +29,7 @@ export function SettingsBehavior() {
preferQuitInsteadOfHiding: userPreferences.preferQuitInsteadOfHiding,
runAtStartup: userPreferences.runAtStartup,
startMinimized: userPreferences.startMinimized,
disableNsfwPopup: userPreferences.disableNsfwPopup,
});
}
}, [userPreferences]);
@ -86,6 +88,14 @@ export function SettingsBehavior() {
/>
</div>
)}
<CheckboxField
label={t("disable_nsfw_popup")}
checked={form.disableNsfwPopup}
onChange={() =>
handleChange({ disableNsfwPopup: !form.disableNsfwPopup })
}
/>
</>
);
}

View File

@ -161,6 +161,7 @@ export interface UserPreferences {
preferQuitInsteadOfHiding: boolean;
runAtStartup: boolean;
startMinimized: boolean;
disableNsfwPopup: boolean;
}
export interface Steam250Game {