Skip to content

Commit

Permalink
add icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjj1024 committed Sep 21, 2024
1 parent 3e45f27 commit 03294e3
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 31 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "turnapp",
"name": "pakeplus",
"private": true,
"version": "0.1.0",
"type": "module",
Expand All @@ -9,7 +9,9 @@
"preview": "vite preview",
"tauri": "tauri",
"icon": "tauri icon",
"tauri dev": "tauri dev"
"tauri dev": "tauri dev",
"tauri build": "tauri build",
"tauri preview": "tauri preview"
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
Expand Down
20 changes: 10 additions & 10 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "turnapp"
name = "pakeplus"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
Expand All @@ -11,7 +11,7 @@ edition = "2021"
tauri-build = { version = "1", features = [] }

[dependencies]
tauri = { version = "1", features = [ "http-all", "window-all", "shell-open"] }
tauri = { version = "1", features = [ "fs-all", "http-all", "window-all", "shell-open"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Expand Down
4 changes: 4 additions & 0 deletions src-tauri/data/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "John",
"age": 30
}
13 changes: 9 additions & 4 deletions src-tauri/src/command/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub async fn open_docs(
app_name: String,
platform: String,
) {
println!("Opening docs in external window: {}", app_url);
println!("Opening docs in external window: {}, {}", app_url, platform);
let docs_window = tauri::WindowBuilder::new(
&handle,
"externaltauri", /* the unique window label */
Expand All @@ -17,8 +17,13 @@ pub async fn open_docs(
.unwrap();
}

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
pub fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
pub async fn read_json_file(handle: tauri::AppHandle) -> String {
let resource_path = handle
.path_resolver()
.resolve_resource("data/example.json")
.expect("failed to resolve resource");
let file = std::fs::File::open(&resource_path).unwrap();
let lang_de: serde_json::Value = serde_json::from_reader(file).unwrap();
return lang_de.to_string();
}
5 changes: 4 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ mod command;

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![command::preview::open_docs])
.invoke_handler(tauri::generate_handler![
command::preview::open_docs,
command::preview::read_json_file
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
11 changes: 9 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
"distDir": "../dist"
},
"package": {
"productName": "turnapp",
"productName": "PakePlus",
"version": "0.1.0"
},
"tauri": {
"allowlist": {
"all": false,
"fs": {
"all": true,
"readFile": true,
"writeFile": true,
"scope": ["$APPCONFIG/*"]
},
"http": {
"all": true,
"scope": ["https://api.github.com/*"]
Expand Down Expand Up @@ -40,7 +46,8 @@
"bundle": {
"active": true,
"targets": "all",
"identifier": "com.turnapp.app",
"identifier": "com.pakeplus.app",
"resources": ["./data/example.json"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
Expand Down
24 changes: 14 additions & 10 deletions src/pages/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<el-form-item label="APP图标" prop="icon">
<el-input
v-model="appForm.icon"
readonly
@click="uploadIcon"
placeholder="例如:本地上传,支持png、jpg、jpeg格式"
/>
Expand Down Expand Up @@ -101,10 +102,7 @@
>取消</el-button
>
&nbsp;&nbsp;&nbsp;&nbsp;
<el-button
type="primary"
@click="centerDialogVisible = false"
>
<el-button type="primary" @click="onSubmit">
确认
</el-button>
</div>
Expand All @@ -122,6 +120,7 @@ import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
import github from '@/apis/github'
import { ElMessage } from 'element-plus'
import { usePakeStore } from '@/store'
import { readTextFile, BaseDirectory } from '@tauri-apps/api/fs'
const router = useRouter()
const store = usePakeStore()
Expand All @@ -134,8 +133,8 @@ const appForm = reactive({
name: '掘金',
rename: 'Juejin',
appid: 'HelloJuejin',
icon: '',
version: '',
icon: 'default.png',
version: '1.0.1',
platform: 'desktop',
desc: '',
})
Expand Down Expand Up @@ -286,10 +285,15 @@ const form = reactive({
model: 'close',
})
const checkList = ref(['Value selected and disabled', 'Value A'])
const onSubmit = () => {
console.log('submit!')
const onSubmit = async () => {
centerDialogVisible.value = false
try {
const jsonContent: any = await invoke('read_json_file')
const data = JSON.parse(jsonContent)
console.log('json data:', data)
} catch (error) {
console.error('Error reading JSON file:', error)
}
}
onMounted(() => {
Expand Down

0 comments on commit 03294e3

Please sign in to comment.