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';
|
2022-09-26 20:02:30 +08:00
|
|
|
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';
|
2024-02-05 21:10:58 +08:00
|
|
|
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
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { AppUserStore } from 'Stores/User/App';
|
2021-01-27 17:59:15 +08:00
|
|
|
import { LanguageStore } from 'Stores/Language';
|
2021-03-11 05:41:35 +08:00
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
2021-02-17 21:40:21 +08:00
|
|
|
import { IdentityUserStore } from 'Stores/User/Identity';
|
2021-03-11 05:41:35 +08:00
|
|
|
import { NotificationUserStore } from 'Stores/User/Notification';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { MessagelistUserStore } from 'Stores/User/Messagelist';
|
2016-07-16 05:29:42 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2016-07-16 05:29:42 +08:00
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
import { IdentityPopupView } from 'View/Popup/Identity';
|
|
|
|
import { LanguagesPopupView } from 'View/Popup/Languages';
|
|
|
|
|
2022-03-08 07:51:32 +08:00
|
|
|
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'));
|
2023-02-21 17:22:59 +08:00
|
|
|
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
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
this.threadsAllowed = AppUserStore.threadsAllowed;
|
2022-08-09 21:34:55 +08:00
|
|
|
|
2023-12-02 06:18:08 +08:00
|
|
|
['useThreads',
|
|
|
|
// These use addSetting()
|
|
|
|
'layout', 'messageReadDelay', 'messagesPerPage', 'checkMailInterval',
|
2024-01-31 01:16:39 +08:00
|
|
|
'editorDefaultType', 'editorWysiwyg', 'msgDefaultAction', 'maxBlockquotesLevel',
|
2023-12-02 06:18:08 +08:00
|
|
|
// These are in addSettings()
|
|
|
|
'requestReadReceipt', 'requestDsn', 'requireTLS', 'pgpSign', 'pgpEncrypt',
|
2023-02-16 00:05:53 +08:00
|
|
|
'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'
|
2022-08-09 21:34:55 +08:00
|
|
|
].forEach(name => this[name] = SettingsUserStore[name]);
|
|
|
|
|
2023-02-21 17:22:59 +08:00
|
|
|
this.allowLanguagesOnSettings = !!SettingsGet('allowLanguagesOnSettings');
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-09-26 20:02:30 +08:00
|
|
|
this.languageTrigger = ko.observable(SaveSettingStatus.Idle);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-02-17 21:40:21 +08:00
|
|
|
this.identities = IdentityUserStore;
|
2016-07-16 05:29:42 +08:00
|
|
|
|
2024-01-31 01:16:39 +08:00
|
|
|
this.wysiwygs = WYSIWYGS;
|
|
|
|
|
2021-09-03 22:37:20 +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: () => {
|
2022-10-10 19:52:56 +08:00
|
|
|
translateTrigger();
|
2021-09-03 22:37:20 +08:00
|
|
|
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') }
|
2021-09-03 22:37:20 +08:00
|
|
|
];
|
|
|
|
},
|
|
|
|
|
2024-01-31 01:16:39 +08:00
|
|
|
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
|
|
|
|
];
|
|
|
|
},
|
|
|
|
|
2021-09-03 22:37:20 +08:00
|
|
|
layoutTypes: () => {
|
2022-10-10 19:52:56 +08:00
|
|
|
translateTrigger();
|
2021-09-03 22:37:20 +08:00
|
|
|
return [
|
2023-02-23 20:54:32 +08:00
|
|
|
{ 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') }
|
2021-09-03 22:37:20 +08:00
|
|
|
];
|
|
|
|
}
|
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');
|
2024-01-31 01:16:39 +08:00
|
|
|
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');
|
2022-09-14 05:00:47 +08:00
|
|
|
this.addSetting('Layout');
|
2023-02-04 23:39:50 +08:00
|
|
|
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);
|
2022-09-26 20:02:30 +08:00
|
|
|
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 => {
|
2022-09-26 20:02:30 +08:00
|
|
|
this.languageTrigger(SaveSettingStatus.Saving);
|
2022-12-23 19:22:57 +08:00
|
|
|
translatorReload(value)
|
2022-09-26 20:02:30 +08:00
|
|
|
.then(fReloadLanguageHelper(SaveSettingStatus.Success), fReloadLanguageHelper(SaveSettingStatus.Failed))
|
2023-02-21 18:52:50 +08:00
|
|
|
.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 => {
|
2022-02-24 02:26:52 +08:00
|
|
|
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() {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(LanguagesPopupView, [this.language, this.languages(), LanguageStore.userLanguage()]);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
}
|