Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export default defineConfig([
{ ignores: ["src-tauri/"]},
{ files: ["**/*.{js,mjs,cjs,jsx}"], plugins: { js }, extends: ["js/recommended"] },
{ files: ["**/*.{js,mjs,cjs,jsx}"], languageOptions: { globals: globals.browser } },
pluginReact.configs.flat.recommended,
pluginReact.configs.flat.recommended
]);
11 changes: 11 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-opener": "^2",
"@tauri-apps/plugin-store": "^2.2.0",
"clsx": "^2.1.1",
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand All @@ -26,6 +27,7 @@
"@tailwindcss/vite": "^4.1.6",
"@tauri-apps/cli": "^2",
"@types/bun": "latest",
"@types/json-schema": "^7.0.15",
"@typescript-eslint/eslint-plugin": "^8.36.0",
"@typescript-eslint/parser": "^8.36.0",
"@vitejs/plugin-react": "^4.3.4",
Expand Down
1 change: 1 addition & 0 deletions public/tools/apple_note.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/tools/notion.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions src-tauri/src/app_note.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::{
fs,
error::Error,
io::Write,
path::PathBuf,
process::Command,
};

fn write_temp_script(bytes: &[u8], stem: &str) -> std::io::Result<PathBuf> {
let mut path = std::env::temp_dir();
path.push(format!("{stem}.scpt"));
let mut file = fs::File::create(&path)?;
file.write_all(bytes)?;
Ok(path)
}
/*
** append text to the last most recent note
*/
pub fn append_note(text: &str) -> Result<(), Box<dyn Error>> {
const APPEND_NOTE: &[u8] = include_bytes!("scripts/append_note.scpt");
let script_path = write_temp_script(APPEND_NOTE, "append_note")?;
let status = Command::new("osascript")
.arg(script_path)
.arg(text)
.status()?;

if !status.success() {
return Err(format!("Failed to append note: {status}").into());
}
Ok(())
}

/*
** create a brand new note wiith title and body
*/
pub fn create_note(title: &str, body: &str) -> Result<(), Box<dyn Error>> {
const CREATE_NOTE: &[u8] = include_bytes!("scripts/create_note.scpt");
let script_path = write_temp_script(CREATE_NOTE, "create_note")?;
let status = Command::new("osascript")
.arg(script_path)
.arg(title)
.arg(body)
.status()?;

if !status.success() {
return Err(format!("Failed to create note: {status}").into());
}
Ok(())
}
41 changes: 41 additions & 0 deletions src-tauri/src/apps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

use std::error::Error;
use crate::app_note::{append_note, create_note};

