Skip to content

Commit

Permalink
fix: 🐛 初始化内容
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi1520 committed Jul 21, 2024
1 parent 4d2e184 commit d1fe582
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 40 deletions.
37 changes: 7 additions & 30 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]


mod folder;
mod file;

use tauri::WindowEvent;

mod folder;

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}


fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_clipboard_manager::init())
Expand All @@ -25,30 +20,12 @@ fn main() {
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_window_state::Builder::default().build())

.on_window_event(|window, event| {
match event {

// WindowEvent::Focused(true) => {
// window.emit("window-focused", {}).unwrap();
// }
WindowEvent::CloseRequested { api, .. } => {
#[cfg(target_os = "macos")]
{
window.minimize().unwrap();
}

#[cfg(not(target_os = "macos"))]
{
window.close().unwrap();
}

api.prevent_close();
}
_ => {}
}
})
.invoke_handler(tauri::generate_handler![file::read_dir, folder::show_in_folder, file::search_keyword_in_dir, greet])
.invoke_handler(tauri::generate_handler![
file::read_dir,
folder::show_in_folder,
file::search_keyword_in_dir,
greet
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
},
"productName": "MDX Editor",
"version": "0.9.5",
"version": "0.9.6",
"identifier": "editor.runjs.cool",
"plugins": {
"updater": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Pen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default function Pen({
async function compileNow(content) {
console.log('compile', filePath)
let md = resultRef.current?.md || ''
if (isMdFile(filePath)) {
if (isMdFile(filePath) || !filePath) {
md = content
}
console.log('md', md)
Expand Down
16 changes: 11 additions & 5 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import React, { useState, useEffect } from 'react'

import {
exists,
create,
writeTextFile,
readTextFile,
mkdir,
BaseDirectory,
} from '@tauri-apps/plugin-fs'
import initial from '@/utils/initial/'
import initial from '@/utils/initial'
import { documentDir, resolve } from '@tauri-apps/api/path'
import useLocalStorage from 'react-use/lib/useLocalStorage'
import { isMdFile } from '@/components/utils/file-tree-util'
Expand All @@ -27,13 +26,20 @@ export default function Page() {
const path = await resolve(documentDirPath, 'mdx-editor')

if (!(await exists(path))) {
await create('mdx-editor', {
await mkdir('mdx-editor', {
baseDir: BaseDirectory.Document,
})
await mkdir('mdx-editor/plugins', {
baseDir: BaseDirectory.Document,
})
await mkdir('mdx-editor/plugins/themes', {
baseDir: BaseDirectory.Document,
})

for (const key in initial) {
const content = initial[key]
await writeTextFile(path + `/${key}.md`, content)

await writeTextFile(`${path}/${key}`, content)
}
}
setDirPath(path)
Expand Down
271 changes: 271 additions & 0 deletions src/utils/initial/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
body {
--weui-BG-0: #ededed;
--weui-BG-2: #fff;
--weui-FG-0: rgba(0, 0, 0, 0.9);
--weui-FG-HALF: rgba(0, 0, 0, 0.9);
--weui-FG-1: rgba(0, 0, 0, 0.55);
--weui-FG-3: rgba(0, 0, 0, 0.1);
--weui-BRAND: #07c160;
--weui-LINK: #576b95;
}

body.dark {
--weui-BG-0: #111;
--weui-BG-2: #191919;
--weui-FG-0: rgba(255, 255, 255, 0.8);
--weui-FG-HALF: rgba(255, 255, 255, 0.6);
--weui-FG-1: rgba(255, 255, 255, 0.5);
--weui-FG-3: rgba(255, 255, 255, 0.1);
--weui-BRAND: #07c160;
--weui-LINK: #7d90a9;
}

body {
color: var(--weui-FG-HALF);
background-color: var(--weui-BG-2);
}
/*默认样式,最佳实践*/

/*全局属性*/
.markdown-body {
word-spacing: 0px;
letter-spacing: 0px;
word-break: break-word;
word-wrap: break-word;
text-align: left;
}

/*段落*/
.markdown-body p {
margin-top: 16px;
margin-bottom: 16px;
}

/*标题*/
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
margin-top: 30px;
margin-bottom: 15px;
padding: 0px;
font-weight: bold;
color: var(--weui-FG-0);
}
.markdown-body h1 {
font-size: 24px;
}
.markdown-body h2 {
font-size: 22px;
}
.markdown-body h3 {
font-size: 20px;
}
.markdown-body h4 {
font-size: 18px;
}
.markdown-body h5 {
font-size: 16px;
}
.markdown-body h6 {
font-size: 14px;
}

/*列表*/
.markdown-body ul,
.markdown-body ol {
margin-top: 8px;
margin-bottom: 8px;
padding-left: 25px;
}
.markdown-body ul {
list-style-type: disc;
}
.markdown-body ul ul {
list-style-type: square;
}

.markdown-body ol {
list-style-type: decimal;
}

.markdown-body li section {
margin-top: 5px;
margin-bottom: 5px;
line-height: 26px;
text-align: left;
font-weight: 500;
}

/*引用*/
.markdown-body blockquote {
background-color: var(--weui-BG-0);
border-left: 4px solid var(--weui-BRAND);
color: var(--weui-FG-HALF);
padding: 1px 16px;
margin: 16px 0;
border-radius: 5px;
}

.markdown-body blockquote p {
line-height: 26px;
color: var(--weui-FG-HALF);
}

/*链接*/
.markdown-body a,
.markdown-body .link {
text-decoration: none;
color: var(--weui-BRAND);
word-wrap: break-word;
}

/*加粗*/
.markdown-body strong {
font-weight: bold;
}

/*斜体*/
.markdown-body em {
font-style: italic;
}

/*加粗斜体*/
.markdown-body em strong {
font-weight: bold;
}

/*删除线*/
.markdown-body del {
font-style: italic;
}

/*分隔线*/
.markdown-body hr {
height: 1px;
margin: 0;
margin-top: 10px;
margin-bottom: 10px;
border: none;
border-top: 1px solid var(--weui-FG-3);
}

/*行内代码*/
.markdown-body p code,
.markdown-body li code {
font-size: 14px;
word-break: break-word;
padding: 2px 4px;
border-radius: 4px;
margin: 0 2px;
color: var(--weui-BRAND);
background-color: var(--weui-BG-0);
font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;
}

.markdown-body pre {
font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;
overflow: auto;
position: relative;
line-height: 1.75;
}

.markdown-body pre > code {
min-width: 100%;
font-size: 12px;
word-break: normal;
display: block;
flex: none;
padding: 12px;
-webkit-overflow-scrolling: touch;
}

/*图片*/
.markdown-body img {
display: block;
max-width: 100%;
}
.qrcode-block img {
border-radius: 0;
box-shadow: none;
}

/*图片*/
.markdown-body figure {
margin: 0;
padding: 0 5px;
margin-top: 10px;
margin-bottom: 10px;
}

/*图片描述文字*/
.markdown-body figcaption {
margin-top: 5px;
text-align: center;
color: var(--weui-LINK);
font-size: 14px;
}

/*表格*/
.markdown-body table {
width: auto;
table-layout: auto;
text-align: left;
margin-top: 2em;
margin-bottom: 2em;
font-size: 0.875rem;
line-height: 1.25rem;
border-spacing: 0;
border: 1px solid var(--weui-FG-3);
border-collapse: collapse;
}

.markdown-body table tr {
border: 0;
}

.markdown-body table tr th,
.markdown-body table tr td {
border: 0;
border-bottom: 1px solid var(--weui-FG-3);
font-size: 16px;
padding: 10px;
text-align: left;
}

.markdown-body table tr th {
color: var(--weui-FG-0);
background-color: var(--weui-BG-0);
font-weight: bold;
}

.markdown-body sub,
sup {
line-height: 0;
}

.markdown-body .contains-task-list {
padding-left: 0;
}
.markdown-body .task-list-item {
list-style: none;
}

.snowfall {
display: flex;
align-items: flex-end;
justify-content: center;
}

.snowfall-bar {
flex-basis: 0;
flex-grow: 1;
margin: 4px;
display: flex;
justify-content: center;
align-items: end;
font-size: 10px;
color: #eff6ff;
}
Loading

0 comments on commit d1fe582

Please sign in to comment.