Decouple open/save dialogs, reload, shouldUseDarkColors from Electron

Summary: Per title. Less imports from Electron.

Reviewed By: timur-valiev, aigoncharov

Differential Revision: D31923504

fbshipit-source-id: dc7557cf7c88c0c8168ba22f7dca7b3e2d339a09
This commit is contained in:
Michel Weststrate
2021-10-26 12:06:18 -07:00
committed by Facebook GitHub Bot
parent d5e4b0c360
commit 9763af4c96
12 changed files with 106 additions and 103 deletions

View File

@@ -205,7 +205,7 @@ function init() {
setPersistor(persistor);
initializeFlipperLibImplementation(store, logger);
initializeFlipperLibImplementation(getRenderHostInstance(), store, logger);
_setGlobalInteractionReporter((r) => {
logger.track('usage', 'interaction', r);
if (!isProduction()) {
@@ -230,26 +230,20 @@ function init() {
sideEffect(
store,
{name: 'loadTheme', fireImmediately: false, throttleMs: 500},
(state) => {
const theme = state.settingsState.darkMode;
(state) => state.settingsState.darkMode,
(theme) => {
let shouldUseDarkMode = false;
if (theme === 'dark') {
shouldUseDarkMode = true;
} else if (theme === 'light') {
shouldUseDarkMode = false;
} else if (theme === 'system') {
shouldUseDarkMode = remote.nativeTheme.shouldUseDarkColors;
shouldUseDarkMode = getRenderHostInstance().shouldUseDarkColors();
}
return {
shouldUseDarkMode: shouldUseDarkMode,
theme: theme,
};
},
(result) => {
(
document.getElementById('flipper-theme-import') as HTMLLinkElement
).href = `themes/${result.shouldUseDarkMode ? 'dark' : 'light'}.css`;
getRenderHostInstance().sendIpcEvent('setTheme', result.theme);
).href = `themes/${shouldUseDarkMode ? 'dark' : 'light'}.css`;
getRenderHostInstance().sendIpcEvent('setTheme', theme);
},
);
}
@@ -272,10 +266,21 @@ function initializeFlipperForElectron() {
readTextFromClipboard() {
return clipboard.readText();
},
selectDirectory(defaultPath = path.resolve('/')) {
async showSaveDialog(options) {
return (await remote.dialog.showSaveDialog(options))?.filePath;
},
async showOpenDialog({filter, defaultPath}) {
const result = await remote.dialog.showOpenDialog({
defaultPath,
properties: ['openFile'],
filters: filter ? [filter] : undefined,
});
return result.filePaths?.[0];
},
showSelectDirectoryDialog(defaultPath = path.resolve('/')) {
return remote.dialog
.showOpenDialog({
properties: ['openDirectory', 'showHiddenFiles'],
properties: ['openDirectory'],
defaultPath,
})
.then((result: SaveDialogReturnValue & {filePaths: string[]}) => {
@@ -305,5 +310,8 @@ function initializeFlipperForElectron() {
sendIpcEvent(event, ...args: any[]) {
ipcRenderer.send(event, ...args);
},
shouldUseDarkColors() {
return remote.nativeTheme.shouldUseDarkColors;
},
});
}