Safe Mode
Ask the app if Safe Mode is on, so that your source can ask its site to leave out titles with a Mature rating.
When Safe Mode is on, the app hides library titles that have a Mature rating. In the lists of your source, it blurs the cover of a title that has a Mature rating or an unknown rating.
Your source can ask the app if Safe Mode is on. Then it can ask the site to leave those titles out.
Ask the app
async isSafeModeEnabled(): Promise<boolean> {
if (typeof Application === "undefined") return true;
const intent = await Application.getContentIntent();
return intent.isSafeModeEnabled;
}
Call getContentIntent for each request. Do not keep the result. The value can change while your
source runs, for example when a Safe Mode schedule starts.
The result holds isSafeModeEnabled only. The app does not tell your source what it hid, or how
many titles it hid.
A person can turn Safe Mode off for one source. Then isSafeModeEnabled is false for that
source.
Older apps
Application exists in Suwatte 7.2.1 and later. On an older app it does not exist, so check for
it first. If it does not exist, treat Safe Mode as on.
Use it in a request
async getSearchResults(request: SearchRequest, page: number): Promise<PagedItemList> {
const safe = await this.isSafeModeEnabled();
const response = await this.client.get("/search", {
params: { q: request.query ?? "", page, adult: safe ? "0" : "1" },
});
const json = await response.json();
return { items: json.results.map(toItem), isLastPage: page >= json.total_pages };
}
The app still applies Safe Mode from the rating of each title. A filter on the site does not
replace a correct rating value.
Set rating on each Item and each Content. The values are ContentRating.EVERYONE,
SUGGESTIVE, MATURE and UNKNOWN.
Test it
The emulator starts each source with Safe Mode on, as a new app does. Each emulate call installs
the default shims again. To test with Safe Mode off, give emulate a different Application:
import emulate, { EmulatorApplication } from "@suwatte/toolchain/emulator";
import Target from "./src/example-en";
const source = emulate<Target>(Target, {
globals: { Application: new EmulatorApplication({ isSafeModeEnabled: false }) },
});
See The emulator.