diff --git a/.github/workflows/base.yml b/.github/workflows/base.yml index d240170af..47403edaf 100644 --- a/.github/workflows/base.yml +++ b/.github/workflows/base.yml @@ -24,6 +24,7 @@ jobs: profile: minimal toolchain: stable override: true + - uses: Swatinem/rust-cache@v2 - uses: actions-rs/cargo@v1 with: command: check @@ -41,6 +42,18 @@ jobs: profile: minimal toolchain: stable override: true + - uses: Swatinem/rust-cache@v2 + - run: | + sudo apt update + sudo apt install libwebkit2gtk-4.0-dev \ + build-essential \ + curl \ + wget \ + file \ + libssl-dev \ + libgtk-3-dev \ + libayatana-appindicator3-dev \ + librsvg2-dev - run: rustup component add clippy - uses: actions-rs/cargo@v1 with: diff --git a/Cargo.toml b/Cargo.toml index f5820bbe8..af9841814 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,9 @@ members = [ "libra", "vault", "neptune", + "lunar/src-tauri", ] +default-members = ["mega", "libra"] exclude = ["craft"] resolver = "1" @@ -25,7 +27,7 @@ callisto = { path = "jupiter/callisto" } gemini = { path = "gemini" } vault = { path = "vault" } neptune = { path = "neptune" } - +mega = { path = "mega" } anyhow = "1.0.86" serde = "1.0.203" serde_json = "1.0.117" diff --git a/lunar/.prettierrc b/lunar/.prettierrc new file mode 100644 index 000000000..9ea78f3c2 --- /dev/null +++ b/lunar/.prettierrc @@ -0,0 +1,8 @@ +{ + "semi": false, + // "trailingComma": "es5", + "singleQuote": true, + "printWidth": 120, + "tabWidth": 2, + // "useTabs": false +} \ No newline at end of file diff --git a/lunar/README.md b/lunar/README.md index 9cc5ec259..72459345f 100644 --- a/lunar/README.md +++ b/lunar/README.md @@ -1 +1,18 @@ -## Lunar Module \ No newline at end of file +## Lunar Module + +## bundle + +Because Lunar depends on Mega, which in turn relies on Neptune’s dynamic library pipy, it’s important to handle libpipy carefully during compilation. + +### Linux + +- deb + +Currently, on Linux Debian, you can complete the compilation directly using cargo tauri build -b deb. + +- AppImage + +However, compilation for AppImage will fail. After encountering the error “libpipy.so Not found” when executing `cargo tauri build -b appimage,` you need to manually copy `target/release/libpipy.so` to the `target/release/bundle/appimage/lunar.AppDir/usr/bin` folder and then manually execute `target/release/bundle/appimage/build_appimage.sh`. + +> [!NOTE] +> If you use archlinux to bundle, according to [\[bug\]\[linuxdeploy\] Linux AppImage script fails](https://github.com/tauri-apps/tauri/issues/8929), you may need to run build with `NO_STRIP=true cargo tauri **`. diff --git a/lunar/next.config.js b/lunar/next.config.js index 568c27213..42ee64ade 100644 --- a/lunar/next.config.js +++ b/lunar/next.config.js @@ -2,6 +2,7 @@ const nextConfig = { reactStrictMode: true, + output: "export", transpilePackages: [ // antd & deps // https://github.com/vercel/next.js/issues/65707 diff --git a/lunar/package.json b/lunar/package.json index cf08f9815..f8d9f185c 100644 --- a/lunar/package.json +++ b/lunar/package.json @@ -15,6 +15,7 @@ "@headlessui/tailwindcss": "^0.2.1", "@heroicons/react": "^2.1.3", "@tailwindcss/forms": "^0.5.7", + "@tauri-apps/api": "^1.6.0", "clsx": "^2.1.1", "framer-motion": "^11.3.2", "next": "14.2.3", diff --git a/lunar/src-tauri/.gitignore b/lunar/src-tauri/.gitignore new file mode 100644 index 000000000..aba21e242 --- /dev/null +++ b/lunar/src-tauri/.gitignore @@ -0,0 +1,3 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ diff --git a/lunar/src-tauri/Cargo.toml b/lunar/src-tauri/Cargo.toml new file mode 100644 index 000000000..8bacc4626 --- /dev/null +++ b/lunar/src-tauri/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "lunar-tauri" +version = "0.1.0" +description = "A Tauri App" +authors = ["you"] +license = "" +repository = "" +edition = "2021" +rust-version = "1.60" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[build-dependencies] +tauri-build = { version = "1.5.3", features = [] } + +[dependencies] +serde_json = "1.0" +serde = { version = "1.0", features = ["derive"] } +tauri = { version = "1.7.0", features = [] } +mega = { workspace = true } + +[features] +# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. +# If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes. +# DO NOT REMOVE!! +custom-protocol = ["tauri/custom-protocol"] diff --git a/lunar/src-tauri/build.rs b/lunar/src-tauri/build.rs new file mode 100644 index 000000000..983f4f185 --- /dev/null +++ b/lunar/src-tauri/build.rs @@ -0,0 +1,11 @@ +fn main() { + #[cfg(target_os = "linux")] + println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN"); + #[cfg(target_os = "macos")] + println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path"); + + // only for githut action check, according to [[feat] Prevent error when distDir doesn't exist](https://github.com/tauri-apps/tauri/issues/3142) + // ../out is the default distDir + std::fs::create_dir_all("../out").expect("failed to create out directory"); + tauri_build::build() +} diff --git a/lunar/src-tauri/config.toml b/lunar/src-tauri/config.toml new file mode 100644 index 000000000..8f3085d8b --- /dev/null +++ b/lunar/src-tauri/config.toml @@ -0,0 +1,90 @@ +# Filling the following environment variables with values you set +## Logging Configuration +[log] +# The path which log file is saved +log_path = "/tmp/.mega/logs" + +# log level +level = "debug" + +# print std log in console, disable it on production for performance +print_std = true + + +[database] +# "sqlite" | "postgres" +# "sqlite" will use `db_path` and ignore `db_url` +db_type = "sqlite" + +# used for sqlite +db_path = "./lunar-mega.db" + +# database connection url +db_url = "postgres://mega:mega@localhost:5432/mega" + +# db max connection, setting it to twice the number of CPU cores would be appropriate. +max_connection = 32 + +# db min connection, setting it to the number of CPU cores would be appropriate. +min_connection = 16 + +# Whether to disabling SQLx Log +sqlx_logging = false + + +[ssh] +ssh_key_path = "/tmp/.mega/ssh" + +[storage] +# raw object stroage type, can be `local` or `remote` +raw_obj_storage_type = "LOCAL" + +## If the object file size exceeds the threshold value, it will be handled by file storage instead of the database, Unit is KB +big_obj_threshold = 1024 + +# set the local path of the project storage +raw_obj_local_path = "/tmp/.mega/objects" + +lfs_obj_local_path = "/tmp/.mega/lfs" + +obs_access_key = "" +obs_secret_key = "" + +# cloud storage region +obs_region = "cn-east-3" + +# Override the endpoint URL used for remote storage services +obs_endpoint = "https://obs.cn-east-3.myhuaweicloud.com" + + +[monorepo] +## Only import directory support multi-branch commit and tag, monorepo only support main branch +## Mega treats files under this directory as import repo and other directories as monorepo +import_dir = "/third-part" + + +[pack] +# The maximum memory used by decode, Unit is GB +pack_decode_mem_size = 4 + +# The location where the object stored when the memory used by decode exceeds the limit +pack_decode_cache_path = "/tmp/.mega/cache" + +clean_cache_after_decode = true + +# The maximum meesage size in channel buffer while decode +channel_message_size = 1_000_000 + + +[ztm] +ca = "http://127.0.0.1:9999" +hub = "http://127.0.0.1:8888" +agent = "http://127.0.0.1:7777" + +[lfs] +## IMPORTANT: The 'enable_split' feature can only be enabled for new databases. Existing databases do not support this feature. +# Enable or disable splitting large files into smaller chunks +enable_split = true # Default is disabled. Set to true to enable file splitting. + +# Size of each file chunk when splitting is enabled, in bytes. Ignored if splitting is disabled. +split_size = 20971520 # Default size is 20MB (20971520 bytes) \ No newline at end of file diff --git a/lunar/src-tauri/icons/128x128.png b/lunar/src-tauri/icons/128x128.png new file mode 100644 index 000000000..77e7d2338 Binary files /dev/null and b/lunar/src-tauri/icons/128x128.png differ diff --git a/lunar/src-tauri/icons/128x128@2x.png b/lunar/src-tauri/icons/128x128@2x.png new file mode 100644 index 000000000..0f7976f1a Binary files /dev/null and b/lunar/src-tauri/icons/128x128@2x.png differ diff --git a/lunar/src-tauri/icons/32x32.png b/lunar/src-tauri/icons/32x32.png new file mode 100644 index 000000000..98fda06fc Binary files /dev/null and b/lunar/src-tauri/icons/32x32.png differ diff --git a/lunar/src-tauri/icons/Square107x107Logo.png b/lunar/src-tauri/icons/Square107x107Logo.png new file mode 100644 index 000000000..f35d84ff1 Binary files /dev/null and b/lunar/src-tauri/icons/Square107x107Logo.png differ diff --git a/lunar/src-tauri/icons/Square142x142Logo.png b/lunar/src-tauri/icons/Square142x142Logo.png new file mode 100644 index 000000000..1823bb269 Binary files /dev/null and b/lunar/src-tauri/icons/Square142x142Logo.png differ diff --git a/lunar/src-tauri/icons/Square150x150Logo.png b/lunar/src-tauri/icons/Square150x150Logo.png new file mode 100644 index 000000000..dc2b22cea Binary files /dev/null and b/lunar/src-tauri/icons/Square150x150Logo.png differ diff --git a/lunar/src-tauri/icons/Square284x284Logo.png b/lunar/src-tauri/icons/Square284x284Logo.png new file mode 100644 index 000000000..0ed3984c5 Binary files /dev/null and b/lunar/src-tauri/icons/Square284x284Logo.png differ diff --git a/lunar/src-tauri/icons/Square30x30Logo.png b/lunar/src-tauri/icons/Square30x30Logo.png new file mode 100644 index 000000000..60bf0eadf Binary files /dev/null and b/lunar/src-tauri/icons/Square30x30Logo.png differ diff --git a/lunar/src-tauri/icons/Square310x310Logo.png b/lunar/src-tauri/icons/Square310x310Logo.png new file mode 100644 index 000000000..c8ca0ad13 Binary files /dev/null and b/lunar/src-tauri/icons/Square310x310Logo.png differ diff --git a/lunar/src-tauri/icons/Square44x44Logo.png b/lunar/src-tauri/icons/Square44x44Logo.png new file mode 100644 index 000000000..8756459b6 Binary files /dev/null and b/lunar/src-tauri/icons/Square44x44Logo.png differ diff --git a/lunar/src-tauri/icons/Square71x71Logo.png b/lunar/src-tauri/icons/Square71x71Logo.png new file mode 100644 index 000000000..2c8023cc8 Binary files /dev/null and b/lunar/src-tauri/icons/Square71x71Logo.png differ diff --git a/lunar/src-tauri/icons/Square89x89Logo.png b/lunar/src-tauri/icons/Square89x89Logo.png new file mode 100644 index 000000000..2c5e6034f Binary files /dev/null and b/lunar/src-tauri/icons/Square89x89Logo.png differ diff --git a/lunar/src-tauri/icons/StoreLogo.png b/lunar/src-tauri/icons/StoreLogo.png new file mode 100644 index 000000000..17d142c0a Binary files /dev/null and b/lunar/src-tauri/icons/StoreLogo.png differ diff --git a/lunar/src-tauri/icons/icon.icns b/lunar/src-tauri/icons/icon.icns new file mode 100644 index 000000000..a2993adc8 Binary files /dev/null and b/lunar/src-tauri/icons/icon.icns differ diff --git a/lunar/src-tauri/icons/icon.ico b/lunar/src-tauri/icons/icon.ico new file mode 100644 index 000000000..06c23c82f Binary files /dev/null and b/lunar/src-tauri/icons/icon.ico differ diff --git a/lunar/src-tauri/icons/icon.png b/lunar/src-tauri/icons/icon.png new file mode 100644 index 000000000..d1756ce45 Binary files /dev/null and b/lunar/src-tauri/icons/icon.png differ diff --git a/lunar/src-tauri/src/main.rs b/lunar/src-tauri/src/main.rs new file mode 100644 index 000000000..479b79973 --- /dev/null +++ b/lunar/src-tauri/src/main.rs @@ -0,0 +1,30 @@ +// Prevents additional console window on Windows in release, DO NOT REMOVE!! +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] + +#[tauri::command] +fn hello_string(name: &str) -> String { + format!("Hello from Rust, {}!", name) +} + +fn start_mega(config_path: &str) { + let args_str = format!("-c \"{}\" service http", config_path); + let args = args_str.split(' ').collect(); + mega::cli::parse(Some(args)).expect("failed to start mega"); +} + +fn main() { + tauri::Builder::default() + .invoke_handler(tauri::generate_handler![hello_string]) + .setup(|app| { + let resource_path = app + .path_resolver() + .resolve_resource("config.toml") + .expect("failed to resolve config.toml resource"); + std::thread::spawn(move || { + start_mega(resource_path.to_str().unwrap()); + }); + Ok(()) + }) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); +} diff --git a/lunar/src-tauri/tauri.conf.json b/lunar/src-tauri/tauri.conf.json new file mode 100644 index 000000000..72b8bfa65 --- /dev/null +++ b/lunar/src-tauri/tauri.conf.json @@ -0,0 +1,74 @@ +{ + "build": { + "beforeBuildCommand": "npm run build", + "beforeDevCommand": "npm run dev", + "devPath": "http://localhost:3000", + "distDir": "../out" + }, + "package": { + "productName": "lunar", + "version": "0.1.0" + }, + "tauri": { + "allowlist": { + "fs": { + "scope": [ + "$RESOURCE/*" + ] + } + }, + "bundle": { + "active": true, + "category": "DeveloperTool", + "copyright": "", + "appimage": {}, + "deb": { + "files": { + "/usr/bin/libpipy.so": "../../target/release/libpipy.so" + } + }, + "externalBin": [], + "icon": [ + "icons/32x32.png", + "icons/128x128.png", + "icons/128x128@2x.png", + "icons/icon.icns", + "icons/icon.ico" + ], + "identifier": "org.mega.dev", + "longDescription": "", + "macOS": { + "entitlements": null, + "exceptionDomain": "", + "frameworks": [], + "providerShortName": null, + "signingIdentity": null + }, + "resources": [ + "config.toml" + ], + "shortDescription": "", + "targets": "all", + "windows": { + "certificateThumbprint": null, + "digestAlgorithm": "sha256", + "timestampUrl": "" + } + }, + "security": { + "csp": null + }, + "updater": { + "active": false + }, + "windows": [ + { + "fullscreen": false, + "height": 600, + "resizable": true, + "title": "lunar-app", + "width": 800 + } + ] + } +} \ No newline at end of file diff --git a/lunar/src/app/page.tsx b/lunar/src/app/page.tsx index 40215e9e9..63aae9a2f 100644 --- a/lunar/src/app/page.tsx +++ b/lunar/src/app/page.tsx @@ -1,15 +1,17 @@ 'use client' -import React from 'react'; -import { Space, Table, Tag } from 'antd'; -import type { TableProps } from 'antd'; +import React from 'react' +import { Space, Table, Tag } from 'antd' +import type { TableProps } from 'antd' +import HelloRust from '@/components/catalyst/hello' +import { GetResult } from '../../../moon/src/components/ApiResult' interface DataType { - key: string; - name: string; - age: number; - address: string; - tags: string[]; + key: string + name: string + age: number + address: string + tags: string[] } const columns: TableProps['columns'] = [ @@ -36,15 +38,15 @@ const columns: TableProps['columns'] = [ render: (_, { tags }) => ( <> {tags.map((tag) => { - let color = tag.length > 5 ? 'geekblue' : 'green'; + let color = tag.length > 5 ? 'geekblue' : 'green' if (tag === 'loser') { - color = 'volcano'; + color = 'volcano' } return ( {tag.toUpperCase()} - ); + ) })} ), @@ -59,7 +61,7 @@ const columns: TableProps['columns'] = [ ), }, -]; +] const data: DataType[] = [ { @@ -83,12 +85,15 @@ const data: DataType[] = [ address: 'Sydney No. 1 Lake Park', tags: ['cool', 'teacher'], }, -]; +] export default function HomePage() { return (
+ + {/* ---- */} + - ); -} \ No newline at end of file + ) +} diff --git a/lunar/src/app/test/page.tsx b/lunar/src/app/test/page.tsx new file mode 100644 index 000000000..7710c26ca --- /dev/null +++ b/lunar/src/app/test/page.tsx @@ -0,0 +1,4 @@ +"use client"; +export default function Page() { + return
hello world
; +} diff --git a/lunar/src/components/catalyst/hello.tsx b/lunar/src/components/catalyst/hello.tsx new file mode 100644 index 000000000..4977510be --- /dev/null +++ b/lunar/src/components/catalyst/hello.tsx @@ -0,0 +1,17 @@ +'use client' +// show helo world +import React, { useEffect } from 'react' +import { invoke } from '@tauri-apps/api/tauri' + +export default function HelloRust({ ...props }) { + const [content, setContent] = React.useState('数据加载中...') + useEffect(() => { + // sleep 1s, to see the loading effect + setTimeout(() => { + invoke('hello_string', { name: 'lunar' }).then((response: string) => { + setContent(response) + }) + }, 1000) + }, []) + return
{content}
+} diff --git a/moon/src/components/ApiResult.tsx b/moon/src/components/ApiResult.tsx new file mode 100644 index 000000000..c3cc3b8ac --- /dev/null +++ b/moon/src/components/ApiResult.tsx @@ -0,0 +1,31 @@ +"use client"; + +import { useEffect, useState } from "react"; + +export function GetResult({ host }: { host: string }) { + const [content, setData] = useState(

Loading...

); + useEffect(() => { + fetch(host, {}).then(async (res) => { + if (!res.ok) { + // setData("error, can't get response:\n" + res); + setData( +
+

Get {host} faied

+
{res.text()}
+
+ ); + return; + } + const data = await res.json(); + console.log(data); + const content = ( +
+

API Result of {host}

+ {JSON.stringify(data, null, 0)} +
+ ); + setData(content); + }); + }, [host]); + return
{content}
; +}