mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-02 12:47:41 +02:00
This commit is contained in:
parent
7ab197a92b
commit
315baacba7
@ -381,6 +381,7 @@ packages/app-desktop/services/plugins/hooks/useContentSize.js
|
|||||||
packages/app-desktop/services/plugins/hooks/useHtmlLoader.js
|
packages/app-desktop/services/plugins/hooks/useHtmlLoader.js
|
||||||
packages/app-desktop/services/plugins/hooks/useScriptLoader.js
|
packages/app-desktop/services/plugins/hooks/useScriptLoader.js
|
||||||
packages/app-desktop/services/plugins/hooks/useSubmitHandler.js
|
packages/app-desktop/services/plugins/hooks/useSubmitHandler.js
|
||||||
|
packages/app-desktop/services/plugins/hooks/useThemeCss.test.js
|
||||||
packages/app-desktop/services/plugins/hooks/useThemeCss.js
|
packages/app-desktop/services/plugins/hooks/useThemeCss.js
|
||||||
packages/app-desktop/services/plugins/hooks/useViewIsReady.js
|
packages/app-desktop/services/plugins/hooks/useViewIsReady.js
|
||||||
packages/app-desktop/services/plugins/hooks/useWebviewToPluginMessages.js
|
packages/app-desktop/services/plugins/hooks/useWebviewToPluginMessages.js
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -367,6 +367,7 @@ packages/app-desktop/services/plugins/hooks/useContentSize.js
|
|||||||
packages/app-desktop/services/plugins/hooks/useHtmlLoader.js
|
packages/app-desktop/services/plugins/hooks/useHtmlLoader.js
|
||||||
packages/app-desktop/services/plugins/hooks/useScriptLoader.js
|
packages/app-desktop/services/plugins/hooks/useScriptLoader.js
|
||||||
packages/app-desktop/services/plugins/hooks/useSubmitHandler.js
|
packages/app-desktop/services/plugins/hooks/useSubmitHandler.js
|
||||||
|
packages/app-desktop/services/plugins/hooks/useThemeCss.test.js
|
||||||
packages/app-desktop/services/plugins/hooks/useThemeCss.js
|
packages/app-desktop/services/plugins/hooks/useThemeCss.js
|
||||||
packages/app-desktop/services/plugins/hooks/useViewIsReady.js
|
packages/app-desktop/services/plugins/hooks/useViewIsReady.js
|
||||||
packages/app-desktop/services/plugins/hooks/useWebviewToPluginMessages.js
|
packages/app-desktop/services/plugins/hooks/useWebviewToPluginMessages.js
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
import { renderHook } from '@testing-library/react-hooks';
|
||||||
|
import useThemeCss from './useThemeCss';
|
||||||
|
import Setting from '@joplin/lib/models/Setting';
|
||||||
|
|
||||||
|
describe('useThemeCss', () => {
|
||||||
|
it('should return a different path when the theme changes', async () => {
|
||||||
|
const hookResult = renderHook(useThemeCss, {
|
||||||
|
initialProps: { pluginId: 'testid', themeId: Setting.THEME_DARK },
|
||||||
|
});
|
||||||
|
|
||||||
|
await hookResult.waitFor(() => {
|
||||||
|
expect(hookResult.result.current).toContain(`plugin_testid_theme_${Setting.THEME_DARK}.css`);
|
||||||
|
});
|
||||||
|
|
||||||
|
hookResult.rerender({ pluginId: 'testid', themeId: Setting.THEME_LIGHT });
|
||||||
|
|
||||||
|
await hookResult.waitFor(() => {
|
||||||
|
expect(hookResult.result.current).toContain(`plugin_testid_theme_${Setting.THEME_LIGHT}.css`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -36,16 +36,18 @@ export default function useThemeCss(dep: HookDependencies) {
|
|||||||
const [cssFilePath, setCssFilePath] = useState('');
|
const [cssFilePath, setCssFilePath] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (cssFilePath) return () => {};
|
|
||||||
|
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
async function createThemeStyleSheet() {
|
async function createThemeStyleSheet() {
|
||||||
const theme = themeStyle(themeId);
|
const theme = themeStyle(themeId);
|
||||||
const css = themeToCssVariables(theme);
|
const css = themeToCssVariables(theme);
|
||||||
const filePath = `${Setting.value('tempDir')}/plugin_${pluginId}_theme_${themeId}.css`;
|
const filePath = `${Setting.value('tempDir')}/plugin_${pluginId}_theme_${themeId}.css`;
|
||||||
await shim.fsDriver().writeFile(filePath, css, 'utf8');
|
|
||||||
if (cancelled) return;
|
if (!(await shim.fsDriver().exists(filePath))) {
|
||||||
|
await shim.fsDriver().writeFile(filePath, css, 'utf8');
|
||||||
|
if (cancelled) return;
|
||||||
|
}
|
||||||
|
|
||||||
setCssFilePath(filePath);
|
setCssFilePath(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +56,7 @@ export default function useThemeCss(dep: HookDependencies) {
|
|||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [pluginId, themeId, cssFilePath]);
|
}, [pluginId, themeId]);
|
||||||
|
|
||||||
return cssFilePath;
|
return cssFilePath;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user