Skip to content

Commit b25c26a

Browse files
fix read json
1 parent 215ff5c commit b25c26a

File tree

10 files changed

+225
-125
lines changed

10 files changed

+225
-125
lines changed

guide.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ Tzcode
2525
│   ├── error.log
2626
│   └── user
2727
├── .Tzocde
28-
│   └── ...
28+
│   └── ...
29+
30+
example release:
31+
/zhangzijie-pro/Tiks/releases/download/1.0.0/tiks -> /usrname/productname/releases/download/{target-os}/{version}/app(linux binary or window exe)

py/server.py

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
app = Flask(__name__)
77
CORS(app)
88

9-
# Paths to JSON files
109
workspace_path = os.path.join(os.path.dirname(__file__), '../space/workspace.json')
1110
key_path = os.path.join(os.path.dirname(__file__), '../space/key.json')
11+
space_color_path = os.path.join(os.path.dirname(__file__), '../space/space-color.json')
1212

1313
def read_json(file_path):
1414
try:
@@ -26,62 +26,69 @@ def write_json(file_path, data):
2626

2727
@app.route('/<path>', methods=['GET'])
2828
def get_data(path):
29-
file_path = workspace_path if path == 'workspace' else key_path
30-
data = read_json(file_path)
31-
if "error" in data:
32-
return jsonify(data), 500
29+
file_path = {
30+
'workspace': workspace_path,
31+
'key': key_path,
32+
'space-color': space_color_path
33+
}.get(path)
34+
if file_path:
35+
data = read_json(file_path)
36+
return jsonify(data)
37+
else:
38+
return jsonify({"error": "Invalid path"}), 400
39+
40+
@app.route('/workspace', methods=['POST'])
41+
def add_workspace():
42+
user_input = request.json.get('input')
43+
data = read_json(workspace_path)
44+
data['workspace'].append(user_input)
45+
write_json(workspace_path, data)
3346
return jsonify(data)
3447

35-
@app.route('/receive-message', methods=['GET'])
36-
def receive_message():
37-
message = "This is a local message."
38-
return jsonify({"message": message})
48+
@app.route('/workspace', methods=['DELETE'])
49+
def delete_workspace():
50+
index = int(request.json.get('index'))
51+
data = read_json(workspace_path)
52+
try:
53+
data['workspace'].pop(index)
54+
except IndexError:
55+
return jsonify({"error": "Invalid index"}), 400
56+
write_json(workspace_path, data)
57+
return jsonify(data)
3958

40-
@app.route('/<path>', methods=['POST'])
41-
def send_input(path):
42-
file_path = workspace_path if path == 'workspace' else key_path
43-
data = request.json
44-
user_input = data.get('input')
45-
if not user_input:
46-
return jsonify({"error": "No input provided"}), 400
59+
@app.route('/key', methods=['POST'])
60+
def add_key():
61+
user_input = request.json.get('input')
62+
data = read_json(key_path)
63+
data['key'].append(user_input)
64+
write_json(key_path, data)
65+
return jsonify(data)
4766

48-
json_data = read_json(file_path)
49-
if "error" in json_data:
50-
return jsonify(json_data), 500
67+
@app.route('/key', methods=['DELETE'])
68+
def delete_key():
69+
index = int(request.json.get('index'))
70+
data = read_json(key_path)
71+
try:
72+
data['key'].pop(index)
73+
except IndexError:
74+
return jsonify({"error": "Invalid index"}), 400
75+
write_json(key_path, data)
76+
return jsonify(data)
5177

52-
item_list = json_data.get(path, [])
53-
if user_input not in item_list:
54-
item_list.append(user_input)
55-
json_data[path] = item_list
56-
write_json(file_path, json_data)
57-
58-
return jsonify({path: item_list})
78+
@app.route('/space-color', methods=['POST'])
79+
def update_space_color():
80+
user_input = request.json.get('input')
81+
nested_keys = request.json.get('keys')
82+
data = read_json(space_color_path)
5983

60-
@app.route('/<path>', methods=['DELETE'])
61-
def delete_input(path):
62-
file_path = workspace_path if path == 'workspace' else key_path
63-
data = request.json
64-
index = data.get('index')
65-
if index is None:
66-
return jsonify({"error": "No index provided"}), 400
84+
d = data['workspace']['background']
85+
for key in nested_keys[:-1]:
86+
d = d[key]
87+
d[nested_keys[-1]] = user_input
6788

