2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { MESSAGES_PER_PAGE_VALUES } from 'Common/Consts';
|
2021-01-25 05:58:06 +08:00
|
|
|
import { SaveSettingsStep } from 'Common/Enums';
|
|
|
|
import { EditorDefaultType, Layout } from 'Common/EnumsUser';
|
2021-03-10 18:44:48 +08:00
|
|
|
import { SettingsGet } from 'Common/Globals';
|
2021-03-16 23:49:14 +08:00
|
|
|
import { isArray, settingsSaveHelperSimpleFunction, addObservablesTo, addSubscribablesTo } from 'Common/Utils';
|
2021-01-26 05:00:13 +08:00
|
|
|
import { i18n, trigger as translatorTrigger, reload as translatorReload, convertLangName } from 'Common/Translator';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
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';
|
|
|
|
import { MessageUserStore } from 'Stores/User/Message';
|
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';
|
|
|
|
|
2021-01-22 23:32:08 +08:00
|
|
|
export class GeneralUserSettings {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
|
|
|
this.language = LanguageStore.language;
|
|
|
|
this.languages = LanguageStore.languages;
|
2021-03-11 05:41:35 +08:00
|
|
|
this.messagesPerPage = SettingsUserStore.messagesPerPage;
|
2016-07-16 05:29:42 +08:00
|
|
|
this.messagesPerPageArray = MESSAGES_PER_PAGE_VALUES;
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
this.editorDefaultType = SettingsUserStore.editorDefaultType;
|
|
|
|
this.layout = SettingsUserStore.layout;
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
this.enableSoundNotification = NotificationUserStore.enableSoundNotification;
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
this.enableDesktopNotification = NotificationUserStore.enableDesktopNotification;
|
|
|
|
this.isDesktopNotificationDenied = NotificationUserStore.isDesktopNotificationDenied;
|
2016-06-17 07:23:49 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
this.showImages = SettingsUserStore.showImages;
|
|
|
|
this.removeColors = SettingsUserStore.removeColors;
|
|
|
|
this.useCheckboxesInList = SettingsUserStore.useCheckboxesInList;
|
|
|
|
this.threadsAllowed = AppUserStore.threadsAllowed;
|
|
|
|
this.useThreads = SettingsUserStore.useThreads;
|
|
|
|
this.replySameFolder = SettingsUserStore.replySameFolder;
|
2021-03-10 18:44:48 +08:00
|
|
|
this.allowLanguagesOnSettings = !!SettingsGet('AllowLanguagesOnSettings');
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.languageFullName = ko.computed(() => convertLangName(this.language()));
|
2021-02-10 19:12:36 +08:00
|
|
|
this.languageTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 });
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-16 17:59:47 +08:00
|
|
|
addObservablesTo(this, {
|
2020-10-27 18:09:24 +08:00
|
|
|
mppTrigger: SaveSettingsStep.Idle,
|
|
|
|
editorDefaultTypeTrigger: SaveSettingsStep.Idle,
|
|
|
|
layoutTrigger: SaveSettingsStep.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
|
|
|
|
|
|
|
this.identityMain = ko.computed(() => {
|
|
|
|
const list = this.identities();
|
2021-03-16 23:49:14 +08:00
|
|
|
return isArray(list) ? list.find(item => item && !item.id()) : null;
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.identityMainDesc = ko.computed(() => {
|
|
|
|
const identity = this.identityMain();
|
|
|
|
return identity ? identity.formattedName() : '---';
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.editorDefaultTypes = ko.computed(() => {
|
|
|
|
translatorTrigger();
|
|
|
|
return [
|
2019-07-05 03:19:24 +08:00
|
|
|
{ 'id': EditorDefaultType.Html, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML') },
|
|
|
|
{ 'id': EditorDefaultType.Plain, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN') },
|
|
|
|
{ 'id': EditorDefaultType.HtmlForced, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML_FORCED') },
|
|
|
|
{ 'id': EditorDefaultType.PlainForced, 'name': i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN_FORCED') }
|
2016-07-16 05:29:42 +08:00
|
|
|
];
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2015-01-27 05:06:00 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.layoutTypes = ko.computed(() => {
|
|
|
|
translatorTrigger();
|
|
|
|
return [
|
2019-07-05 03:19:24 +08:00
|
|
|
{ '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-07-16 05:29:42 +08:00
|
|
|
];
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
|
2021-03-16 18:38:40 +08:00
|
|
|
const fReloadLanguageHelper = (saveSettingsStep) => () => {
|
|
|
|
this.languageTrigger(saveSettingsStep);
|
|
|
|
setTimeout(() => this.languageTrigger(SaveSettingsStep.Idle), 1000);
|
|
|
|
};
|
|
|
|
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)
|
|
|
|
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
|
|
|
|
.then(() => {
|
|
|
|
Remote.saveSettings(null, {
|
|
|
|
'Language': value
|
|
|
|
});
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2021-03-16 18:38:40 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
editorDefaultType:
|
|
|
|
Remote.saveSettingsHelper('EditorDefaultType', null,
|
|
|
|
settingsSaveHelperSimpleFunction(this.editorDefaultTypeTrigger, this)),
|
|
|
|
|
|
|
|
messagesPerPage: Remote.saveSettingsHelper('MPP', null, settingsSaveHelperSimpleFunction(this.mppTrigger, this)),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-16 18:38:40 +08:00
|
|
|
showImages: Remote.saveSettingsHelper('ShowImages', v=>v?'1':'0'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-16 18:38:40 +08:00
|
|
|
removeColors: Remote.saveSettingsHelper('RemoveColors', v=>v?'1':'0'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-16 18:38:40 +08:00
|
|
|
useCheckboxesInList: Remote.saveSettingsHelper('UseCheckboxesInList', v=>v?'1':'0'),
|
|
|
|
|
|
|
|
enableDesktopNotification: (value =>
|
2020-08-19 02:24:17 +08:00
|
|
|
Remote.saveSettings(null, {
|
|
|
|
'DesktopNotifications': value ? 1 : 0
|
|
|
|
})
|
2021-03-16 18:38:40 +08:00
|
|
|
).debounce(3000),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-16 18:38:40 +08:00
|
|
|
enableSoundNotification: (value =>
|
2020-08-19 02:24:17 +08:00
|
|
|
Remote.saveSettings(null, {
|
|
|
|
'SoundNotification': value ? 1 : 0
|
|
|
|
})
|
2021-03-16 18:38:40 +08:00
|
|
|
).debounce(3000),
|
2016-07-16 05:29:42 +08:00
|
|
|
|
2021-03-16 18:38:40 +08:00
|
|
|
replySameFolder: (value =>
|
2020-08-19 02:24:17 +08:00
|
|
|
Remote.saveSettings(null, {
|
|
|
|
'ReplySameFolder': value ? 1 : 0
|
|
|
|
})
|
2021-03-16 18:38:40 +08:00
|
|
|
).debounce(3000),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-16 18:38:40 +08:00
|
|
|
useThreads: value => {
|
2021-03-12 23:54:37 +08:00
|
|
|
MessageUserStore.list([]);
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveSettings(null, {
|
2020-08-19 02:24:17 +08:00
|
|
|
'UseThreads': value ? 1 : 0
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2021-03-16 18:38:40 +08:00
|
|
|
},
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-16 18:38:40 +08:00
|
|
|
layout: value => {
|
2021-03-12 23:54:37 +08:00
|
|
|
MessageUserStore.list([]);
|
2021-03-16 18:38:40 +08:00
|
|
|
Remote.saveSettings(settingsSaveHelperSimpleFunction(this.layoutTrigger, this), {
|
2016-07-16 05:29:42 +08:00
|
|
|
'Layout': value
|
|
|
|
});
|
2021-03-16 18:38:40 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
editMainIdentity() {
|
|
|
|
const identity = this.identityMain();
|
|
|
|
if (identity) {
|
|
|
|
showScreenPopup(IdentityPopupView, [identity]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testSoundNotification() {
|
|
|
|
NotificationUserStore.playSoundNotification(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
testSystemNotification() {
|
|
|
|
NotificationUserStore.displayDesktopNotification('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
|
|
|
}
|
|
|
|
}
|