snappymail/dev/Settings/User/General.js

172 lines
5.9 KiB
JavaScript
Raw Permalink 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';
import { SaveSettingStatus } from 'Common/Enums';
2023-04-03 16:29:26 +08:00
import { LayoutSideView, LayoutBottomView } from 'Common/EnumsUser';
2023-02-01 19:21:31 +08:00
import { setRefreshFoldersInterval } from 'Common/Folders';
2021-07-22 03:34:17 +08:00
import { Settings, SettingsGet } from 'Common/Globals';
import { WYSIWYGS } from 'Common/HtmlEditor';
2022-02-28 17:38:47 +08:00
import { isArray } from 'Common/Utils';
import { addSubscribablesTo, addComputablesTo } from 'External/ko';
2022-10-10 19:52:56 +08:00
import { i18n, translateTrigger, 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 { 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;
2022-12-12 20:03:41 +08:00
this.hourCycle = LanguageStore.hourCycle;
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
2023-05-30 20:24:45 +08:00
this.desktopNotifications = NotificationUserStore.enabled;
2022-06-08 00:46:06 +08:00
this.isDesktopNotificationAllowed = NotificationUserStore.allowed;
2016-06-17 07:23:49 +08:00
this.threadsAllowed = AppUserStore.threadsAllowed;
2023-12-02 06:18:08 +08:00
['useThreads',
// These use addSetting()
'layout', 'messageReadDelay', 'messagesPerPage', 'checkMailInterval',
'editorDefaultType', 'editorWysiwyg', 'msgDefaultAction', 'maxBlockquotesLevel',
2023-12-02 06:18:08 +08:00
// These are in addSettings()
'requestReadReceipt', 'requestDsn', 'requireTLS', 'pgpSign', 'pgpEncrypt',
'viewHTML', 'viewImages', 'viewImagesWhitelist', 'removeColors', 'allowStyles', 'allowDraftAutosave',
2023-12-02 06:18:08 +08:00
'hideDeleted', 'listInlineAttachments', 'simpleAttachmentsList', 'collapseBlockquotes',
'useCheckboxesInList', 'listGrouped', 'replySameFolder', 'allowSpellcheck',
'messageReadAuto', 'showNextMessage', 'messageNewWindow'
].forEach(name => this[name] = SettingsUserStore[name]);
this.allowLanguagesOnSettings = !!SettingsGet('allowLanguagesOnSettings');
2016-06-30 08:02:45 +08:00
this.languageTrigger = ko.observable(SaveSettingStatus.Idle);
2014-08-21 23:08:34 +08:00
this.identities = IdentityUserStore;
2016-07-16 05:29:42 +08:00
this.wysiwygs = WYSIWYGS;
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: () => {
2022-10-10 19:52:56 +08:00
translateTrigger();
return [
2023-04-03 16:29:26 +08:00
{ id: 'Html', name: i18n('SETTINGS_GENERAL/EDITOR_HTML') },
{ id: 'Plain', name: i18n('SETTINGS_GENERAL/EDITOR_PLAIN') }
];
},
hasWysiwygs: () => 1 < WYSIWYGS().length,
2022-08-31 23:31:08 +08:00
msgDefaultActions: () => {
2022-10-10 19:52:56 +08:00
translateTrigger();
2022-08-31 23:31:08 +08:00
return [
{ id: 1, name: i18n('MESSAGE/BUTTON_REPLY') }, // ComposeType.Reply,
{ id: 2, name: i18n('MESSAGE/BUTTON_REPLY_ALL') } // ComposeType.ReplyAll
];
},
layoutTypes: () => {
2022-10-10 19:52:56 +08:00
translateTrigger();
return [
{ id: 0, name: i18n('SETTINGS_GENERAL/LAYOUT_NO_SPLIT') },
2023-04-03 16:29:26 +08:00
{ id: LayoutSideView, name: i18n('SETTINGS_GENERAL/LAYOUT_VERTICAL_SPLIT') },
{ id: LayoutBottomView, name: i18n('SETTINGS_GENERAL/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');
this.addSetting('editorWysiwyg');
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');
2023-02-01 19:21:31 +08:00
this.addSetting('CheckMailInterval');
this.addSetting('Layout');
this.addSetting('MaxBlockquotesLevel');
2022-02-28 17:38:47 +08:00
2023-12-02 06:18:08 +08:00
this.addSettings([
'requestReadReceipt', 'requestDsn', 'requireTLS', 'pgpSign', 'pgpEncrypt',
'ViewHTML', 'ViewImages', 'ViewImagesWhitelist', 'RemoveColors', 'AllowStyles', 'AllowDraftAutosave',
'HideDeleted', 'ListInlineAttachments', 'simpleAttachmentsList', 'CollapseBlockquotes',
'UseCheckboxesInList', 'listGrouped', 'ReplySameFolder', 'allowSpellcheck',
'messageReadAuto', 'showNextMessage', 'messageNewWindow',
'DesktopNotifications', 'SoundNotification']);
2022-03-01 17:18:12 +08:00
2021-03-16 18:38:40 +08:00
const fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageTrigger(saveSettingsStep);
setTimeout(() => this.languageTrigger(SaveSettingStatus.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 => {
this.languageTrigger(SaveSettingStatus.Saving);
2022-12-23 19:22:57 +08:00
translatorReload(value)
.then(fReloadLanguageHelper(SaveSettingStatus.Success), fReloadLanguageHelper(SaveSettingStatus.Failed))
.then(() => Remote.saveSetting('language', value));
2021-03-16 18:38:40 +08:00
},
2022-12-12 20:03:41 +08:00
hourCycle: value =>
Remote.saveSetting('hourCycle', value),
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);
2023-02-01 19:21:31 +08:00
},
checkMailInterval: () => {
setRefreshFoldersInterval(SettingsUserStore.checkMailInterval());
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
}
}