mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-17 06:26:58 +01:00
Better theme export
This commit is contained in:
@@ -1293,7 +1293,7 @@ async fn cmd_update_folder(folder: Folder, w: WebviewWindow) -> Result<Folder, S
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn cmd_write_file_dev(w: WebviewWindow, pathname: &str, contents: &str) -> Result<(), String> {
|
||||
async fn cmd_write_file_dev(pathname: &str, contents: &str) -> Result<(), String> {
|
||||
if !is_dev() {
|
||||
panic!("Cannot write arbitrary files when not in dev mode");
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { useLocalStorage } from 'react-use';
|
||||
import { useThemes } from '../../hooks/useThemes';
|
||||
import { capitalize } from '../../lib/capitalize';
|
||||
import { catppuccinMacchiato } from '../../lib/theme/themes/catppuccin';
|
||||
import { githubLight } from '../../lib/theme/themes/github';
|
||||
import { monokaiProDefault } from '../../lib/theme/themes/monokai-pro';
|
||||
import { rosePineDefault } from '../../lib/theme/themes/rose-pine';
|
||||
import { yaakDark } from '../../lib/theme/themes/yaak';
|
||||
import { getThemeCSS } from '../../lib/theme/window';
|
||||
import { Banner } from '../core/Banner';
|
||||
@@ -53,30 +49,28 @@ export function SettingsDesign() {
|
||||
const themes = useThemes();
|
||||
|
||||
const [exportDir, setExportDir] = useLocalStorage<string | null>('theme_export_dir', null);
|
||||
const [loadingExport, setLoadingExport] = useState<boolean>(false);
|
||||
|
||||
const saveThemes = async () => {
|
||||
const dir = await open({ directory: true });
|
||||
if (!dir) return;
|
||||
const saveThemes = () => {
|
||||
setLoadingExport(true);
|
||||
setTimeout(async () => {
|
||||
const allThemesCSS = themes.themes.map(getThemeCSS).join('\n\n');
|
||||
const coreThemeCSS = [yaakDark].map(getThemeCSS).join('\n\n');
|
||||
|
||||
const allThemesCSS = themes.themes.map(getThemeCSS).join('\n\n');
|
||||
const coreThemeCSS = [
|
||||
yaakDark,
|
||||
catppuccinMacchiato,
|
||||
rosePineDefault,
|
||||
monokaiProDefault,
|
||||
githubLight,
|
||||
]
|
||||
.map(getThemeCSS)
|
||||
.join('\n\n');
|
||||
|
||||
await invoke('cmd_write_file_dev', {
|
||||
pathname: dir + '/themes-all.css',
|
||||
contents: coreThemeCSS,
|
||||
});
|
||||
await invoke('cmd_write_file_dev', {
|
||||
pathname: dir + '/themes-slim.css',
|
||||
contents: allThemesCSS,
|
||||
});
|
||||
try {
|
||||
await invoke('cmd_write_file_dev', {
|
||||
pathname: exportDir + '/themes-all.css',
|
||||
contents: allThemesCSS,
|
||||
});
|
||||
await invoke('cmd_write_file_dev', {
|
||||
pathname: exportDir + '/themes-slim.css',
|
||||
contents: coreThemeCSS,
|
||||
});
|
||||
} catch (err) {
|
||||
console.log('FAILED', err);
|
||||
}
|
||||
setLoadingExport(false);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -96,6 +90,7 @@ export function SettingsDesign() {
|
||||
</Button>
|
||||
<Button
|
||||
disabled={exportDir == null}
|
||||
isLoading={loadingExport}
|
||||
size="sm"
|
||||
color="primary"
|
||||
variant="border"
|
||||
|
||||
@@ -220,7 +220,7 @@ export function getThemeCSS(theme: YaakTheme): string {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
return [`/* ${theme.name} */`, `[data-theme="${theme.id}"] {`, themeCSS, '}'].join('\n');
|
||||
return [`/* ${theme.name} */`, `[data-theme="${theme.id}"] {`, indent(themeCSS), '}'].join('\n');
|
||||
}
|
||||
|
||||
export function addThemeStylesToDocument(theme: YaakTheme) {
|
||||
|
||||
Reference in New Issue
Block a user