mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-22 17:39:46 +01:00
Recursive Insomnia import!
This commit is contained in:
@@ -12,7 +12,7 @@ module.exports = {
|
|||||||
parserOptions: {
|
parserOptions: {
|
||||||
project: ["./tsconfig.json"]
|
project: ["./tsconfig.json"]
|
||||||
},
|
},
|
||||||
ignorePatterns: ["src-tauri/**/*"],
|
ignorePatterns: ["src-tauri/**/*", "plugins/**/*"],
|
||||||
settings: {
|
settings: {
|
||||||
react: {
|
react: {
|
||||||
version: "detect"
|
version: "detect"
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
import { importEnvironment } from './importers/environment.js';
|
|
||||||
import { importRequest } from './importers/request.js';
|
|
||||||
import { importWorkspace } from './importers/workspace.js';
|
|
||||||
|
|
||||||
const TYPES = {
|
|
||||||
workspace: 'workspace',
|
|
||||||
request: 'request',
|
|
||||||
environment: 'environment',
|
|
||||||
};
|
|
||||||
|
|
||||||
export function pluginHookImport(contents) {
|
|
||||||
const parsed = JSON.parse(contents);
|
|
||||||
if (!isObject(parsed)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { _type, __export_format } = parsed;
|
|
||||||
if (_type !== 'export' || __export_format !== 4 || !Array.isArray(parsed.resources)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const resources = {
|
|
||||||
workspaces: [],
|
|
||||||
requests: [],
|
|
||||||
environments: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const v of parsed.resources) {
|
|
||||||
if (v._type === TYPES.workspace) {
|
|
||||||
resources.workspaces.push(importWorkspace(v));
|
|
||||||
} else if (v._type === TYPES.environment) {
|
|
||||||
resources.environments.push(importEnvironment(v));
|
|
||||||
} else if (v._type === TYPES.request) {
|
|
||||||
resources.requests.push(importRequest(v));
|
|
||||||
} else {
|
|
||||||
console.log('UNKNOWN TYPE', v._type, JSON.stringify(v, null, 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter out any `null` values
|
|
||||||
resources.requests = resources.requests.filter(Boolean);
|
|
||||||
resources.environments = resources.environments.filter(Boolean);
|
|
||||||
resources.workspaces = resources.workspaces.filter(Boolean);
|
|
||||||
|
|
||||||
return resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isObject(obj) {
|
|
||||||
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
||||||
}
|
|
||||||
@@ -39,7 +39,7 @@ tauri = { version = "1.3", features = [
|
|||||||
"shell-open",
|
"shell-open",
|
||||||
"system-tray",
|
"system-tray",
|
||||||
"updater",
|
"updater",
|
||||||
"window-start-dragging",
|
"window-start-dragging",
|
||||||
"dialog-open",
|
"dialog-open",
|
||||||
] }
|
] }
|
||||||
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
|
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
|
||||||
|
|||||||
1133
src-tauri/plugins/insomnia-importer/Insomnia_bigger.json
Normal file
1133
src-tauri/plugins/insomnia-importer/Insomnia_bigger.json
Normal file
File diff suppressed because it is too large
Load Diff
19
src-tauri/plugins/insomnia-importer/helpers/types.js
Normal file
19
src-tauri/plugins/insomnia-importer/helpers/types.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
export function isWorkspace(obj) {
|
||||||
|
return isJSObject(obj) && obj._type === 'workspace';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isRequestGroup(obj) {
|
||||||
|
return isJSObject(obj) && obj._type === 'request_group';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isRequest(obj) {
|
||||||
|
return isJSObject(obj) && obj._type === 'request';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isEnvironment(obj) {
|
||||||
|
return isJSObject(obj) && obj._type === 'environment';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isJSObject(obj) {
|
||||||
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
||||||
|
}
|
||||||
7
src-tauri/plugins/insomnia-importer/helpers/variables.js
Normal file
7
src-tauri/plugins/insomnia-importer/helpers/variables.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export function parseVariables(data) {
|
||||||
|
return Object.entries(data).map(([name, value]) => ({
|
||||||
|
enabled: true,
|
||||||
|
name,
|
||||||
|
value: `${value}`,
|
||||||
|
}));
|
||||||
|
}
|
||||||
@@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Import an Insomnia environment object.
|
* Import an Insomnia environment object.
|
||||||
* @param {Object} e - The environment object to import.
|
* @param {Object} e - The environment object to import.
|
||||||
|
* @param workspaceId - Workspace to import into.
|
||||||
*/
|
*/
|
||||||
export function importEnvironment(e) {
|
export function importEnvironment(e, workspaceId) {
|
||||||
if (e.parentId.startsWith('env_')) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
console.log('IMPORTING Environment', e._id, e.name, JSON.stringify(e, null, 2));
|
console.log('IMPORTING Environment', e._id, e.name, JSON.stringify(e, null, 2));
|
||||||
return {
|
return {
|
||||||
id: e._id,
|
id: e._id,
|
||||||
createdAt: new Date(e.created ?? Date.now()).toISOString().replace('Z', ''),
|
createdAt: new Date(e.created ?? Date.now()).toISOString().replace('Z', ''),
|
||||||
updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace('Z', ''),
|
updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace('Z', ''),
|
||||||
workspaceId: e.parentId,
|
workspaceId,
|
||||||
model: 'environment',
|
model: 'environment',
|
||||||
name: e.name,
|
name: e.name,
|
||||||
variables: Object.entries(e.data).map(([name, value]) => ({
|
variables: Object.entries(e.data).map(([name, value]) => ({
|
||||||
17
src-tauri/plugins/insomnia-importer/importers/folder.js
Normal file
17
src-tauri/plugins/insomnia-importer/importers/folder.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Import an Insomnia folder object.
|
||||||
|
* @param {Object} f - The environment object to import.
|
||||||
|
* @param workspaceId - Workspace to import into.
|
||||||
|
*/
|
||||||
|
export function importFolder(f, workspaceId) {
|
||||||
|
console.log('IMPORTING FOLDER', f._id, f.name, JSON.stringify(f, null, 2));
|
||||||
|
return {
|
||||||
|
id: f._id,
|
||||||
|
createdAt: new Date(f.created ?? Date.now()).toISOString().replace('Z', ''),
|
||||||
|
updatedAt: new Date(f.updated ?? Date.now()).toISOString().replace('Z', ''),
|
||||||
|
folderId: f.parentId === workspaceId ? null : f.parentId,
|
||||||
|
workspaceId,
|
||||||
|
model: 'folder',
|
||||||
|
name: f.name,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* Import an Insomnia request object.
|
* Import an Insomnia request object.
|
||||||
* @param {Object} r - The request object to import.
|
* @param {Object} r - The request object to import.
|
||||||
|
* @param workspaceId - The workspace ID to use for the request.
|
||||||
* @param {number} sortPriority - The sort priority to use for the request.
|
* @param {number} sortPriority - The sort priority to use for the request.
|
||||||
*/
|
*/
|
||||||
export function importRequest(r, sortPriority = 0) {
|
export function importRequest(r, workspaceId, sortPriority = 0) {
|
||||||
console.log('IMPORTING REQUEST', r._id, r.name, JSON.stringify(r, null, 2));
|
console.log('IMPORTING REQUEST', r._id, r.name, JSON.stringify(r, null, 2));
|
||||||
return {
|
return {
|
||||||
id: r._id,
|
id: r._id,
|
||||||
createdAt: new Date(r.created ?? Date.now()).toISOString().replace('Z', ''),
|
createdAt: new Date(r.created ?? Date.now()).toISOString().replace('Z', ''),
|
||||||
updatedAt: new Date(r.updated ?? Date.now()).toISOString().replace('Z', ''),
|
updatedAt: new Date(r.updated ?? Date.now()).toISOString().replace('Z', ''),
|
||||||
workspaceId: r.parentId,
|
workspaceId,
|
||||||
|
folderId: r.parentId === workspaceId ? null : r.parentId,
|
||||||
model: 'http_request',
|
model: 'http_request',
|
||||||
sortPriority,
|
sortPriority,
|
||||||
name: r.name,
|
name: r.name,
|
||||||
@@ -2,13 +2,14 @@
|
|||||||
* Import an Insomnia workspace object.
|
* Import an Insomnia workspace object.
|
||||||
* @param {Object} w - The workspace object to import.
|
* @param {Object} w - The workspace object to import.
|
||||||
*/
|
*/
|
||||||
export function importWorkspace(w) {
|
export function importWorkspace(w, variables) {
|
||||||
console.log('IMPORTING Workpace', w._id, w.name, JSON.stringify(w, null, 2));
|
console.log('IMPORTING Workspace', w._id, w.name, JSON.stringify(w, null, 2));
|
||||||
return {
|
return {
|
||||||
id: w._id,
|
id: w._id,
|
||||||
createdAt: new Date(w.created ?? Date.now()).toISOString().replace('Z', ''),
|
createdAt: new Date(w.created ?? Date.now()).toISOString().replace('Z', ''),
|
||||||
updatedAt: new Date(w.updated ?? Date.now()).toISOString().replace('Z', ''),
|
updatedAt: new Date(w.updated ?? Date.now()).toISOString().replace('Z', ''),
|
||||||
model: 'workspace',
|
model: 'workspace',
|
||||||
name: w.name,
|
name: w.name,
|
||||||
|
variables,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
78
src-tauri/plugins/insomnia-importer/index.js
Normal file
78
src-tauri/plugins/insomnia-importer/index.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import { importEnvironment } from './importers/environment.js';
|
||||||
|
import { importRequest } from './importers/request.js';
|
||||||
|
import { importWorkspace } from './importers/workspace.js';
|
||||||
|
import {
|
||||||
|
isEnvironment,
|
||||||
|
isJSObject,
|
||||||
|
isRequest,
|
||||||
|
isRequestGroup,
|
||||||
|
isWorkspace,
|
||||||
|
} from './helpers/types.js';
|
||||||
|
import { parseVariables } from './helpers/variables.js';
|
||||||
|
import { importFolder } from './importers/folder.js';
|
||||||
|
|
||||||
|
export function pluginHookImport(contents) {
|
||||||
|
const parsed = JSON.parse(contents);
|
||||||
|
if (!isJSObject(parsed)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { _type, __export_format } = parsed;
|
||||||
|
if (_type !== 'export' || __export_format !== 4 || !Array.isArray(parsed.resources)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resources = {
|
||||||
|
workspaces: [],
|
||||||
|
requests: [],
|
||||||
|
environments: [],
|
||||||
|
folders: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Import workspaces
|
||||||
|
const workspacesToImport = parsed.resources.filter(isWorkspace);
|
||||||
|
for (const workspaceToImport of workspacesToImport) {
|
||||||
|
console.log('IMPORTING WORKSPACE', workspaceToImport.name);
|
||||||
|
const baseEnvironment = parsed.resources.find(
|
||||||
|
(r) => isEnvironment(r) && r.parentId === workspaceToImport._id,
|
||||||
|
);
|
||||||
|
console.log('FOUND BASE ENV', baseEnvironment.name);
|
||||||
|
resources.workspaces.push(
|
||||||
|
importWorkspace(
|
||||||
|
workspaceToImport,
|
||||||
|
baseEnvironment ? parseVariables(baseEnvironment.data) : [],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
console.log('IMPORTING ENVIRONMENTS', baseEnvironment.name);
|
||||||
|
const environmentsToImport = parsed.resources.filter(
|
||||||
|
(r) => isEnvironment(r) && r.parentId === baseEnvironment?._id,
|
||||||
|
);
|
||||||
|
console.log('FOUND', environmentsToImport.length, 'ENVIRONMENTS');
|
||||||
|
resources.environments.push(
|
||||||
|
...environmentsToImport.map((r) => importEnvironment(r, workspaceToImport._id)),
|
||||||
|
);
|
||||||
|
|
||||||
|
const nextFolder = (parentId) => {
|
||||||
|
const children = parsed.resources.filter((r) => r.parentId === parentId);
|
||||||
|
let sortPriority = 0;
|
||||||
|
for (const child of children) {
|
||||||
|
if (isRequestGroup(child)) {
|
||||||
|
resources.folders.push(importFolder(child, workspaceToImport._id));
|
||||||
|
nextFolder(child._id);
|
||||||
|
} else if (isRequest(child)) {
|
||||||
|
resources.requests.push(importRequest(child, workspaceToImport._id, sortPriority++));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Import folders
|
||||||
|
nextFolder(workspaceToImport._id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter out any `null` values
|
||||||
|
resources.requests = resources.requests.filter(Boolean);
|
||||||
|
resources.environments = resources.environments.filter(Boolean);
|
||||||
|
resources.workspaces = resources.workspaces.filter(Boolean);
|
||||||
|
|
||||||
|
return resources;
|
||||||
|
}
|
||||||
@@ -32,11 +32,11 @@ use tokio::sync::Mutex;
|
|||||||
|
|
||||||
use window_ext::TrafficLightWindowExt;
|
use window_ext::TrafficLightWindowExt;
|
||||||
|
|
||||||
mod menu;
|
|
||||||
mod models;
|
mod models;
|
||||||
mod plugin;
|
mod plugin;
|
||||||
mod render;
|
mod render;
|
||||||
mod window_ext;
|
mod window_ext;
|
||||||
|
mod window_menu;
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
pub struct CustomResponse {
|
pub struct CustomResponse {
|
||||||
@@ -266,16 +266,13 @@ async fn import_data(
|
|||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_instance: State<'_, Mutex<Pool<Sqlite>>>,
|
db_instance: State<'_, Mutex<Pool<Sqlite>>>,
|
||||||
file_paths: Vec<&str>,
|
file_paths: Vec<&str>,
|
||||||
workspace_id: Option<&str>,
|
|
||||||
) -> Result<plugin::ImportedResources, String> {
|
) -> Result<plugin::ImportedResources, String> {
|
||||||
let pool = &*db_instance.lock().await;
|
let pool = &*db_instance.lock().await;
|
||||||
let workspace_id2 = workspace_id.unwrap_or_default();
|
|
||||||
let imported = plugin::run_plugin_import(
|
let imported = plugin::run_plugin_import(
|
||||||
&window.app_handle(),
|
&window.app_handle(),
|
||||||
pool,
|
pool,
|
||||||
"insomnia-importer",
|
"insomnia-importer",
|
||||||
file_paths.first().unwrap(),
|
file_paths.first().unwrap(),
|
||||||
workspace_id2,
|
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
Ok(imported)
|
Ok(imported)
|
||||||
@@ -764,7 +761,6 @@ fn main() {
|
|||||||
&pool,
|
&pool,
|
||||||
"insomnia-importer",
|
"insomnia-importer",
|
||||||
arg_file,
|
arg_file,
|
||||||
"wk_WN8Nrm2Awm",
|
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
exit(0);
|
exit(0);
|
||||||
@@ -834,7 +830,7 @@ fn is_dev() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_window(handle: &AppHandle<Wry>, url: Option<&str>) -> Window<Wry> {
|
fn create_window(handle: &AppHandle<Wry>, url: Option<&str>) -> Window<Wry> {
|
||||||
let mut app_menu = menu::os_default("Yaak".to_string().as_str());
|
let mut app_menu = window_menu::os_default("Yaak".to_string().as_str());
|
||||||
if is_dev() {
|
if is_dev() {
|
||||||
let submenu = Submenu::new(
|
let submenu = Submenu::new(
|
||||||
"Developer",
|
"Developer",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
|
use boa_engine::builtins::promise::PromiseState;
|
||||||
use boa_engine::{
|
use boa_engine::{
|
||||||
js_string,
|
js_string,
|
||||||
module::{ModuleLoader, SimpleModuleLoader},
|
module::{ModuleLoader, SimpleModuleLoader},
|
||||||
@@ -12,7 +13,7 @@ use serde_json::json;
|
|||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use tauri::AppHandle;
|
use tauri::AppHandle;
|
||||||
|
|
||||||
use crate::models::{self, Environment, HttpRequest, Workspace};
|
use crate::models::{self, Environment, Folder, HttpRequest, Workspace};
|
||||||
|
|
||||||
pub fn run_plugin_hello(app_handle: &AppHandle, plugin_name: &str) {
|
pub fn run_plugin_hello(app_handle: &AppHandle, plugin_name: &str) {
|
||||||
run_plugin(app_handle, plugin_name, "hello", &[]);
|
run_plugin(app_handle, plugin_name, "hello", &[]);
|
||||||
@@ -20,9 +21,10 @@ pub fn run_plugin_hello(app_handle: &AppHandle, plugin_name: &str) {
|
|||||||
|
|
||||||
#[derive(Default, Debug, Deserialize, Serialize)]
|
#[derive(Default, Debug, Deserialize, Serialize)]
|
||||||
pub struct ImportedResources {
|
pub struct ImportedResources {
|
||||||
requests: Vec<HttpRequest>,
|
|
||||||
environments: Vec<Environment>,
|
|
||||||
workspaces: Vec<Workspace>,
|
workspaces: Vec<Workspace>,
|
||||||
|
environments: Vec<Environment>,
|
||||||
|
folders: Vec<Folder>,
|
||||||
|
requests: Vec<HttpRequest>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run_plugin_import(
|
pub async fn run_plugin_import(
|
||||||
@@ -30,9 +32,9 @@ pub async fn run_plugin_import(
|
|||||||
pool: &Pool<Sqlite>,
|
pool: &Pool<Sqlite>,
|
||||||
plugin_name: &str,
|
plugin_name: &str,
|
||||||
file_path: &str,
|
file_path: &str,
|
||||||
workspace_id: &str,
|
|
||||||
) -> ImportedResources {
|
) -> ImportedResources {
|
||||||
let file = fs::read_to_string(file_path).expect("Unable to read file");
|
let file = fs::read_to_string(file_path)
|
||||||
|
.expect(format!("Unable to read file {}", file_path.to_string()).as_str());
|
||||||
let file_contents = file.as_str();
|
let file_contents = file.as_str();
|
||||||
let result_json = run_plugin(
|
let result_json = run_plugin(
|
||||||
app_handle,
|
app_handle,
|
||||||
@@ -44,34 +46,35 @@ pub async fn run_plugin_import(
|
|||||||
serde_json::from_value(result_json).expect("failed to parse result json");
|
serde_json::from_value(result_json).expect("failed to parse result json");
|
||||||
let mut imported_resources = ImportedResources::default();
|
let mut imported_resources = ImportedResources::default();
|
||||||
|
|
||||||
println!("Importing resources: {}", workspace_id.is_empty());
|
println!("Importing resources");
|
||||||
if workspace_id.is_empty() {
|
for w in resources.workspaces {
|
||||||
for w in resources.workspaces {
|
println!("Importing workspace: {:?}", w);
|
||||||
println!("Importing workspace: {:?}", w);
|
let x = models::upsert_workspace(&pool, w)
|
||||||
let x = models::upsert_workspace(&pool, w)
|
.await
|
||||||
.await
|
.expect("Failed to create workspace");
|
||||||
.expect("Failed to create workspace");
|
imported_resources.workspaces.push(x.clone());
|
||||||
imported_resources.workspaces.push(x.clone());
|
println!("Imported workspace: {}", x.name);
|
||||||
println!("Imported workspace: {}", x.name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for mut e in resources.environments {
|
for e in resources.environments {
|
||||||
if !workspace_id.is_empty() {
|
|
||||||
e.workspace_id = workspace_id.to_string();
|
|
||||||
}
|
|
||||||
println!("Importing environment: {:?}", e);
|
println!("Importing environment: {:?}", e);
|
||||||
let x = models::upsert_environment(&pool, e)
|
let x = models::upsert_environment(&pool, e)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create environment");
|
.expect("Failed to create environment");
|
||||||
imported_resources.environments.push(x.clone());
|
imported_resources.environments.push(x.clone());
|
||||||
println!("Imported environment: {}", x.name);
|
println!("Imported environment: {}", x.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for mut r in resources.requests {
|
for f in resources.folders {
|
||||||
if !workspace_id.is_empty() {
|
println!("Importing folder: {:?}", f);
|
||||||
r.workspace_id = workspace_id.to_string();
|
let x = models::upsert_folder(&pool, f)
|
||||||
}
|
.await
|
||||||
|
.expect("Failed to create folder");
|
||||||
|
imported_resources.folders.push(x.clone());
|
||||||
|
println!("Imported folder: {}", x.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
for r in resources.requests {
|
||||||
println!("Importing request: {:?}", r);
|
println!("Importing request: {:?}", r);
|
||||||
let x = models::upsert_request(&pool, r)
|
let x = models::upsert_request(&pool, r)
|
||||||
.await
|
.await
|
||||||
@@ -91,12 +94,12 @@ fn run_plugin(
|
|||||||
) -> serde_json::Value {
|
) -> serde_json::Value {
|
||||||
let plugin_dir = app_handle
|
let plugin_dir = app_handle
|
||||||
.path_resolver()
|
.path_resolver()
|
||||||
.resolve_resource("../plugins")
|
.resolve_resource("plugins")
|
||||||
.expect("failed to resolve plugin directory resource")
|
.expect("failed to resolve plugin directory resource")
|
||||||
.join(plugin_name);
|
.join(plugin_name);
|
||||||
let plugin_index_file = plugin_dir.join("index.js");
|
let plugin_index_file = plugin_dir.join("index.js");
|
||||||
|
|
||||||
println!("Plugin dir: {:?}", plugin_dir);
|
println!("Plugin dir={:?} file={:?}", plugin_dir, plugin_index_file);
|
||||||
|
|
||||||
// Module loader for the specific plugin
|
// Module loader for the specific plugin
|
||||||
let loader = &SimpleModuleLoader::new(plugin_dir).expect("failed to create module loader");
|
let loader = &SimpleModuleLoader::new(plugin_dir).expect("failed to create module loader");
|
||||||
@@ -119,23 +122,25 @@ fn run_plugin(
|
|||||||
// TODO: Is this needed if loaded from file already?
|
// TODO: Is this needed if loaded from file already?
|
||||||
loader.insert(plugin_index_file, module.clone());
|
loader.insert(plugin_index_file, module.clone());
|
||||||
|
|
||||||
let _promise_result = module
|
let promise_result = module
|
||||||
.load_link_evaluate(context)
|
.load_link_evaluate(context)
|
||||||
.expect("failed to evaluate module");
|
.expect("failed to evaluate module");
|
||||||
|
|
||||||
// Very important to push forward the job queue after queueing promises.
|
// Very important to push forward the job queue after queueing promises.
|
||||||
context.run_jobs();
|
context.run_jobs();
|
||||||
|
|
||||||
// // Checking if the final promise didn't return an error.
|
// Checking if the final promise didn't return an error.
|
||||||
// match promise_result.state() {
|
match promise_result.state().expect("failed to get promise state") {
|
||||||
// PromiseState::Pending => return Err("module didn't execute!".into()),
|
PromiseState::Pending => {
|
||||||
// PromiseState::Fulfilled(v) => {
|
panic!("Promise was pending");
|
||||||
// assert_eq!(v, JsValue::undefined())
|
}
|
||||||
// }
|
PromiseState::Fulfilled(v) => {
|
||||||
// PromiseState::Rejected(err) => {
|
assert_eq!(v, JsValue::undefined())
|
||||||
// return Err(JsError::from_opaque(err).try_native(context)?.into())
|
}
|
||||||
// }
|
PromiseState::Rejected(err) => {
|
||||||
// }
|
panic!("Failed to link: {}", err.display());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let namespace = module.namespace(context);
|
let namespace = module.namespace(context);
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,11 @@
|
|||||||
"tauri": {
|
"tauri": {
|
||||||
"windows": [],
|
"windows": [],
|
||||||
"cli": {
|
"cli": {
|
||||||
"description": "Yaak CLI",
|
"description": "Yaak CLI",
|
||||||
"longDescription": "This is the Yaak CLI, yo",
|
"longDescription": "This is the Yaak CLI, yo",
|
||||||
"beforeHelp": "u can use it to build, develop and manage your Yaak application.",
|
"beforeHelp": "u can use it to build, develop and manage your Yaak application.",
|
||||||
"afterHelp": "Have fun!",
|
"afterHelp": "Have fun!",
|
||||||
"args": [],
|
"args": [],
|
||||||
"subcommands": {
|
"subcommands": {
|
||||||
"import": {
|
"import": {
|
||||||
"args": [{
|
"args": [{
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
"longDescription": "The best cross-platform visual API client",
|
"longDescription": "The best cross-platform visual API client",
|
||||||
"resources": [
|
"resources": [
|
||||||
"migrations/*",
|
"migrations/*",
|
||||||
"../plugins/*"
|
"plugins/*"
|
||||||
],
|
],
|
||||||
"shortDescription": "The best API client",
|
"shortDescription": "The best API client",
|
||||||
"targets": [
|
"targets": [
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { memo, useCallback, useMemo } from 'react';
|
import { memo, useCallback, useMemo } from 'react';
|
||||||
|
import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
|
||||||
|
import { useAppRoutes } from '../hooks/useAppRoutes';
|
||||||
|
import { useEnvironments } from '../hooks/useEnvironments';
|
||||||
import { Button } from './core/Button';
|
import { Button } from './core/Button';
|
||||||
import type { DropdownItem } from './core/Dropdown';
|
import type { DropdownItem } from './core/Dropdown';
|
||||||
import { Dropdown } from './core/Dropdown';
|
import { Dropdown } from './core/Dropdown';
|
||||||
import { Icon } from './core/Icon';
|
import { Icon } from './core/Icon';
|
||||||
import { useEnvironments } from '../hooks/useEnvironments';
|
|
||||||
import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
|
|
||||||
import { useDialog } from './DialogContext';
|
import { useDialog } from './DialogContext';
|
||||||
import { EnvironmentEditDialog } from './EnvironmentEditDialog';
|
import { EnvironmentEditDialog } from './EnvironmentEditDialog';
|
||||||
import { useAppRoutes } from '../hooks/useAppRoutes';
|
|
||||||
import { useCreateEnvironment } from '../hooks/useCreateEnvironment';
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
className?: string;
|
className?: string;
|
||||||
@@ -20,7 +19,6 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
|
|||||||
}: Props) {
|
}: Props) {
|
||||||
const environments = useEnvironments();
|
const environments = useEnvironments();
|
||||||
const activeEnvironment = useActiveEnvironment();
|
const activeEnvironment = useActiveEnvironment();
|
||||||
const createEnvironment = useCreateEnvironment();
|
|
||||||
const dialog = useDialog();
|
const dialog = useDialog();
|
||||||
const routes = useAppRoutes();
|
const routes = useAppRoutes();
|
||||||
|
|
||||||
@@ -32,44 +30,33 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
|
|||||||
}, [dialog, activeEnvironment]);
|
}, [dialog, activeEnvironment]);
|
||||||
|
|
||||||
const items: DropdownItem[] = useMemo(
|
const items: DropdownItem[] = useMemo(
|
||||||
() =>
|
() => [
|
||||||
environments.length === 0
|
...environments.map(
|
||||||
? [
|
(e) => ({
|
||||||
{
|
key: e.id,
|
||||||
key: 'create',
|
label: e.name,
|
||||||
label: 'Create Environment',
|
rightSlot: e.id === activeEnvironment?.id ? <Icon icon="check" /> : undefined,
|
||||||
leftSlot: <Icon icon="plusCircle" />,
|
onSelect: async () => {
|
||||||
onSelect: async () => {
|
if (e.id !== activeEnvironment?.id) {
|
||||||
await createEnvironment.mutateAsync();
|
routes.setEnvironment(e);
|
||||||
showEnvironmentDialog();
|
} else {
|
||||||
},
|
routes.setEnvironment(null);
|
||||||
},
|
}
|
||||||
]
|
},
|
||||||
: [
|
}),
|
||||||
...environments.map(
|
[activeEnvironment?.id],
|
||||||
(e) => ({
|
),
|
||||||
key: e.id,
|
...((environments.length > 0
|
||||||
label: e.name,
|
? [{ type: 'separator', label: 'Environments' }]
|
||||||
rightSlot: e.id === activeEnvironment?.id ? <Icon icon="check" /> : undefined,
|
: []) as DropdownItem[]),
|
||||||
onSelect: async () => {
|
{
|
||||||
if (e.id !== activeEnvironment?.id) {
|
key: 'edit',
|
||||||
routes.setEnvironment(e);
|
label: 'Manage Environments',
|
||||||
} else {
|
leftSlot: <Icon icon="gear" />,
|
||||||
routes.setEnvironment(null);
|
onSelect: showEnvironmentDialog,
|
||||||
}
|
},
|
||||||
},
|
],
|
||||||
}),
|
[activeEnvironment, environments, routes, showEnvironmentDialog],
|
||||||
[activeEnvironment?.id],
|
|
||||||
),
|
|
||||||
{ type: 'separator', label: 'Environments' },
|
|
||||||
{
|
|
||||||
key: 'edit',
|
|
||||||
label: 'Manage Environments',
|
|
||||||
leftSlot: <Icon icon="gear" />,
|
|
||||||
onSelect: showEnvironmentDialog,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
[activeEnvironment, environments, routes, createEnvironment, showEnvironmentDialog],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import { invoke } from '@tauri-apps/api';
|
import { invoke } from '@tauri-apps/api';
|
||||||
import { useCallback, useRef } from 'react';
|
|
||||||
import { open } from '@tauri-apps/api/dialog';
|
import { open } from '@tauri-apps/api/dialog';
|
||||||
|
import { useCallback, useRef } from 'react';
|
||||||
|
import { useAppRoutes } from '../hooks/useAppRoutes';
|
||||||
import { useDeleteRequest } from '../hooks/useDeleteRequest';
|
import { useDeleteRequest } from '../hooks/useDeleteRequest';
|
||||||
import { useDuplicateRequest } from '../hooks/useDuplicateRequest';
|
import { useDuplicateRequest } from '../hooks/useDuplicateRequest';
|
||||||
|
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
|
||||||
import { useTheme } from '../hooks/useTheme';
|
import { useTheme } from '../hooks/useTheme';
|
||||||
|
import type { Environment, Folder, HttpRequest, Workspace } from '../lib/models';
|
||||||
|
import { pluralize } from '../lib/pluralize';
|
||||||
import type { DropdownItem, DropdownProps, DropdownRef } from './core/Dropdown';
|
import type { DropdownItem, DropdownProps, DropdownRef } from './core/Dropdown';
|
||||||
import { Dropdown } from './core/Dropdown';
|
import { Dropdown } from './core/Dropdown';
|
||||||
import { HotKey } from './core/HotKey';
|
import { HotKey } from './core/HotKey';
|
||||||
import { Icon } from './core/Icon';
|
import { Icon } from './core/Icon';
|
||||||
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
|
|
||||||
import { useAppRoutes } from '../hooks/useAppRoutes';
|
|
||||||
import type { Environment, HttpRequest, Workspace } from '../lib/models';
|
|
||||||
import { useDialog } from './DialogContext';
|
import { useDialog } from './DialogContext';
|
||||||
import { pluralize } from '../lib/pluralize';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
requestId: string | null;
|
requestId: string | null;
|
||||||
@@ -50,10 +50,10 @@ export function RequestActionsDropdown({ requestId, children }: Props) {
|
|||||||
const imported: {
|
const imported: {
|
||||||
workspaces: Workspace[];
|
workspaces: Workspace[];
|
||||||
environments: Environment[];
|
environments: Environment[];
|
||||||
|
folders: Folder[];
|
||||||
requests: HttpRequest[];
|
requests: HttpRequest[];
|
||||||
} = await invoke('import_data', {
|
} = await invoke('import_data', {
|
||||||
filePaths: selected,
|
filePaths: selected,
|
||||||
workspaceId: null,
|
|
||||||
});
|
});
|
||||||
const importedWorkspace = imported.workspaces[0];
|
const importedWorkspace = imported.workspaces[0];
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ export function RequestActionsDropdown({ requestId, children }: Props) {
|
|||||||
description: 'Imported the following:',
|
description: 'Imported the following:',
|
||||||
size: 'dynamic',
|
size: 'dynamic',
|
||||||
render: () => {
|
render: () => {
|
||||||
const { workspaces, environments, requests } = imported;
|
const { workspaces, environments, folders, requests } = imported;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ul className="list-disc pl-6">
|
<ul className="list-disc pl-6">
|
||||||
@@ -72,6 +72,9 @@ export function RequestActionsDropdown({ requestId, children }: Props) {
|
|||||||
<li>
|
<li>
|
||||||
{environments.length} {pluralize('Environment', environments.length)}
|
{environments.length} {pluralize('Environment', environments.length)}
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
{folders.length} {pluralize('Folder', folders.length)}
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
{requests.length} {pluralize('Request', requests.length)}
|
{requests.length} {pluralize('Request', requests.length)}
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -403,7 +403,6 @@ function SidebarItems({
|
|||||||
>
|
>
|
||||||
{tree.children.map((child, i) => (
|
{tree.children.map((child, i) => (
|
||||||
<Fragment key={child.item.id}>
|
<Fragment key={child.item.id}>
|
||||||
{hoveredIndex === i && hoveredTree?.item.id === tree.item.id && <DropMarker />}
|
|
||||||
{hoveredIndex === i && hoveredTree?.item.id === tree.item.id && <DropMarker />}
|
{hoveredIndex === i && hoveredTree?.item.id === tree.item.id && <DropMarker />}
|
||||||
<DraggableSidebarItem
|
<DraggableSidebarItem
|
||||||
selected={selectedId === child.item.id}
|
selected={selectedId === child.item.id}
|
||||||
|
|||||||
Reference in New Issue
Block a user