Skip to content

Commit

Permalink
config tauri config and lib rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjj1024 committed Dec 20, 2024
1 parent 755017d commit 8a76cdb
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 46 deletions.
86 changes: 52 additions & 34 deletions src-tauri/data/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,79 @@ on:
default: 'template'

jobs:
release:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-20.04, windows-latest]
runs-on: ${{ matrix.platform }}
include:
- platform: 'macos-latest' # for Arm based macs (M1 and above).
target: 'aarch64-apple-darwin'
args: '--target aarch64-apple-darwin'
- platform: 'macos-latest' # for Intel based macs.
target: 'x86_64-apple-darwin'
args: '--target x86_64-apple-darwin'

- platform: 'ubuntu-22.04'
target: 'x86_64-unknown-linux-gnu'
args: ''
- platform: 'ubuntu-22.04'
target: 'aarch64-unknown-linux-gnu'
args: ''

- platform: 'windows-latest'
target: 'x86_64-pc-windows-msvc'
- platform: 'windows-latest'
target: 'i686-pc-windows-msvc'
- platform: 'windows-latest'
target: 'aarch64-pc-windows-msvc'
args: '--target aarch64-pc-windows-msvc'

runs-on: ${{ matrix.platform }}
timeout-minutes: 60
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-20.04'
# You can remove libayatana-appindicator3-dev if you don't use the system tray feature.
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev
- name: Install rust target
run: rustup target add ${{ matrix.target }}

- name: Rust setup
uses: dtolnay/rust-toolchain@stable
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Rust cache
uses: swatinem/rust-cache@v2
- uses: pnpm/action-setup@v3
with:
workspaces: './src-tauri -> target'
version: latest

- name: Sync node version and setup cache
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm

- name: Install PNPM
run: npm i -g pnpm

- name: Install frontend dependencies
# If you don't have `beforeBuildCommand` configured you may want to build your frontend here too.
run: pnpm install # Change this to npm, yarn or pnpm.

- name: Regenerate Icons
run: pnpm tauri icon
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}

- name: Create apple icon
run: node ./cli/creatIcon.cjs
- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Build the app
uses: tauri-apps/tauri-action@v0
- name: install frontend dependencies
run: pnpm install # change this to npm, pnpm or bun depending on which one you use.

- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: ${{ github.ref_name }} # This only works if your workflow triggers on new tags.
releaseName: 'PROJECTNAME v__VERSION__' # tauri-action replaces \_\_VERSION\_\_ with the app version.
releaseBody: 'RELEASEBODY'
releaseDraft: false
tagName: PakePlus-v__VERSION__
releaseName: 'PakePlus v__VERSION__'
body_path: ./Note.md
releaseDraft: true
prerelease: false
publish: true
args: ${{ matrix.args }}
File renamed without changes.
18 changes: 17 additions & 1 deletion src-tauri/src/command/pakeplus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub async fn update_main_rust(
) -> String {
let resource_path = handle
.path()
.resolve("data/main.rs", BaseDirectory::Resource)
.resolve("data/lib.rs", BaseDirectory::Resource)
.expect("failed to resolve resource");
let mut main_rust = std::fs::File::open(&resource_path).unwrap();
let mut contents = String::new();
Expand Down Expand Up @@ -284,6 +284,22 @@ pub async fn rust_main_window(handle: tauri::AppHandle, config: String) -> Strin
return encoded_contents;
}

#[tauri::command]
pub async fn rust_lib_window(handle: tauri::AppHandle, config: String) -> String {
let resource_path = handle
.path()
.resolve("data/lib.rs", BaseDirectory::Resource)
.expect("failed to resolve resource");
let mut main_rust = std::fs::File::open(&resource_path).unwrap();
let mut contents = String::new();
main_rust.read_to_string(&mut contents).unwrap();
contents = contents.replace("WINDOWCONFIG", config.as_str());
// println!("Updated config file: {}", contents);
// The new file content, using Base64 encoding
let encoded_contents = BASE64_STANDARD.encode(contents);
return encoded_contents;
}

#[tauri::command]
pub async fn update_custom_js(handle: tauri::AppHandle, js_content: String) -> String {
let resource_path = handle
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub fn run() {
command::pakeplus::update_config_file,
command::pakeplus::update_cargo_file,
command::pakeplus::update_main_rust,
command::pakeplus::rust_lib_window,
command::pakeplus::update_custom_js,
command::pakeplus::content_to_base64,
command::pakeplus::update_config_json,
Expand Down
8 changes: 1 addition & 7 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@
"bundle": {
"active": true,
"targets": "all",
"resources": [
"./data/*",
"./data/config.json",
"./data/main.rs",
"./data/Cargo.toml",
"./data/custom.js"
],
"resources": ["./data/*"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
Expand Down
8 changes: 4 additions & 4 deletions src/pages/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1096,16 +1096,16 @@ const updateMainRs = async () => {
}
// update build.yml file content
const mainRsConfig = async () => {
const libRsConfig = async () => {
// get CargoToml file sha
const shaRes = await getFileSha(
'src-tauri/src/main.rs',
'src-tauri/src/lib.rs',
store.currentProject.name
)
console.log('get CargoToml file sha', shaRes)
if (shaRes.status === 200 || shaRes.status === 404) {
// get CargoToml file content
const configContent: any = await invoke('rust_main_window', {
const configContent: any = await invoke('rust_lib_window', {
config: JSON.stringify(tauriConfig.windows),
})
const updateRes: any = await githubApi.updateMainRsFile(
Expand Down Expand Up @@ -1174,7 +1174,7 @@ const onPublish = async () => {
await updateCargoToml()
// update main rust
// await updateMainRs()
await mainRsConfig()
await libRsConfig()
// update custom js
await updateCustomJs()
// update tauri config json
Expand Down

0 comments on commit 8a76cdb

Please sign in to comment.