Settings window: Don't show until everything is rendered

This commit is contained in:
Scott Nonnenberg 2021-09-02 08:48:53 -07:00 committed by GitHub
parent bf25a5db0b
commit 30c3b7630c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 22 deletions

13
main.js
View file

@ -907,17 +907,16 @@ function showSettingsWindow() {
settingsWindow.loadURL(prepareFileUrl([__dirname, 'settings.html'])); settingsWindow.loadURL(prepareFileUrl([__dirname, 'settings.html']));
settingsWindow.on('closed', () => { settingsWindow.on('closed', () => {
removeDarkOverlay();
settingsWindow = null; settingsWindow = null;
}); });
settingsWindow.once('ready-to-show', () => { ipc.once('settings-done-rendering', () => {
settingsWindow.show(); if (!settingsWindow) {
settingsWindow.webContents.send('render'); console.warn('settings-done-rendering: no settingsWindow available!');
return;
if (config.get('openDevTools')) {
settingsWindow.webContents.openDevTools();
} }
settingsWindow.show();
}); });
} }

View file

@ -103,6 +103,7 @@ const createProps = (): PropsType => ({
addCustomColor: action('addCustomColor'), addCustomColor: action('addCustomColor'),
closeSettings: action('closeSettings'), closeSettings: action('closeSettings'),
doDeleteAllData: action('doDeleteAllData'), doDeleteAllData: action('doDeleteAllData'),
doneRendering: action('doneRendering'),
editCustomColor: action('editCustomColor'), editCustomColor: action('editCustomColor'),
getConversationsWithCustomColor: () => Promise.resolve([]), getConversationsWithCustomColor: () => Promise.resolve([]),
initialSpellCheckSetting: true, initialSpellCheckSetting: true,

View file

@ -78,6 +78,7 @@ export type PropsType = {
addCustomColor: (color: CustomColorType) => unknown; addCustomColor: (color: CustomColorType) => unknown;
closeSettings: () => unknown; closeSettings: () => unknown;
doDeleteAllData: () => unknown; doDeleteAllData: () => unknown;
doneRendering: () => unknown;
editCustomColor: (colorId: string, color: CustomColorType) => unknown; editCustomColor: (colorId: string, color: CustomColorType) => unknown;
getConversationsWithCustomColor: ( getConversationsWithCustomColor: (
colorId: string colorId: string
@ -164,6 +165,7 @@ export const Preferences = ({
defaultConversationColor, defaultConversationColor,
deviceName = '', deviceName = '',
doDeleteAllData, doDeleteAllData,
doneRendering,
editCustomColor, editCustomColor,
getConversationsWithCustomColor, getConversationsWithCustomColor,
hasAudioNotifications, hasAudioNotifications,
@ -251,6 +253,10 @@ export const Preferences = ({
document.body.classList.toggle('dark-theme', theme === ThemeType.dark); document.body.classList.toggle('dark-theme', theme === ThemeType.dark);
}, [theme]); }, [theme]);
useEffect(() => {
doneRendering();
}, [doneRendering]);
useEffect(() => { useEffect(() => {
const handler = (event: KeyboardEvent) => { const handler = (event: KeyboardEvent) => {
if (event.key === 'Escape') { if (event.key === 'Escape') {

20
ts/window.d.ts vendored
View file

@ -180,15 +180,6 @@ declare global {
WhatIsThis: WhatIsThis; WhatIsThis: WhatIsThis;
SignalModule: {
registerReactRenderer: (
f: <P extends {}>(
component: FunctionComponent<P> | ComponentClass<P>,
props?: (Attributes & P) | null
) => void
) => void;
};
registerScreenShareControllerRenderer: ( registerScreenShareControllerRenderer: (
f: ( f: (
component: typeof CallingScreenSharingController, component: typeof CallingScreenSharingController,
@ -515,6 +506,17 @@ declare global {
GV2_MIGRATION_DISABLE_INVITE: boolean; GV2_MIGRATION_DISABLE_INVITE: boolean;
RETRY_DELAY: boolean; RETRY_DELAY: boolean;
// These elements are only available in the Settings window
SignalModule: {
registerReactRenderer: (
f: <P extends {}>(
component: FunctionComponent<P> | ComponentClass<P>,
props?: (Attributes & P) | null
) => void
) => void;
};
renderPreferences: () => unknown;
} }
// We want to extend `Error`, so we need an interface. // We want to extend `Error`, so we need an interface.

View file

@ -9,3 +9,5 @@ window.SignalModule.registerReactRenderer((Component, props) => {
document.getElementById('app') document.getElementById('app')
); );
}); });
window.renderPreferences();

View file

@ -43,6 +43,9 @@ window.ReactDOM = ReactDOM;
window.getEnvironment = getEnvironment; window.getEnvironment = getEnvironment;
window.getVersion = () => String(config.version); window.getVersion = () => String(config.version);
window.i18n = i18n.setup(locale, localeMessages); window.i18n = i18n.setup(locale, localeMessages);
function doneRendering() {
ipcRenderer.send('settings-done-rendering');
}
const settingAudioNotification = createSetting('audioNotification'); const settingAudioNotification = createSetting('audioNotification');
const settingAutoDownloadUpdate = createSetting('autoDownloadUpdate'); const settingAutoDownloadUpdate = createSetting('autoDownloadUpdate');
@ -157,9 +160,9 @@ function getSystemTraySettingValues(
}; };
} }
async function renderPreferences() { window.renderPreferences = async () => {
if (!renderComponent) { if (!renderComponent) {
setTimeout(renderPreferences, 100); setTimeout(window.renderPreferences, 100);
return; return;
} }
@ -293,6 +296,7 @@ async function renderPreferences() {
addCustomColor: ipcAddCustomColor, addCustomColor: ipcAddCustomColor,
closeSettings: () => ipcRenderer.send('close-settings'), closeSettings: () => ipcRenderer.send('close-settings'),
doDeleteAllData: () => ipcRenderer.send('delete-all-data'), doDeleteAllData: () => ipcRenderer.send('delete-all-data'),
doneRendering,
editCustomColor: ipcEditCustomColor, editCustomColor: ipcEditCustomColor,
getConversationsWithCustomColor: ipcGetConversationsWithCustomColor, getConversationsWithCustomColor: ipcGetConversationsWithCustomColor,
initialSpellCheckSetting: initialSpellCheckSetting:
@ -377,13 +381,11 @@ async function renderPreferences() {
function reRender<Value>(f: (value: Value) => Promise<Value>) { function reRender<Value>(f: (value: Value) => Promise<Value>) {
return async (value: Value) => { return async (value: Value) => {
await f(value); await f(value);
renderPreferences(); window.renderPreferences();
}; };
} }
renderComponent(Preferences, props); renderComponent(Preferences, props);
} };
ipcRenderer.on('render', renderPreferences);
initializeLogging(); initializeLogging();