AutoDNDWhilePlaying: respect invisible & manual user change
This commit is contained in:
parent
a98bce31e7
commit
5d4d2447ff
2 changed files with 40 additions and 7 deletions
|
|
@ -74,7 +74,7 @@ async function extract(data: Buffer, outDir: string) {
|
|||
}
|
||||
|
||||
export async function installExt(id: string) {
|
||||
const extDir = join(extensionCacheDir, `${id}`);
|
||||
const extDir = join(extensionCacheDir, id);
|
||||
|
||||
try {
|
||||
await access(extDir, fsConstants.F_OK);
|
||||
|
|
@ -92,7 +92,7 @@ export async function installExt(id: string) {
|
|||
}
|
||||
|
||||
if (session.defaultSession.extensions) {
|
||||
session.defaultSession.extensions.loadExtension(id);
|
||||
session.defaultSession.extensions.loadExtension(extDir);
|
||||
} else {
|
||||
session.defaultSession.loadExtension(extDir);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { definePluginSettings } from "@api/Settings";
|
|||
import { getUserSettingLazy } from "@api/UserSettings";
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { UserSettingsProtoStore } from "@webpack/common";
|
||||
|
||||
let savedStatus: string | null;
|
||||
|
||||
|
|
@ -39,24 +40,56 @@ const settings = definePluginSettings({
|
|||
}
|
||||
});
|
||||
|
||||
let lastStatus: string | null = null;
|
||||
|
||||
function handleUserSettingsChange() {
|
||||
const status = StatusSettings.getSetting();
|
||||
if (status !== lastStatus) {
|
||||
lastStatus = status;
|
||||
|
||||
savedStatus = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function setStatus(status: string) {
|
||||
lastStatus = status;
|
||||
await StatusSettings.updateSetting(status);
|
||||
}
|
||||
|
||||
|
||||
export default definePlugin({
|
||||
name: "AutoDNDWhilePlaying",
|
||||
description: "Automatically updates your online status (online, idle, dnd) when launching games",
|
||||
tags: ["Activity", "Utility"],
|
||||
authors: [Devs.thororen],
|
||||
settings,
|
||||
|
||||
flux: {
|
||||
RUNNING_GAMES_CHANGE({ games }) {
|
||||
async RUNNING_GAMES_CHANGE({ games }) {
|
||||
const status = StatusSettings.getSetting();
|
||||
|
||||
if (games.length > 0) {
|
||||
if (status !== settings.store.statusToSet) {
|
||||
if (status !== settings.store.statusToSet && status !== "invisible") {
|
||||
savedStatus = status;
|
||||
StatusSettings.updateSetting(settings.store.statusToSet);
|
||||
await setStatus(settings.store.statusToSet);
|
||||
}
|
||||
} else if (savedStatus) {
|
||||
const toRestore = savedStatus;
|
||||
savedStatus = null;
|
||||
|
||||
if (status !== toRestore) {
|
||||
await setStatus(toRestore);
|
||||
}
|
||||
} else if (savedStatus && savedStatus !== settings.store.statusToSet) {
|
||||
StatusSettings.updateSetting(savedStatus);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
start() {
|
||||
lastStatus = StatusSettings.getSetting();
|
||||
UserSettingsProtoStore.addChangeListener(handleUserSettingsChange);
|
||||
},
|
||||
|
||||
stop() {
|
||||
UserSettingsProtoStore.removeChangeListener(handleUserSettingsChange);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue