설정 (settings)
dmn.settings는 앱 전역 설정을 조회/부분 업데이트하고, 변경 사항을 구독할 수 있습니다.
조회
get()
전체 앱 설정을 조회합니다.
interface SettingsState {
hardwareAcceleration: boolean;
alwaysOnTop: boolean;
overlayLocked: boolean;
noteEffect: boolean;
noteSettings: NoteSettings;
angleMode: string;
language: string;
laboratoryEnabled: boolean;
developerModeEnabled: boolean;
backgroundColor: string;
useCustomCSS: boolean;
customCSS: { path: string | null; content: string };
useCustomJS: boolean;
customJS: { path: string | null; content: string; plugins: JsPlugin[] };
overlayResizeAnchor:
| "top-left"
| "top-right"
| "bottom-left"
| "bottom-right"
| "center";
keyCounterEnabled: boolean;
gridSettings: {
alignmentGuides: boolean;
spacingGuides: boolean;
sizeMatchGuides: boolean;
};
}const settings = await dmn.settings.get();
console.log("언어:", settings.language);
console.log("항상 위:", settings.alwaysOnTop);
console.log("오버레이 잠금:", settings.overlayLocked);상세 타입은 앱 소스의 src/types/settings.ts, src/types/noteSettings.ts를 참조하세요.
수정
update(patch)
설정을 부분 업데이트합니다.
// 단일 값 변경
await dmn.settings.update({
language: "en",
});
// 여러 값 동시 변경
await dmn.settings.update({
alwaysOnTop: true,
backgroundColor: "transparent",
});중첩 객체도 부분 병합됩니다. (noteSettings, customCSS, customJS, gridSettings)
await dmn.settings.update({
noteEffect: true,
noteSettings: { speed: 15, reverse: true },
});이벤트 구독
onChanged(listener)
설정 변경 이벤트를 구독합니다.
interface SettingsDiff {
changed: Record<string, any>; // 변경된 설정(패치)
full: SettingsState; // 전체 설정(최신 스냅샷)
}const unsub = dmn.settings.onChanged(({ changed, full }) => {
console.log("변경된 설정:", changed);
console.log("전체 설정:", full);
});
// 구독 해제
unsub();일반적인 패턴
특정 설정 값 감시
function watchSetting(path, callback) {
let prev;
return dmn.settings.onChanged(({ full }) => {
const current = path.split(".").reduce((o, k) => o?.[k], full);
if (current !== prev) {
prev = current;
callback(current);
}
});
}
const unsub = watchSetting("language", (language) => {
console.log("언어 변경:", language);
});토글 헬퍼
async function toggleBooleanSetting(key) {
const settings = await dmn.settings.get();
const current = settings[key];
if (typeof current === "boolean") {
await dmn.settings.update({ [key]: !current });
}
}
await toggleBooleanSetting("alwaysOnTop");