mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-05-12 13:03:31 -04:00
feat: Remember screen lock preference (#7609)
This commit is contained in:
@@ -14,17 +14,25 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useWakeLock } from "@vueuse/core";
|
||||
import { useUserExperiencePreferences } from "~/composables/use-users/preferences";
|
||||
|
||||
const { isSupported: wakeIsSupported, isActive, request, release } = useWakeLock();
|
||||
const userExperiencePreferences = useUserExperiencePreferences();
|
||||
|
||||
function handleLock() {
|
||||
if (userExperiencePreferences.value.lockScreen) {
|
||||
lockScreen();
|
||||
}
|
||||
else {
|
||||
unlockScreen();
|
||||
}
|
||||
}
|
||||
|
||||
const wakeLock = computed({
|
||||
get: () => isActive.value,
|
||||
get: () => userExperiencePreferences.value.lockScreen,
|
||||
set: () => {
|
||||
if (isActive.value) {
|
||||
unlockScreen();
|
||||
}
|
||||
else {
|
||||
lockScreen();
|
||||
}
|
||||
userExperiencePreferences.value.lockScreen = !userExperiencePreferences.value.lockScreen;
|
||||
handleLock();
|
||||
},
|
||||
});
|
||||
async function lockScreen() {
|
||||
@@ -34,11 +42,11 @@ async function lockScreen() {
|
||||
}
|
||||
}
|
||||
async function unlockScreen() {
|
||||
if (wakeIsSupported || isActive) {
|
||||
if (wakeIsSupported || isActive.value) {
|
||||
console.debug("Wake Lock Released");
|
||||
await release();
|
||||
}
|
||||
}
|
||||
onMounted(() => lockScreen());
|
||||
onMounted(() => handleLock());
|
||||
onUnmounted(() => unlockScreen());
|
||||
</script>
|
||||
|
||||
@@ -73,6 +73,10 @@ export interface UserActivityPreferences {
|
||||
defaultActivity: ActivityKey;
|
||||
}
|
||||
|
||||
export interface UserExperiencePreferences {
|
||||
lockScreen: boolean;
|
||||
}
|
||||
|
||||
export function useUserMealPlanPreferences(): Ref<UserMealPlanPreferences> {
|
||||
const fromStorage = useLocalStorage(
|
||||
"meal-planner-preferences",
|
||||
@@ -81,9 +85,7 @@ export function useUserMealPlanPreferences(): Ref<UserMealPlanPreferences> {
|
||||
numberOfDays: 7,
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as unknown as Ref<UserMealPlanPreferences>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
@@ -92,15 +94,14 @@ export function useUserPrintPreferences(): Ref<UserPrintPreferences> {
|
||||
const fromStorage = useLocalStorage(
|
||||
"recipe-print-preferences",
|
||||
{
|
||||
imagePosition: "left",
|
||||
imagePosition: "left" as ImagePosition,
|
||||
showDescription: true,
|
||||
showNotes: true,
|
||||
showNutrition: false,
|
||||
expandChildRecipes: false,
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as unknown as Ref<UserPrintPreferences>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
@@ -118,9 +119,7 @@ export function useUserSortPreferences(): Ref<UserRecipePreferences> {
|
||||
useMobileCards: false,
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as unknown as Ref<UserRecipePreferences>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
@@ -132,9 +131,7 @@ export function useUserActivityPreferences(): Ref<UserActivityPreferences> {
|
||||
defaultActivity: ActivityKey.RECIPES,
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as Ref<UserActivityPreferences>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
@@ -146,9 +143,7 @@ export function useUserSearchQuerySession(): Ref<UserSearchQuery> {
|
||||
recipe: "",
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as unknown as Ref<UserSearchQuery>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
@@ -160,9 +155,7 @@ export function useShoppingListPreferences(): Ref<UserShoppingListPreferences> {
|
||||
viewAllLists: false,
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as unknown as Ref<UserShoppingListPreferences>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
@@ -175,9 +168,7 @@ export function useTimelinePreferences(): Ref<UserTimelinePreferences> {
|
||||
types: ["info", "system", "comment"] as TimelineEventType[],
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as unknown as Ref<UserTimelinePreferences>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
@@ -186,12 +177,10 @@ export function useParsingPreferences(): Ref<UserParsingPreferences> {
|
||||
const fromStorage = useLocalStorage(
|
||||
"parsing-preferences",
|
||||
{
|
||||
parser: "nlp",
|
||||
parser: "nlp" as RegisteredParser,
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as unknown as Ref<UserParsingPreferences>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
@@ -203,9 +192,7 @@ export function useCookbookPreferences(): Ref<UserCookbooksPreferences> {
|
||||
hideOtherHouseholds: false,
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as unknown as Ref<UserCookbooksPreferences>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
@@ -224,9 +211,7 @@ export function useRecipeFinderPreferences(): Ref<UserRecipeFinderPreferences> {
|
||||
includeToolsOnHand: true,
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as unknown as Ref<UserRecipeFinderPreferences>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
@@ -241,9 +226,19 @@ export function useRecipeCreatePreferences(): Ref<UserRecipeCreatePreferences> {
|
||||
parseRecipe: true,
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
// we cast to a Ref because by default it will return an optional type ref
|
||||
// but since we pass defaults we know all properties are set.
|
||||
) as unknown as Ref<UserRecipeCreatePreferences>;
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
|
||||
export function useUserExperiencePreferences(): Ref<UserExperiencePreferences> {
|
||||
const fromStorage = useLocalStorage(
|
||||
"user-experience-preferences",
|
||||
{
|
||||
lockScreen: true,
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
);
|
||||
|
||||
return fromStorage;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user