nicolium: make settings synchronization in notes opt-in

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2026-03-07 10:30:33 +01:00
parent f41474f50b
commit 20b132f388
4 changed files with 68 additions and 51 deletions

View File

@ -99,9 +99,11 @@ const fetchMeSuccess =
const settings = account.settings_store?.[FE_NAME] || account.settings_store?.[LEGACY_FE_NAME];
if (client.features.frontendConfigurations) {
if (settings) {
useSettingsStore.getState().actions.loadUserSettings(settings);
} else if (client.features.notes) {
}
if (!client.features.frontendConfigurations && client.features.notes) {
const note = await getClient(getState)
.accounts.getRelationships([account.id])
.then((relationships) => relationships[0]?.note);
@ -112,6 +114,9 @@ const fetchMeSuccess =
if (match) {
try {
const frontendConfig = JSON.parse(decodeURIComponent(match[1]));
if (typeof frontendConfig === 'object' && frontendConfig !== null) {
frontendConfig.storeSettingsInNotes = true;
}
useSettingsStore.getState().actions.loadUserSettings(frontendConfig);
return frontendConfig;
} catch (error) {

View File

@ -10,6 +10,7 @@ import { useSettingsStore } from '@/stores/settings';
import toast from '@/toast';
import { isLoggedIn } from '@/utils/auth';
import type { Settings } from '@/schemas/frontend-settings';
import type { AppDispatch, RootState } from '@/store';
const LEGACY_FE_NAME = NODE_ENV === 'production' ? 'pl_fe' : 'pl_fe_dev';
@ -30,33 +31,35 @@ const saveSuccessMessage = defineMessage({
const changeSetting = (path: string[], value: any, opts?: SettingOpts) => {
useSettingsStore.getState().actions.changeSetting(path, value);
if (opts?.save !== false) return saveSettings(opts);
if (opts?.save !== false) return saveSettings(opts, path[0] === 'storeSettingsInNotes');
return () => {};
};
const saveSettings = (opts?: SettingOpts) => (dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return;
const saveSettings =
(opts?: SettingOpts, isNotesChange?: boolean) =>
(dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return;
const {
userSettings,
actions: { userSettingsSaving },
} = useSettingsStore.getState();
if (userSettings.saved) return;
const {
userSettings,
actions: { userSettingsSaving },
} = useSettingsStore.getState();
if (userSettings.saved) return;
const { saved, ...data } = userSettings;
const { saved, ...data } = userSettings;
dispatch(updateSettingsStore(data))
.then(() => {
userSettingsSaving();
dispatch(updateSettingsStore(data, isNotesChange))
.then(() => {
userSettingsSaving();
if (opts?.showAlert) {
toast.success(saveSuccessMessage);
}
})
.catch((error) => {
toast.showAlertForError(error);
});
};
if (opts?.showAlert) {
toast.success(saveSuccessMessage);
}
})
.catch((error) => {
toast.showAlertForError(error);
});
};
/** Update settings store for Mastodon, etc. */
const updateAuthAccount = async (url: string, settings: any) => {
@ -73,7 +76,8 @@ const updateAuthAccount = async (url: string, settings: any) => {
};
const updateSettingsStore =
(settings: any) => async (dispatch: AppDispatch, getState: () => RootState) => {
(settings: Partial<Settings>, isNotesChange?: boolean) =>
async (dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const client = getClient(state);
@ -86,17 +90,21 @@ const updateSettingsStore =
}),
);
} else {
if (client.features.notes) {
if (client.features.notes && (settings.storeSettingsInNotes || isNotesChange)) {
// Inspired by Phanpy and designed for compatibility with other software doing this
// https://github.com/cheeaun/phanpy/commit/a8b5c8cd64d456d30aab09dc56da7e4e20100e67
const note = (await client.accounts.getRelationships([state.me as string]))[0]?.note;
const settingsNote = `<nicolium-config>${encodeURIComponent(JSON.stringify(settings))}</nicolium-config>`;
let newNote;
if (/<nicolium-config>(.*)<\/nicolium-config>/.test(note || '')) {
newNote = note!.replace(/<nicolium-config>(.*)<\/nicolium-config>/, settingsNote);
if (settings.storeSettingsInNotes) {
if (/<nicolium-config>(.*)<\/nicolium-config>/.test(note || '')) {
newNote = note!.replace(/<nicolium-config>(.*)<\/nicolium-config>/, settingsNote);
} else {
newNote = `${note || ''}\n\n${settingsNote}`;
}
} else {
newNote = `${note || ''}\n\n${settingsNote}`;
newNote = note ? note.replace(/<nicolium-config>(.*)<\/nicolium-config>/, '') : '';
}
client.accounts.updateAccountNote(state.me as string, newNote);
}

View File

@ -282,6 +282,32 @@ const Preferences = () => {
return (
<Form>
{!features.frontendConfigurations && features.notes && (
<List>
<ListItem
label={
<FormattedMessage
id='preferences.fields.store_settings_in_notes'
defaultMessage='Store settings in account notes (recommended)'
/>
}
hint={
<FormattedMessage
id='preferences.fields.store_settings_in_notes_hint'
defaultMessage='It allows you to sync your settings across devices. They are only visible to you.'
/>
}
>
<SettingToggle
settings={settings}
settingPath={['storeSettingsInNotes']}
defaultValue
onChange={onToggleChange}
/>
</ListItem>
</List>
)}
<List>
<ListItem
label={
@ -298,30 +324,6 @@ const Preferences = () => {
onChange={onToggleChange}
/>
</ListItem>
</List>
<List>
{/* <ListItem
label={
<FormattedMessage
id='preferences.fields.store_settings_in_notes'
defaultMessage='Store settings in account notes'
/>
}
hint={
<FormattedMessage
id='preferences.fields.store_settings_in_notes_hint'
defaultMessage='It allows you to sync your settings across devices. They are only visible to you.'
/>
}
>
<SettingToggle
settings={settings}
settingPath={['storeSettingsInNotes']}
defaultValue
onChange={onToggleChange}
/>
</ListItem> */}
<ListItem
label={

View File

@ -1586,6 +1586,8 @@
"preferences.fields.render_mfm_hint": "MFM support is experimental, not all node types are supported.",
"preferences.fields.render_mfm_label": "Render Misskey Flavored Markdown",
"preferences.fields.spoilers_display_label": "Automatically expand text behind spoilers",
"preferences.fields.store_settings_in_notes": "Store settings in account notes (recommended)",
"preferences.fields.store_settings_in_notes_hint": "It allows you to sync your settings across devices. They are only visible to you.",
"preferences.fields.system_emoji_font_label": "Use system emoji font",
"preferences.fields.system_font_label": "Use system's default font",
"preferences.fields.theme": "Theme",