snappymail/dev/Settings/User/General.js

154 lines
5.1 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
2016-06-30 08:02:45 +08:00
2022-06-08 00:46:06 +08:00
import { SMAudio } from 'Common/Audio';
2021-01-25 05:58:06 +08:00
import { SaveSettingsStep } from 'Common/Enums';
import { EditorDefaultType, Layout } from 'Common/EnumsUser';
2021-07-22 03:34:17 +08:00
import { Settings, SettingsGet } from 'Common/Globals';
2022-02-28 17:38:47 +08:00
import { isArray } from 'Common/Utils';
import { addSubscribablesTo, addComputablesTo } from 'External/ko';
import { i18n, trigger as translatorTrigger, translatorReload, convertLangName } from 'Common/Translator';
2016-06-30 08:02:45 +08:00
2022-02-28 17:38:47 +08:00
import { AbstractViewSettings } from 'Knoin/AbstractViews';
2019-07-05 03:19:24 +08:00
import { showScreenPopup } from 'Knoin/Knoin';
2016-07-16 05:29:42 +08:00
import { AppUserStore } from 'Stores/User/App';
import { LanguageStore } from 'Stores/Language';
import { SettingsUserStore } from 'Stores/User/Settings';
import { IdentityUserStore } from 'Stores/User/Identity';
import { NotificationUserStore } from 'Stores/User/Notification';
import { MessageUserStore } from 'Stores/User/Message';
import { MessagelistUserStore } from 'Stores/User/Messagelist';
2016-07-16 05:29:42 +08:00
import Remote from 'Remote/User/Fetch';
2016-07-16 05:29:42 +08:00
import { IdentityPopupView } from 'View/Popup/Identity';
import { LanguagesPopupView } from 'View/Popup/Languages';
export class UserSettingsGeneral extends AbstractViewSettings {
2016-07-16 05:29:42 +08:00
constructor() {
2022-02-28 17:38:47 +08:00
super();
2016-07-16 05:29:42 +08:00
this.language = LanguageStore.language;
this.languages = LanguageStore.languages;
2016-06-30 08:02:45 +08:00
2022-06-08 00:46:06 +08:00
this.soundNotification = SMAudio.notifications;
2021-07-21 17:19:52 +08:00
this.notificationSound = ko.observable(SettingsGet('NotificationSound'));
this.notificationSounds = ko.observableArray(SettingsGet('NewMailSounds'));
2016-06-30 08:02:45 +08:00
2022-06-08 00:46:06 +08:00
this.desktopNotification = NotificationUserStore.enabled;
this.isDesktopNotificationAllowed = NotificationUserStore.allowed;
2016-06-17 07:23:49 +08:00
this.threadsAllowed = AppUserStore.threadsAllowed;
['layout', 'messageReadDelay', 'messagesPerPage',
'editorDefaultType', 'requestReadReceipt', 'requestDsn', 'pgpSign', 'pgpEncrypt',
'viewHTML', 'showImages', 'removeColors', 'hideDeleted',
2022-08-31 23:31:08 +08:00
'useCheckboxesInList', 'useThreads', 'replySameFolder', 'msgDefaultAction'
].forEach(name => this[name] = SettingsUserStore[name]);
2021-03-10 18:44:48 +08:00
this.allowLanguagesOnSettings = !!SettingsGet('AllowLanguagesOnSettings');
2016-06-30 08:02:45 +08:00
2022-02-28 17:38:47 +08:00
this.languageTrigger = ko.observable(SaveSettingsStep.Idle);
2014-08-21 23:08:34 +08:00
this.identities = IdentityUserStore;
2016-07-16 05:29:42 +08:00
addComputablesTo(this, {
languageFullName: () => convertLangName(this.language()),
identityMain: () => {
const list = this.identities();
return isArray(list) ? list.find(item => item && !item.id()) : null;
},
identityMainDesc: () => {
const identity = this.identityMain();
return identity ? identity.formattedName() : '---';
},
editorDefaultTypes: () => {
translatorTrigger();
return [
{ id: EditorDefaultType.Html, name: i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML') },
{ id: EditorDefaultType.Plain, name: i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN') }
];
},
2022-08-31 23:31:08 +08:00
msgDefaultActions: () => {
translatorTrigger();
return [
{ id: 1, name: i18n('MESSAGE/BUTTON_REPLY') }, // ComposeType.Reply,
{ id: 2, name: i18n('MESSAGE/BUTTON_REPLY_ALL') } // ComposeType.ReplyAll
];
},
layoutTypes: () => {
translatorTrigger();
return [
{ id: Layout.NoPreview, name: i18n('SETTINGS_GENERAL/LABEL_LAYOUT_NO_SPLIT') },
{ id: Layout.SidePreview, name: i18n('SETTINGS_GENERAL/LABEL_LAYOUT_VERTICAL_SPLIT') },
{ id: Layout.BottomPreview, name: i18n('SETTINGS_GENERAL/LABEL_LAYOUT_HORIZONTAL_SPLIT') }
];
}
2016-06-30 08:02:45 +08:00
});
2014-08-21 23:08:34 +08:00
2022-02-28 17:38:47 +08:00
this.addSetting('EditorDefaultType');
2022-08-31 23:31:08 +08:00
this.addSetting('MsgDefaultAction');
2022-02-28 17:38:47 +08:00
this.addSetting('MessageReadDelay');
this.addSetting('MessagesPerPage');
this.addSetting('Layout', () => MessagelistUserStore([]));
this.addSettings(['ViewHTML', 'ShowImages', 'HideDeleted', 'UseCheckboxesInList', 'ReplySameFolder',
'requestReadReceipt', 'requestDsn', 'pgpSign', 'pgpEncrypt',
2022-03-01 17:18:12 +08:00
'DesktopNotifications', 'SoundNotification']);
2021-03-16 18:38:40 +08:00
const fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageTrigger(saveSettingsStep);
setTimeout(() => this.languageTrigger(SaveSettingsStep.Idle), 1000);
2022-03-01 17:18:12 +08:00
};
2022-02-28 17:38:47 +08:00
2021-03-16 18:38:40 +08:00
addSubscribablesTo(this, {
language: value => {
2016-07-16 05:29:42 +08:00
this.languageTrigger(SaveSettingsStep.Animate);
2019-07-05 03:19:24 +08:00
translatorReload(false, value)
2022-02-28 17:38:47 +08:00
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
2021-03-18 23:12:24 +08:00
.then(() => Remote.saveSetting('Language', value));
2021-03-16 18:38:40 +08:00
},
2021-03-18 23:12:24 +08:00
removeColors: value => {
let dom = MessageUserStore.bodiesDom();
if (dom) {
dom.innerHTML = '';
}
2022-02-28 17:38:47 +08:00
Remote.saveSetting('RemoveColors', value);
2021-03-18 23:12:24 +08:00
},
2014-08-21 23:08:34 +08:00
2021-07-21 17:19:52 +08:00
notificationSound: value => {
Remote.saveSetting('NotificationSound', value);
2021-07-22 03:34:17 +08:00
Settings.set('NotificationSound', value);
2021-07-21 17:19:52 +08:00
},
2016-07-16 05:29:42 +08:00
2021-03-16 18:38:40 +08:00
useThreads: value => {
MessagelistUserStore([]);
2022-02-28 17:38:47 +08:00
Remote.saveSetting('UseThreads', value);
2021-03-16 18:38:40 +08:00
}
});
}
editMainIdentity() {
const identity = this.identityMain();
2021-07-22 03:34:17 +08:00
identity && showScreenPopup(IdentityPopupView, [identity]);
2021-03-16 18:38:40 +08:00
}
testSoundNotification() {
2022-06-08 00:46:06 +08:00
SMAudio.playNotification(true);
2021-03-16 18:38:40 +08:00
}
testSystemNotification() {
2022-06-08 00:46:06 +08:00
NotificationUserStore.display('SnappyMail', 'Test notification');
2016-07-16 05:29:42 +08:00
}
2014-08-25 15:10:51 +08:00
2016-07-16 05:29:42 +08:00
selectLanguage() {
showScreenPopup(LanguagesPopupView, [this.language, this.languages(), LanguageStore.userLanguage()]);
2016-07-16 05:29:42 +08:00
}
}