diff --git a/preload.js b/preload.js index 49d9f9a17..429fa18e2 100644 --- a/preload.js +++ b/preload.js @@ -186,31 +186,18 @@ ipc.on('remove-dark-overlay', () => { }); -window.getSettingValue = settingID => { - console.log("EXECUTED"); - console.log("EXECUTED"); - console.log("EXECUTED"); - console.log("EXECUTED"); - - const theme = window.storage.get('theme-setting', 'dark'); - console.log(`THEME: ${theme}`); - console.log(`THEME: ${theme}`); - console.log(`THEME: ${theme}`); - console.log(`THEME: ${theme}`); - console.log(`THEME: ${theme}`); - - if (settingID === 'theme'){ - const theme = window.storage.get('theme-setting', 'dark'); - console.log(`THEME: ${theme}`); - } +window.getSettingValue = (settingID, comparisonValue = null) => { + // Comparison value allows you to pull boolean values from any type. + // Eg. window.getSettingValue('theme', 'light') + // returns 'false' when the value is 'dark'. + const settingVal = window.storage.get(settingID); + return comparisonValue ? !!settingVal === comparisonValue : settingVal; } -window.setSettingValue = settingID => { - const those = settingID; - return those; +window.setSettingValue = (settingID, value) => { + window.storage.put(settingID, value); } - installGetter('device-name', 'getDeviceName'); installGetter('theme-setting', 'getThemeSetting'); diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index 42abc6557..19eb635c7 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -18,18 +18,33 @@ export enum SessionSettingType { Button = 'button', } +//const { Settings } = window.Signal.Types; + // Grab initial values from database on startup const localSettings = [ { - id: 'theme', + id: 'theme-setting', title: 'Light Mode', + hidden: true, + comparisonValue: 'light', description: 'Choose the theme best suited to you', type: SessionSettingType.Toggle, category: SessionSettingCategory.General, - afterClick: () => window.toggleTheme(), + setFn: window.toggleTheme, }, { - id: 'typingIndicators', + id: 'hide-menu-bar', + title: 'Hide Menu Bar', + //hidden: !Settings.isHideMenuBarSupported(), + type: SessionSettingType.Toggle, + category: SessionSettingCategory.General, + setFn: window.setHideMenuBar, + }, + + + + { + id: 'typing-indicators-setting', title: 'Typing Indicators', description: 'See and share when messages are being typed. This setting is optional and applies to all conversations.', @@ -37,7 +52,7 @@ const localSettings = [ category: SessionSettingCategory.Privacy, }, { - id: 'screenLock', + id: 'qwer', title: 'Screen Lock', description: 'Unlock Loki Session using your password. Visit notification settings to customise.', @@ -45,7 +60,7 @@ const localSettings = [ category: SessionSettingCategory.Privacy, }, { - id: 'screenSecurity', + id: 'qewrtrg', title: 'Screen Security', description: 'Prevent Loki Session previews from appearing in desktop notifications.', @@ -53,7 +68,7 @@ const localSettings = [ category: SessionSettingCategory.Privacy, }, { - id: 'linkPreviews', + id: 'erhe', title: 'Send Link Previews', description: 'Supported for Imgur, Instagram, Pinterest, Reddit and YouTube.', @@ -61,7 +76,7 @@ const localSettings = [ category: SessionSettingCategory.Privacy, }, { - id: 'clearConversationHistory', + id: 'qwefwef', title: 'Clear Conversation History', category: SessionSettingCategory.Privacy, type: SessionSettingType.Button, @@ -69,7 +84,7 @@ const localSettings = [ buttonColor: SessionButtonColor.Danger, }, { - id: 'changePassword', + id: 'ergreg', title: 'Change Password', category: SessionSettingCategory.Account, type: SessionSettingType.Button, @@ -77,7 +92,7 @@ const localSettings = [ buttonColor: SessionButtonColor.Primary, }, { - id: 'removePassword', + id: 'etyjhnyth', title: 'Remove Password', category: SessionSettingCategory.Account, type: SessionSettingType.Button, @@ -99,6 +114,12 @@ export class SettingsView extends React.Component { } public renderSettingInCategory() { + const { Settings } = window.Signal.Types; + console.log(Settings); + console.log(Settings); + console.log(Settings); + console.log(Settings); + return ( <> {localSettings.map(setting => { @@ -107,19 +128,19 @@ export class SettingsView extends React.Component { return (
- {renderSettings && ( + {renderSettings && !(setting.hidden) && ( { - SettingsManager.updateSetting(setting); - }} - buttonText={setting.buttonText || undefined} - buttonColor={setting.buttonColor || undefined} + title={setting.title} + description={setting.description} + type={setting.type} + value={ window.getSettingValue(setting.id, setting.comparisonValue || null) } + onClick={() => { + this.updateSetting(setting); + }} + buttonText={setting.buttonText || undefined} + buttonColor={setting.buttonColor || undefined} /> - )} + )}
); })} @@ -139,17 +160,20 @@ export class SettingsView extends React.Component { ); } -} -export class SettingsManager { - public static updateSetting(item: any) { + public updateSetting(item: any) { if (item.type === SessionSettingType.Toggle) { - //alert(`You clicked a toggle with ID: ${item.id}`); - // Manage toggle events + // If no custom afterClick function given, alter values in storage here + if (!item.setFn) { + // Switch to opposite state + const newValue = !window.getSettingValue(item.id); + window.setSettingValue(item.id, newValue); + } } - // If there's an onClick function, execute it - item.afterClick && item.afterClick(); + // If there's a custom afterClick function, + // execute it instead of automatically updating settings + item.setFn && item.setFn(); return; } diff --git a/ts/global.d.ts b/ts/global.d.ts index 517ecb9ec..75e3798b5 100644 --- a/ts/global.d.ts +++ b/ts/global.d.ts @@ -23,10 +23,12 @@ interface Window { confirmationDialog: any; showSeedDialog: any; showAddServerDialog: any; - toggleTheme: any; deleteAccount: any; + toggleTheme: any; + setHideMenuBar: any; getSettingValue: any; setSettingValue: any; + } interface Promise {