Skip to content

Commit 49a4546

Browse files
authored
Accept variables from Omnibar in workflow steps (#97)
Bump to v1 🎉 - potential breaking changes below! ## Features - Add arguments support for workflows ## Updates - Update autocomplete-js to 1.7.4 - Refactor creation of Autocomplete - Changed the Autocomplete component to use @algolia/core for more control - Added styling for inputs and buttons in core components - Updated workflow-source, settings-source and math-source to work with the new autocomplete component, added descriptions
1 parent 27df99d commit 49a4546

21 files changed

+2067
-517
lines changed

package-lock.json

Lines changed: 1581 additions & 291 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
"version": "0.11.0",
44
"private": true,
55
"dependencies": {
6-
"@algolia/autocomplete-js": "^1.7.1",
6+
"@algolia/autocomplete-core": "^1.7.4",
7+
"@algolia/autocomplete-js": "^1.7.4",
78
"@algolia/autocomplete-theme-classic": "^1.7.1",
89
"@radix-ui/colors": "^0.1.8",
10+
"@radix-ui/react-icons": "^1.1.1",
11+
"@radix-ui/react-popover": "^1.0.2",
912
"@radix-ui/react-tabs": "^0.1.5",
1013
"@stitches/react": "^1.2.7",
1114
"@tauri-apps/api": "^1.1.0",
@@ -56,6 +59,6 @@
5659
},
5760
"devDependencies": {
5861
"@hookform/devtools": "^4.0.2",
59-
"@tauri-apps/cli": "^1.1.1"
62+
"@tauri-apps/cli": "^1.2.2"
6063
}
6164
}

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "brancato"
3-
version = "0.11.0"
3+
version = "1.0.0"
44
description = "A tool for stage-managing your life"
55
authors = ["Ryan Killeen"]
66
license = ""

src-tauri/src/main.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use app_config::{set_custom_user_config_path, AppConfig};
1111
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
1212
use rayon::prelude::*;
1313
use serde::Serialize;
14-
use std::{path::PathBuf, sync::Mutex};
14+
use std::{collections::HashMap, path::PathBuf, sync::Mutex};
1515
use tauri::{
1616
api::dialog::blocking::FileDialogBuilder, utils::platform::current_exe, AppHandle,
1717
CustomMenuItem, GlobalShortcutManager, Manager, RunEvent, State, SystemTray, SystemTrayEvent,
@@ -49,10 +49,10 @@ fn save_user_config(
4949
state: State<Mutex<UserConfig>>,
5050
app: AppHandle,
5151
config: UserConfig,
52-
) -> Result<(), tauri::Error> {
52+
) -> Result<&str, tauri::Error> {
5353
update_user_config_and_state(&app, state, config).ok();
5454

55-
Ok(())
55+
Ok("Success!".into())
5656
}
5757

5858
#[tauri::command]
@@ -130,16 +130,25 @@ fn set_user_config_path(app_config_state: State<Mutex<AppConfig>>) -> Option<Pat
130130
}
131131