/*
** app functions
*/
pub fn call(func: &str, args: &[&str]) -> Result<(), Box<dyn Error>> {
match func {
/*
** this function basically use osascript to append text to the last most recent note.
** it is launching app "Notes" and appending text to the last most recent note.
*/
"append_note" => {
if args.len() != 1 {
return Err(format!("append_note expects 1 argument, but got {}", args.len()).into());
}
append_note(&args[0])?;
Ok(())
}

/*
** this function also use osascript to create a new note with title and body.
** it is launching app "Notes" and creating a new note with title and body.
*/
"create_note" => {
if args.len() != 2 {
return Err(format!("create_note expects 2 arguments, but got {}", args.len()).into());
}
create_note(&args[0], &args[1])?;
Ok(())
}

/*************************************************************************************
** if the function is not found, return an error in case of unexpected function call.
*/
_ => {
return Err(format!("Unknown function: {func}").into());
}
}
}
14 changes: 7 additions & 7 deletions src-tauri/src/browser_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,20 @@ pub async fn launch_new_instance(

if is_dev {
command
.arg("--disable-web-security")
// .arg("--disable-web-security")
.arg("--disable-features=VizDisplayCompositor")
.arg("--ignore-certificate-errors")
// .arg("--ignore-certificate-errors")
.arg("--allow-running-insecure-content");
}

/*
** nice visual cue in dev, blank tab in prod
*/
command.arg(if is_dev {
"https://www.google.com"
} else {
"about:blank"
});
// command.arg(if is_dev {
// "https://www.google.com"
// } else {
// "about:blank"
// });

let mut child_process = command
.stdout(Stdio::piped())
Expand Down
24 changes: 23 additions & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ use crate::browser_manager::{
sunset_browser_instance,
};
use crate::utils::download_and_extract;
use crate::skills::download_skill_json;
use crate::sketchs_browser::WebsiteSkills;
use crate::apps::call;

#[tauri::command]
pub async fn download_and_extract_resource(url: String) -> Result<String, String> {
Expand Down Expand Up @@ -137,7 +140,7 @@ pub async fn launch_browser(browser_path: Option<String>) -> Result<String, Stri

match launch_new_instance(&target_browser_path, port).await {
Ok(ws_url) => {
let _ = create_new_page(port, Some("https://www.google.com")).await;
// let _ = create_new_page(port, Some("https://www.google.com")).await;
Ok(ws_url)
}
Err(e) => Err(format!(
Expand Down Expand Up @@ -225,3 +228,22 @@ pub async fn debug_browser_connection(browser_path: String) -> Result<String, St
Ok(debug_info.join("\n"))
}

#[tauri::command]
pub async fn load_skills(
domain: &str,
company: Option<String>,
repo: Option<String>,
branch: String
) -> Result<WebsiteSkills, String> {
println!("loading skills for domain: {}", domain);
download_skill_json(domain.to_string(), company, repo, branch).await
}

#[tauri::command]
pub async fn call_app(func: String, args: Vec<String>) -> Result<String, String> {
// run the dispatcher ; map Ok() to () and Err() to String
let string_refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
call(&func, &string_refs)
.map(|_| "OK".to_string())
.map_err(|e| e.to_string())
}
12 changes: 10 additions & 2 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
mod utils;
mod skills;
mod apps;
mod app_note;
mod config;
mod sketchs;
mod sketchs_browser;
mod network;
mod commands;
mod platform;
Expand All @@ -15,7 +19,9 @@ use commands::{
validate_ws_endpoint,
scan_for_existing_browsers,
debug_browser_connection,
download_and_extract_resource
download_and_extract_resource,
load_skills,
call_app
};

#[cfg_attr(mobile, tauri::mobile_entry_point)]
Expand All @@ -32,7 +38,9 @@ pub fn run() {
validate_ws_endpoint,
scan_for_existing_browsers,
debug_browser_connection,
download_and_extract_resource
download_and_extract_resource,
load_skills,
call_app
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub async fn create_new_page(port: u16, url: Option<&str>) -> Result<String, Str
.build()
.map_err(|e| format!("Failed to create HTTP client: {e}"))?;

let target_url = url.unwrap_or("about:blank");
let target_url = url.unwrap_or("");
let new_page_url = format!("http://127.0.0.1:{port}/json/new?{target_url}");

println!("creating new page: {new_page_url}");
Expand Down
Binary file added src-tauri/src/scripts/append_note.scpt
Binary file not shown.
Binary file added src-tauri/src/scripts/create_note.scpt
Binary file not shown.
3 changes: 2 additions & 1 deletion src-tauri/src/sketchs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ pub struct PuppeteerExecutionResult {
pub error_message: Option<String>,
pub current_url: Option<String>,
pub page_context: Option<serde_json::Value>,
}
}

32 changes: 32 additions & 0 deletions src-tauri/src/sketchs_browser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
pub struct WebsiteSkills {
pub domain: String,
pub skills: Vec<SkillDefinition>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct SkillDefinition {
pub name: String,
pub description: String,
#[serde(default)]
pub input: Option<std::collections::HashMap<String, String>>,
#[serde(default)]
pub output: Option<String>,
pub steps: Vec<SkillStep>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct SkillStep {
pub action: String,
#[serde(default)]
pub selector: Option<String>,
#[serde(default)]
pub input_key: Option<String>,
#[serde(default)]
pub index: Option<u32>,
#[serde(default)]
pub output_key: Option<String>,
}

29 changes: 29 additions & 0 deletions src-tauri/src/skills.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use reqwest::Client;
use crate::sketchs_browser::WebsiteSkills;

pub async fn download_skill_json(
domain: String,
company: Option<String>,
repo: Option<String>,
branch: String,
) -> Result<WebsiteSkills, String> {
let company: String = company.unwrap_or_else(|| "runtime-org".to_string());
let repo: String = repo.unwrap_or_else(|| "sk".to_string());
let url: String = format!("https://raw.githubusercontent.com/{company}/{repo}/{branch}/skills/{domain}.json");
println!("downloading skills from: {}", url);
let text: String = Client::new()
.get(url)
.send()
.await
.map_err(|e| format!("Failed to download skill file for {domain}: {e}"))?
.text()
.await
.map_err(|e| format!("Failed to download skill file for {company}.{domain}: {e}"))?;

let parsed: WebsiteSkills = serde_json::from_str(&text)
.map_err(|e| format!("Failed to parse skill file for {domain}: {e}"))?;

println!("parsed: {:?}", parsed);

Ok(parsed)
}
9 changes: 7 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
{
"title": "runtime",
"width": 400,
"height": 700
"height": 700,
"resizable": true,
"minWidth": 400,
"maxWidth": 400,
"minHeight": 600
}
],
"security": {
Expand All @@ -30,6 +34,7 @@
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
],
"resources": ["src/scripts/*.scpt"]
}
}
Loading