mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-29 06:28:12 +08:00
Make tool settings JSON errors safer
This commit is contained in:
@@ -56,6 +56,7 @@ interface NumberOption {
|
|||||||
kind: "number";
|
kind: "number";
|
||||||
initial: number;
|
initial: number;
|
||||||
step: number;
|
step: number;
|
||||||
|
min?: number;
|
||||||
callback?: Function;
|
callback?: Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +117,7 @@ export default defineComponent({
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
["Shape", [{ kind: "number", initial: 6, step: 1, min: 3, callback: this.setToolSettings }]],
|
["Shape", [{ kind: "number", initial: 6, step: 1, min: 3, callback: this.setToolSettings }]],
|
||||||
]),
|
]) as ToolOptionsMap,
|
||||||
SeparatorType,
|
SeparatorType,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -27,11 +27,13 @@ pub fn select_tool(tool: String) -> Result<(), JsValue> {
|
|||||||
/// Update the settings for a given tool
|
/// Update the settings for a given tool
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn set_tool_settings(tool: String, settings: &JsValue) -> Result<(), JsValue> {
|
pub fn set_tool_settings(tool: String, settings: &JsValue) -> Result<(), JsValue> {
|
||||||
let settings: ToolSettings = settings.into_serde().expect("Invalid JSON for ToolSettings");
|
match settings.into_serde::<ToolSettings>() {
|
||||||
EDITOR_STATE.with(|editor| match translate_tool(&tool) {
|
Ok(settings) => EDITOR_STATE.with(|editor| match translate_tool(&tool) {
|
||||||
Some(tool) => editor.borrow_mut().handle_message(ToolMessage::SetToolSettings(tool, settings)).map_err(convert_error),
|
Some(tool) => editor.borrow_mut().handle_message(ToolMessage::SetToolSettings(tool, settings)).map_err(convert_error),
|
||||||
None => Err(Error::new(&format!("Couldn't select {} because it was not recognized as a valid tool", tool)).into()),
|
None => Err(Error::new(&format!("Couldn't select {} because it was not recognized as a valid tool", tool)).into()),
|
||||||
})
|
}),
|
||||||
|
Err(err) => Err(Error::new(&format!("Invalud JSON for ToolSettings: {}", err)).into()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
|
|||||||
Reference in New Issue
Block a user