2022-06-23 19:15:27 +00:00
|
|
|
// Copyright 2021-2022 Signal Messenger, LLC
|
2021-08-18 20:08:14 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-06-23 19:15:27 +00:00
|
|
|
// This has to be the first import because of monkey-patching
|
|
|
|
import '../shims';
|
|
|
|
|
2021-08-18 20:08:14 +00:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2021-09-16 15:52:56 +00:00
|
|
|
import { contextBridge, ipcRenderer } from 'electron';
|
2021-08-18 20:08:14 +00:00
|
|
|
|
2021-10-07 23:28:47 +00:00
|
|
|
import { SignalContext } from '../context';
|
2021-08-18 20:08:14 +00:00
|
|
|
import * as Settings from '../../types/Settings';
|
2021-09-16 15:52:56 +00:00
|
|
|
import { Preferences } from '../../components/Preferences';
|
2021-08-18 20:08:14 +00:00
|
|
|
import {
|
|
|
|
SystemTraySetting,
|
|
|
|
parseSystemTraySetting,
|
|
|
|
shouldMinimizeToSystemTray,
|
|
|
|
} from '../../types/SystemTraySetting';
|
|
|
|
import { awaitObject } from '../../util/awaitObject';
|
|
|
|
import { createSetting, createCallback } from '../../util/preload';
|
2021-10-28 00:05:56 +00:00
|
|
|
import { startInteractionMode } from '../startInteractionMode';
|
2021-08-18 20:08:14 +00:00
|
|
|
|
2021-09-02 15:48:53 +00:00
|
|
|
function doneRendering() {
|
|
|
|
ipcRenderer.send('settings-done-rendering');
|
|
|
|
}
|
2021-08-18 20:08:14 +00:00
|
|
|
|
|
|
|
const settingAudioNotification = createSetting('audioNotification');
|
2021-08-19 22:56:29 +00:00
|
|
|
const settingAutoDownloadUpdate = createSetting('autoDownloadUpdate');
|
2021-08-18 20:08:14 +00:00
|
|
|
const settingAutoLaunch = createSetting('autoLaunch');
|
|
|
|
const settingCallRingtoneNotification = createSetting(
|
|
|
|
'callRingtoneNotification'
|
|
|
|
);
|
|
|
|
const settingCallSystemNotification = createSetting('callSystemNotification');
|
|
|
|
const settingCountMutedConversations = createSetting('countMutedConversations');
|
|
|
|
const settingDeviceName = createSetting('deviceName', { setter: false });
|
|
|
|
const settingHideMenuBar = createSetting('hideMenuBar');
|
|
|
|
const settingIncomingCallNotification = createSetting(
|
|
|
|
'incomingCallNotification'
|
|
|
|
);
|
|
|
|
const settingMediaCameraPermissions = createSetting('mediaCameraPermissions');
|
|
|
|
const settingMediaPermissions = createSetting('mediaPermissions');
|
|
|
|
const settingNotificationDrawAttention = createSetting(
|
|
|
|
'notificationDrawAttention'
|
|
|
|
);
|
|
|
|
const settingNotificationSetting = createSetting('notificationSetting');
|
|
|
|
const settingRelayCalls = createSetting('alwaysRelayCalls');
|
|
|
|
const settingSpellCheck = createSetting('spellCheck');
|
|
|
|
const settingTheme = createSetting('themeSetting');
|
|
|
|
const settingSystemTraySetting = createSetting('systemTraySetting');
|
|
|
|
|
|
|
|
const settingLastSyncTime = createSetting('lastSyncTime');
|
|
|
|
|
|
|
|
const settingZoomFactor = createSetting('zoomFactor');
|
|
|
|
|
|
|
|
// Getters only.
|
|
|
|
const settingBlockedCount = createSetting('blockedCount');
|
|
|
|
const settingLinkPreview = createSetting('linkPreviewSetting', {
|
|
|
|
setter: false,
|
|
|
|
});
|
|
|
|
const settingPhoneNumberDiscoverability = createSetting(
|
|
|
|
'phoneNumberDiscoverabilitySetting',
|
|
|
|
{ setter: false }
|
|
|
|
);
|
|
|
|
const settingPhoneNumberSharing = createSetting('phoneNumberSharingSetting', {
|
|
|
|
setter: false,
|
|
|
|
});
|
|
|
|
const settingReadReceipts = createSetting('readReceiptSetting', {
|
|
|
|
setter: false,
|
|
|
|
});
|
|
|
|
const settingTypingIndicators = createSetting('typingIndicatorSetting', {
|
|
|
|
setter: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Media settings
|
|
|
|
const settingAudioInput = createSetting('preferredAudioInputDevice');
|
|
|
|
const settingAudioOutput = createSetting('preferredAudioOutputDevice');
|
|
|
|
const settingVideoInput = createSetting('preferredVideoInputDevice');
|
|
|
|
|
|
|
|
const settingUniversalExpireTimer = createSetting('universalExpireTimer');
|
|
|
|
|
|
|
|
// Callbacks
|
|
|
|
const ipcGetAvailableIODevices = createCallback('getAvailableIODevices');
|
|
|
|
const ipcGetCustomColors = createCallback('getCustomColors');
|
|
|
|
const ipcIsSyncNotSupported = createCallback('isPrimary');
|
|
|
|
const ipcMakeSyncRequest = createCallback('syncRequest');
|
2021-08-19 01:04:38 +00:00
|
|
|
const ipcPNP = createCallback('isPhoneNumberSharingEnabled');
|
2021-08-18 20:08:14 +00:00
|
|
|
|
|
|
|
// ChatColorPicker redux hookups
|
|
|
|
// The redux actions update over IPC through a preferences re-render
|
|
|
|
const ipcGetDefaultConversationColor = createCallback(
|
|
|
|
'getDefaultConversationColor'
|
|
|
|
);
|
|
|
|
const ipcGetConversationsWithCustomColor = createCallback(
|
|
|
|
'getConversationsWithCustomColor'
|
|
|
|
);
|
|
|
|
const ipcAddCustomColor = createCallback('addCustomColor');
|
|
|
|
const ipcEditCustomColor = createCallback('editCustomColor');
|
|
|
|
const ipcRemoveCustomColor = createCallback('removeCustomColor');
|
|
|
|
const ipcRemoveCustomColorOnConversations = createCallback(
|
|
|
|
'removeCustomColorOnConversations'
|
|
|
|
);
|
|
|
|
const ipcResetAllChatColors = createCallback('resetAllChatColors');
|
|
|
|
const ipcResetDefaultChatColor = createCallback('resetDefaultChatColor');
|
|
|
|
const ipcSetGlobalDefaultConversationColor = createCallback(
|
|
|
|
'setGlobalDefaultConversationColor'
|
|
|
|
);
|
|
|
|
|
|
|
|
const DEFAULT_NOTIFICATION_SETTING = 'message';
|
|
|
|
|
2021-11-11 22:43:05 +00:00
|
|
|
function getSystemTraySettingValues(systemTraySetting: SystemTraySetting): {
|
2021-08-18 20:08:14 +00:00
|
|
|
hasMinimizeToAndStartInSystemTray: boolean;
|
|
|
|
hasMinimizeToSystemTray: boolean;
|
|
|
|
} {
|
|
|
|
const parsedSystemTraySetting = parseSystemTraySetting(systemTraySetting);
|
|
|
|
const hasMinimizeToAndStartInSystemTray =
|
|
|
|
parsedSystemTraySetting ===
|
|
|
|
SystemTraySetting.MinimizeToAndStartInSystemTray;
|
|
|
|
const hasMinimizeToSystemTray = shouldMinimizeToSystemTray(
|
|
|
|
parsedSystemTraySetting
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
hasMinimizeToAndStartInSystemTray,
|
|
|
|
hasMinimizeToSystemTray,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-07 19:42:17 +00:00
|
|
|
const renderPreferences = async () => {
|
2021-10-28 00:05:56 +00:00
|
|
|
startInteractionMode();
|
|
|
|
|
2021-08-18 20:08:14 +00:00
|
|
|
const {
|
|
|
|
blockedCount,
|
|
|
|
deviceName,
|
|
|
|
hasAudioNotifications,
|
2021-08-19 22:56:29 +00:00
|
|
|
hasAutoDownloadUpdate,
|
2021-08-18 20:08:14 +00:00
|
|
|
hasAutoLaunch,
|
|
|
|
hasCallNotifications,
|
|
|
|
hasCallRingtoneNotification,
|
|
|
|
hasCountMutedConversations,
|
|
|
|
hasHideMenuBar,
|
|
|
|
hasIncomingCallNotifications,
|
|
|
|
hasLinkPreviews,
|
|
|
|
hasMediaCameraPermissions,
|
|
|
|
hasMediaPermissions,
|
|
|
|
hasNotificationAttention,
|
|
|
|
hasReadReceipts,
|
|
|
|
hasRelayCalls,
|
|
|
|
hasSpellCheck,
|
|
|
|
hasTypingIndicators,
|
2021-08-19 01:04:38 +00:00
|
|
|
isPhoneNumberSharingSupported,
|
2021-08-18 20:08:14 +00:00
|
|
|
lastSyncTime,
|
|
|
|
notificationContent,
|
|
|
|
selectedCamera,
|
|
|
|
selectedMicrophone,
|
|
|
|
selectedSpeaker,
|
|
|
|
systemTraySetting,
|
|
|
|
themeSetting,
|
|
|
|
universalExpireTimer,
|
|
|
|
whoCanFindMe,
|
|
|
|
whoCanSeeMe,
|
|
|
|
zoomFactor,
|
|
|
|
|
|
|
|
availableIODevices,
|
|
|
|
customColors,
|
|
|
|
isSyncNotSupported,
|
|
|
|
defaultConversationColor,
|
|
|
|
} = await awaitObject({
|
|
|
|
blockedCount: settingBlockedCount.getValue(),
|
|
|
|
deviceName: settingDeviceName.getValue(),
|
|
|
|
hasAudioNotifications: settingAudioNotification.getValue(),
|
2021-08-19 22:56:29 +00:00
|
|
|
hasAutoDownloadUpdate: settingAutoDownloadUpdate.getValue(),
|
2021-08-18 20:08:14 +00:00
|
|
|
hasAutoLaunch: settingAutoLaunch.getValue(),
|
|
|
|
hasCallNotifications: settingCallSystemNotification.getValue(),
|
|
|
|
hasCallRingtoneNotification: settingCallRingtoneNotification.getValue(),
|
|
|
|
hasCountMutedConversations: settingCountMutedConversations.getValue(),
|
|
|
|
hasHideMenuBar: settingHideMenuBar.getValue(),
|
|
|
|
hasIncomingCallNotifications: settingIncomingCallNotification.getValue(),
|
|
|
|
hasLinkPreviews: settingLinkPreview.getValue(),
|
|
|
|
hasMediaCameraPermissions: settingMediaCameraPermissions.getValue(),
|
|
|
|
hasMediaPermissions: settingMediaPermissions.getValue(),
|
|
|
|
hasNotificationAttention: settingNotificationDrawAttention.getValue(),
|
|
|
|
hasReadReceipts: settingReadReceipts.getValue(),
|
|
|
|
hasRelayCalls: settingRelayCalls.getValue(),
|
|
|
|
hasSpellCheck: settingSpellCheck.getValue(),
|
|
|
|
hasTypingIndicators: settingTypingIndicators.getValue(),
|
2021-08-19 01:04:38 +00:00
|
|
|
isPhoneNumberSharingSupported: ipcPNP(),
|
2021-08-18 20:08:14 +00:00
|
|
|
lastSyncTime: settingLastSyncTime.getValue(),
|
|
|
|
notificationContent: settingNotificationSetting.getValue(),
|
|
|
|
selectedCamera: settingVideoInput.getValue(),
|
|
|
|
selectedMicrophone: settingAudioInput.getValue(),
|
|
|
|
selectedSpeaker: settingAudioOutput.getValue(),
|
|
|
|
systemTraySetting: settingSystemTraySetting.getValue(),
|
|
|
|
themeSetting: settingTheme.getValue(),
|
|
|
|
universalExpireTimer: settingUniversalExpireTimer.getValue(),
|
|
|
|
whoCanFindMe: settingPhoneNumberDiscoverability.getValue(),
|
|
|
|
whoCanSeeMe: settingPhoneNumberSharing.getValue(),
|
|
|
|
zoomFactor: settingZoomFactor.getValue(),
|
|
|
|
|
|
|
|
// Callbacks
|
|
|
|
availableIODevices: ipcGetAvailableIODevices(),
|
|
|
|
customColors: ipcGetCustomColors(),
|
|
|
|
isSyncNotSupported: ipcIsSyncNotSupported(),
|
|
|
|
defaultConversationColor: ipcGetDefaultConversationColor(),
|
|
|
|
});
|
|
|
|
|
2021-11-11 22:43:05 +00:00
|
|
|
const { availableCameras, availableMicrophones, availableSpeakers } =
|
|
|
|
availableIODevices;
|
2021-08-18 20:08:14 +00:00
|
|
|
|
2021-11-11 22:43:05 +00:00
|
|
|
const { hasMinimizeToAndStartInSystemTray, hasMinimizeToSystemTray } =
|
|
|
|
getSystemTraySettingValues(systemTraySetting);
|
2021-08-18 20:08:14 +00:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
// Settings
|
|
|
|
availableCameras,
|
|
|
|
availableMicrophones,
|
|
|
|
availableSpeakers,
|
|
|
|
blockedCount,
|
|
|
|
customColors,
|
|
|
|
defaultConversationColor,
|
|
|
|
deviceName,
|
|
|
|
hasAudioNotifications,
|
2021-08-19 22:56:29 +00:00
|
|
|
hasAutoDownloadUpdate,
|
2021-08-18 20:08:14 +00:00
|
|
|
hasAutoLaunch,
|
|
|
|
hasCallNotifications,
|
|
|
|
hasCallRingtoneNotification,
|
|
|
|
hasCountMutedConversations,
|
|
|
|
hasHideMenuBar,
|
|
|
|
hasIncomingCallNotifications,
|
|
|
|
hasLinkPreviews,
|
|
|
|
hasMediaCameraPermissions,
|
|
|
|
hasMediaPermissions,
|
|
|
|
hasMinimizeToAndStartInSystemTray,
|
|
|
|
hasMinimizeToSystemTray,
|
|
|
|
hasNotificationAttention,
|
|
|
|
hasNotifications: notificationContent !== 'off',
|
|
|
|
hasReadReceipts,
|
|
|
|
hasRelayCalls,
|
|
|
|
hasSpellCheck,
|
|
|
|
hasTypingIndicators,
|
|
|
|
lastSyncTime,
|
|
|
|
notificationContent,
|
|
|
|
selectedCamera,
|
|
|
|
selectedMicrophone,
|
|
|
|
selectedSpeaker,
|
|
|
|
themeSetting,
|
|
|
|
universalExpireTimer,
|
|
|
|
whoCanFindMe,
|
|
|
|
whoCanSeeMe,
|
|
|
|
zoomFactor,
|
|
|
|
|
|
|
|
// Actions and other props
|
|
|
|
addCustomColor: ipcAddCustomColor,
|
2022-06-08 22:00:32 +00:00
|
|
|
closeSettings: () => SignalContext.executeMenuRole('close'),
|
2021-08-18 20:08:14 +00:00
|
|
|
doDeleteAllData: () => ipcRenderer.send('delete-all-data'),
|
2021-09-02 15:48:53 +00:00
|
|
|
doneRendering,
|
2021-08-18 20:08:14 +00:00
|
|
|
editCustomColor: ipcEditCustomColor,
|
|
|
|
getConversationsWithCustomColor: ipcGetConversationsWithCustomColor,
|
|
|
|
initialSpellCheckSetting:
|
2022-06-13 21:39:35 +00:00
|
|
|
SignalContext.config.appStartInitialSpellcheckSetting,
|
2021-08-18 20:08:14 +00:00
|
|
|
makeSyncRequest: ipcMakeSyncRequest,
|
|
|
|
removeCustomColor: ipcRemoveCustomColor,
|
|
|
|
removeCustomColorOnConversations: ipcRemoveCustomColorOnConversations,
|
|
|
|
resetAllChatColors: ipcResetAllChatColors,
|
|
|
|
resetDefaultChatColor: ipcResetDefaultChatColor,
|
|
|
|
setGlobalDefaultConversationColor: ipcSetGlobalDefaultConversationColor,
|
|
|
|
|
|
|
|
// Limited support features
|
|
|
|
isAudioNotificationsSupported: Settings.isAudioNotificationSupported(),
|
2021-08-20 21:41:58 +00:00
|
|
|
isAutoDownloadUpdatesSupported: Settings.isAutoDownloadUpdatesSupported(),
|
2021-08-18 20:08:14 +00:00
|
|
|
isAutoLaunchSupported: Settings.isAutoLaunchSupported(),
|
|
|
|
isHideMenuBarSupported: Settings.isHideMenuBarSupported(),
|
|
|
|
isNotificationAttentionSupported: Settings.isDrawAttentionSupported(),
|
2021-08-19 01:04:38 +00:00
|
|
|
isPhoneNumberSharingSupported,
|
2021-08-18 20:08:14 +00:00
|
|
|
isSyncSupported: !isSyncNotSupported,
|
2021-09-16 15:52:56 +00:00
|
|
|
isSystemTraySupported: Settings.isSystemTraySupported(
|
2021-10-07 23:28:47 +00:00
|
|
|
SignalContext.getVersion()
|
2021-09-16 15:52:56 +00:00
|
|
|
),
|
2021-08-18 20:08:14 +00:00
|
|
|
|
|
|
|
// Change handlers
|
|
|
|
onAudioNotificationsChange: reRender(settingAudioNotification.setValue),
|
2021-08-19 22:56:29 +00:00
|
|
|
onAutoDownloadUpdateChange: reRender(settingAutoDownloadUpdate.setValue),
|
2021-08-18 20:08:14 +00:00
|
|
|
onAutoLaunchChange: reRender(settingAutoLaunch.setValue),
|
|
|
|
onCallNotificationsChange: reRender(settingCallSystemNotification.setValue),
|
|
|
|
onCallRingtoneNotificationChange: reRender(
|
|
|
|
settingCallRingtoneNotification.setValue
|
|
|
|
),
|
|
|
|
onCountMutedConversationsChange: reRender(
|
|
|
|
settingCountMutedConversations.setValue
|
|
|
|
),
|
|
|
|
onHideMenuBarChange: reRender(settingHideMenuBar.setValue),
|
|
|
|
onIncomingCallNotificationsChange: reRender(
|
|
|
|
settingIncomingCallNotification.setValue
|
|
|
|
),
|
|
|
|
onLastSyncTimeChange: reRender(settingLastSyncTime.setValue),
|
|
|
|
onMediaCameraPermissionsChange: reRender(
|
|
|
|
settingMediaCameraPermissions.setValue
|
|
|
|
),
|
|
|
|
onMinimizeToAndStartInSystemTrayChange: reRender(async (value: boolean) => {
|
|
|
|
await settingSystemTraySetting.setValue(
|
|
|
|
value
|
|
|
|
? SystemTraySetting.MinimizeToAndStartInSystemTray
|
|
|
|
: SystemTraySetting.MinimizeToSystemTray
|
|
|
|
);
|
|
|
|
return value;
|
|
|
|
}),
|
|
|
|
onMinimizeToSystemTrayChange: reRender(async (value: boolean) => {
|
|
|
|
await settingSystemTraySetting.setValue(
|
|
|
|
value
|
|
|
|
? SystemTraySetting.MinimizeToSystemTray
|
|
|
|
: SystemTraySetting.DoNotUseSystemTray
|
|
|
|
);
|
|
|
|
return value;
|
|
|
|
}),
|
|
|
|
onMediaPermissionsChange: reRender(settingMediaPermissions.setValue),
|
|
|
|
onNotificationAttentionChange: reRender(
|
|
|
|
settingNotificationDrawAttention.setValue
|
|
|
|
),
|
|
|
|
onNotificationContentChange: reRender(settingNotificationSetting.setValue),
|
|
|
|
onNotificationsChange: reRender(async (value: boolean) => {
|
|
|
|
await settingNotificationSetting.setValue(
|
|
|
|
value ? DEFAULT_NOTIFICATION_SETTING : 'off'
|
|
|
|
);
|
|
|
|
return value;
|
|
|
|
}),
|
|
|
|
onRelayCallsChange: reRender(settingRelayCalls.setValue),
|
|
|
|
onSelectedCameraChange: reRender(settingVideoInput.setValue),
|
|
|
|
onSelectedMicrophoneChange: reRender(settingAudioInput.setValue),
|
|
|
|
onSelectedSpeakerChange: reRender(settingAudioOutput.setValue),
|
|
|
|
onSpellCheckChange: reRender(settingSpellCheck.setValue),
|
|
|
|
onThemeChange: reRender(settingTheme.setValue),
|
|
|
|
onUniversalExpireTimerChange: reRender(
|
|
|
|
settingUniversalExpireTimer.setValue
|
|
|
|
),
|
2021-09-07 19:42:17 +00:00
|
|
|
|
|
|
|
// Zoom factor change doesn't require immediate rerender since it will:
|
|
|
|
// 1. Update the zoom factor in the main window
|
|
|
|
// 2. Trigger `preferred-size-changed` in the main process
|
|
|
|
// 3. Finally result in `window.storage` update which will cause the
|
|
|
|
// rerender.
|
|
|
|
onZoomFactorChange: settingZoomFactor.setValue,
|
2021-08-18 20:08:14 +00:00
|
|
|
|
2021-10-07 23:28:47 +00:00
|
|
|
i18n: SignalContext.i18n,
|
2022-06-08 22:00:32 +00:00
|
|
|
|
|
|
|
platform: process.platform,
|
2022-06-15 18:21:03 +00:00
|
|
|
isWindows11: SignalContext.OS.isWindows11(),
|
2022-06-08 22:00:32 +00:00
|
|
|
executeMenuRole: SignalContext.executeMenuRole,
|
2021-08-18 20:08:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function reRender<Value>(f: (value: Value) => Promise<Value>) {
|
|
|
|
return async (value: Value) => {
|
|
|
|
await f(value);
|
2021-09-07 19:42:17 +00:00
|
|
|
renderPreferences();
|
2021-08-18 20:08:14 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-16 15:52:56 +00:00
|
|
|
ReactDOM.render(
|
|
|
|
React.createElement(Preferences, props),
|
|
|
|
document.getElementById('app')
|
|
|
|
);
|
2021-09-02 15:48:53 +00:00
|
|
|
};
|
2021-09-07 19:42:17 +00:00
|
|
|
|
2021-09-29 18:37:30 +00:00
|
|
|
ipcRenderer.on('preferences-changed', () => renderPreferences());
|
2021-09-16 15:52:56 +00:00
|
|
|
|
2021-10-07 23:28:47 +00:00
|
|
|
contextBridge.exposeInMainWorld('SignalContext', {
|
|
|
|
...SignalContext,
|
2021-09-16 15:52:56 +00:00
|
|
|
renderWindow: renderPreferences,
|
|
|
|
});
|