132132
#[tauri::command]
133-
async fn run_workflow(state: State<'_, Mutex<UserConfig>>, label: String) -> Result<(), ()> {
133+
async fn run_workflow(
134+
state: State<'_, Mutex<UserConfig>>,
135+
name: String,
136+
args: HashMap<String, String>,
137+
) -> Result<(), ()> {
134138
let workflows = state.lock().expect("Can't unlock").clone().workflows;
135139

140+
// println!("{:?}", args);
141+
136142
workflows
137143
.into_iter()
138-
.find(|x| x.name == label)
144+
.find(|x| x.name == name)
139145
.expect("Couldn't find workflow")
140146
.steps
141147
.par_iter_mut()
142-
.for_each(|step| run_step(&step.value));
148+
.for_each(|step| {
149+
let copy = args.clone();
150+
run_step(&step.value, Some(copy))
151+
});
143152

144153
Ok(())
145154
}

src-tauri/src/workflows.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate open;
22
use serde::{Deserialize, Serialize};
3-
use std::{env, path::Path};
3+
use std::{collections::HashMap, env, path::Path};
44

55
#[derive(Debug, Serialize, Deserialize, Clone)]
66
pub struct Step {
@@ -11,6 +11,7 @@ pub struct Step {
1111
pub struct Workflow {
1212
pub name: String,
1313
pub steps: Vec<Step>,
14+
pub arguments: Option<Vec<String>>,
1415
}
1516

1617
// On Windows, some apps expect a relative working directory (Looking at you, OBS....)
@@ -21,10 +22,17 @@ pub fn open_app(path: &str) {
2122
open::that(path).expect("Dang")
2223
}
2324

24-
pub fn run_step(path: &str) {
25-
if path.contains("http://") || path.contains("https://") {
26-
open::that_in_background(&path);
25+
pub fn run_step(path: &str, args: Option<HashMap<String, String>>) {
26+
let mut target = path.to_string();
27+
if let Some(args) = args {
28+
for (key, value) in args {
29+
target = target.replace(&format!("${}", key), &value);
30+
}
31+
}
32+
println!("target: {:?}", &target);
33+
if target.contains("http://") || target.contains("https://") {
34+
open::that_in_background(&target);
2735
} else {
28-
open_app(&path);
36+
open_app(&target);
2937
}
3038
}

src-tauri/tauri.conf.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"package": {
3-
"productName": "brancato",
4-
"version": "0.11.0"
3+
"productName": "brancato"
54
},
65
"build": {
76
"distDir": "../build",

src/Config.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111

1212
export type Workflow = {
1313
name: string;
14+
arguments?: string[];
1415
steps: {
1516
value: string;
1617
}[];

src/components/Autocomplete.jsx

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

src/components/NewAutocomplete.jsx

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { createAutocomplete } from "@algolia/autocomplete-core";
2+
import { useState, useMemo } from "react";
3+
import { appWindow } from "@tauri-apps/api/window";
4+
5+
function Autocomplete({ getSources }) {
6+
// (1) Create a React state.
7+
const [autocompleteState, setAutocompleteState] = useState();
8+
const autocomplete = useMemo(
9+
() =>
10+
createAutocomplete({
11+
placeholder: "",
12+
openOnFocus: true,
13+
autoFocus: true,
14+
defaultActiveItemId: 0,
15+
onStateChange({ state }) {
16+
// (2) Synchronize the Autocomplete state with the state.
17+
setAutocompleteState(state);
18+
},
19+
getSources({ ...props }) {
20+
return getSources({ ...props });
21+
},
22+
}),
23+
[getSources]
24+
);
25+
26+
return (
27+
<form
28+
onSubmit={(e) => {
29+
e.preventDefault();
30+
const argKey = autocompleteState?.context?.searchPrefix ?? "";
31+
const argValue = {
32+
[argKey]: autocompleteState?.query,
33+
};
34+
console.log("argValue", argValue);
35+
autocompleteState?.context.onComplete &&
36+
autocompleteState.context.onComplete(argValue);
37+
}}
38+
>
39+
<div
40+
style={{
41+
backgroundColor: "white",
42+
padding: "0.5rem 1rem",
43+
borderRadius: "4px",
44+
boxShadow: "rgb(0 0 0 / 9%) 0px 3px 12px",
45+
}}
46+
onKeyDown={(e) => {
47+
if (e.key === "Escape") {
48+
autocomplete.setContext({ searchPrefix: null });
49+
appWindow.hide();
50+
}
51+
}}
52+
>
53+
<div className="aa-Autocomplete" {...autocomplete.getRootProps({})}>
54+
<div style={{ display: "flex", gap: "8px", alignItems: "center" }}>
55+
{autocompleteState?.context?.searchPrefix && (
56+
<span style={{ fontWeight: 900 }}>
57+
{autocompleteState?.context?.searchPrefix}:
58+
</span>
59+
)}
60+
<input className="aa-Input" {...autocomplete.getInputProps({})} />
61+
</div>
62+
63+
<div
64+
style={{
65+
padding: "1rem",
66+
boxShadow: "rgb(0 0 0 / 9%) 0px 3px 12px",
67+
width: "100%",
68+
left: 0,
69+
transform: "translateY(20px)",
70+
}}
71+
className="aa-Panel"
72+
{...autocomplete.getPanelProps({})}
73+
>
74+
{autocompleteState?.isOpen &&
75+
autocompleteState?.collections.map((collection, index) => {
76+
const { source, items } = collection;
77+
console.log({ source });
78+
return (
79+
<div key={`source-${index}`} className="aa-Source">
80+
{/* <h2>{source}</h2> */}
81+
{source.templates.header && source.templates.header()}
82+
{items.length > 0 && (
83+
<ul className="aa-List" {...autocomplete.getListProps()}>
84+
{items.map((item) => {
85+
return (
86+
<li
87+
className="aa-Item"
88+
{...autocomplete.getItemProps({
89+
item,
90+
source,
91+
})}
92+
>
93+
{source.templates.item({ item })}
94+
</li>
95+
);
96+
// <li
97+
// key={item.objectID}
98+
// className="aa-Item"
99+
// {...autocomplete.getItemProps({
100+
// item,
101+
// source,
102+
// })}
103+
// >
104+
// {item.label}
105+
// </li>
106+
})}
107+
</ul>
108+
)}
109+
</div>
110+
);
111+
})}
112+
</div>
113+
</div>
114+
</div>
115+
</form>
116+
);
117+
118+
// ...
119+
}
120+
121+
export default Autocomplete;

0 commit comments

Comments
 (0)