68-
json_data = read_json(file_path)
69-
if "error" in json_data:
70-
return jsonify(json_data), 500
89+
write_json(space_color_path, data)
90+
return jsonify(data)
7191

72-
item_list = json_data.get(path, [])
73-
try:
74-
index = int(index)
75-
if 0 <= index < len(item_list):
76-
item_list.pop(index)
77-
json_data[path] = item_list
78-
write_json(file_path, json_data)
79-
else:
80-
return jsonify({"error": "Index out of range"}), 400
81-
except ValueError:
82-
return jsonify({"error": "Invalid index"}), 400
83-
84-
return jsonify({path: item_list})
8592

8693
if __name__ == '__main__':
87-
app.run(host='127.0.0.1', port=5000)
94+
app.run(host='127.0.0.1', port=5000)

space/space-color.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"workspace": {
3+
"background": {
4+
"menu": "",
5+
"footer": "",
6+
"terimal": "",
7+
"code-editor": "",
8+
"left-file": "",
9+
"right-file": ""
10+
}
11+
}
12+
}

space/space.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

src-tauri/src/page/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub mod new_window{
3030
)
3131
.title("setting")
3232
.fullscreen(false)
33-
.resizable(false)
34-
.decorations(false)
33+
.resizable(true)
34+
.decorations(true)
3535
.inner_size(300.0, 250.0)
3636
.visible(true)
3737
.build()

ui/css/setting/setting.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@
2121

2222
body{
2323
background-color: antiquewhite;
24+
}
25+
26+
.hidden {
27+
display: none;
2428
}

ui/js/menu.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ document.getElementById('titlebar-close').addEventListener('click', () => {
1717

1818

1919
// toggle color
20+
import {rightfileValue,leftfileValue,codeEditorValue,terimalValue,menuValue,footerValue} from "../js/setting"
2021

2122
function changeBackgroundColor(selectors, newColor,originalColor,isOriginalColor) {
2223
selectors.forEach(selector => {
@@ -31,15 +32,30 @@ function changeBackgroundColor(selectors, newColor,originalColor,isOriginalColor
3132
});
3233
}
3334

35+
function change_color(rfv,lfv,ce,tl,menu,ft,isOriginalColor){
36+
changeBackgroundColor(['.titlebar'],menu,'#329ea3',isOriginalColor);
37+
changeBackgroundColor(['.footer'],ft,'#1e1e1e',isOriginalColor);
38+
changeBackgroundColor(['.bottom-section','input'],tl,'#252526',isOriginalColor);
39+
changeBackgroundColor(['.CodeMirror'],ce,'#e4e3e3 !important',isOriginalColor);
40+
changeBackgroundColor(['.initial-page','.top-section'],ce,'#1e1e1e',isOriginalColor);
41+
changeBackgroundColor(['.left-file'],lfv,'#3c3c3c',isOriginalColor);
42+
changeBackgroundColor(['.right-file','.sidebar'],rfv,'#2c2c2c',isOriginalColor);
43+
}
44+
3445
let isOriginalColor = true;
3546
document.getElementById('titlebar-background').addEventListener('click',()=>{
36-
changeBackgroundColor(['.titlebar'],'#8f9092','#329ea3',isOriginalColor);
47+
/* changeBackgroundColor(['.titlebar'],'#8f9092','#329ea3',isOriginalColor);
3748
changeBackgroundColor(['.footer'],'#8f9092','#1e1e1e',isOriginalColor);
3849
changeBackgroundColor(['.bottom-section','input'],'','#252526',isOriginalColor);
3950
changeBackgroundColor(['.CodeMirror'],'','#e4e3e3 !important',isOriginalColor);
4051
changeBackgroundColor(['.initial-page','.top-section'],'','#1e1e1e',isOriginalColor);
4152
changeBackgroundColor(['.left-file'],'#fff','#3c3c3c',isOriginalColor);
42-
changeBackgroundColor(['.right-file','.sidebar'],'#ff1','#2c2c2c',isOriginalColor);
53+
changeBackgroundColor(['.right-file','.sidebar'],'#ff7','#2c2c2c',isOriginalColor);
4354
55+
isOriginalColor=!isOriginalColor; */
56+
change_color(rightfileValue,leftfileValue,codeEditorValue,terimalValue,menuValue,footerValue,isOriginalColor);
4457
isOriginalColor=!isOriginalColor;
58+
console.log(rightfileValue);
59+
4560
})
61+

0 commit comments

Comments
 (0)