This commit is contained in:
Gregory Schier
2024-05-30 11:45:40 -07:00
parent 9e8afc3cc9
commit 606977d795
3 changed files with 145 additions and 132 deletions
+51 -36
View File
@@ -6,56 +6,56 @@ extern crate objc;
use std::collections::HashMap; use std::collections::HashMap;
use std::env::current_dir; use std::env::current_dir;
use std::fs; use std::fs;
use std::fs::{create_dir_all, File, read_to_string}; use std::fs::{create_dir_all, read_to_string, File};
use std::path::PathBuf; use std::path::PathBuf;
use std::process::exit; use std::process::exit;
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
use ::http::Uri;
use ::http::uri::InvalidUri; use ::http::uri::InvalidUri;
use ::http::Uri;
use base64::Engine; use base64::Engine;
use fern::colors::ColoredLevelConfig; use fern::colors::ColoredLevelConfig;
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
use rand::random; use rand::random;
use serde_json::{json, Value}; use serde_json::{json, Value};
use sqlx::{Pool, Sqlite, SqlitePool};
use sqlx::migrate::Migrator; use sqlx::migrate::Migrator;
use sqlx::sqlite::SqliteConnectOptions; use sqlx::sqlite::SqliteConnectOptions;
use sqlx::types::Json; use sqlx::types::Json;
use tauri::{AppHandle, LogicalSize, RunEvent, State, WebviewUrl, WebviewWindow}; use sqlx::{Pool, Sqlite, SqlitePool};
use tauri::{Manager, WindowEvent};
use tauri::path::BaseDirectory; use tauri::path::BaseDirectory;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use tauri::TitleBarStyle; use tauri::TitleBarStyle;
use tauri::{AppHandle, LogicalSize, RunEvent, State, WebviewUrl, WebviewWindow};
use tauri::{Manager, WindowEvent};
use tauri_plugin_log::{fern, Target, TargetKind}; use tauri_plugin_log::{fern, Target, TargetKind};
use tauri_plugin_shell::ShellExt; use tauri_plugin_shell::ShellExt;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use ::grpc::{Code, deserialize_message, serialize_message, ServiceDefinition};
use ::grpc::manager::{DynamicMessage, GrpcHandle}; use ::grpc::manager::{DynamicMessage, GrpcHandle};
use ::grpc::{deserialize_message, serialize_message, Code, ServiceDefinition};
use crate::analytics::{AnalyticsAction, AnalyticsResource}; use crate::analytics::{AnalyticsAction, AnalyticsResource};
use crate::grpc::metadata_to_map; use crate::grpc::metadata_to_map;
use crate::http_request::send_http_request; use crate::http_request::send_http_request;
use crate::models::{ use crate::models::{
cancel_pending_grpc_connections, cancel_pending_responses, CookieJar, cancel_pending_grpc_connections, cancel_pending_responses, create_http_response,
create_http_response, delete_all_grpc_connections, delete_all_http_responses, delete_cookie_jar, delete_all_grpc_connections, delete_all_http_responses, delete_cookie_jar, delete_environment,
delete_environment, delete_folder, delete_grpc_connection, delete_grpc_request, delete_folder, delete_grpc_connection, delete_grpc_request, delete_http_request,
delete_http_request, delete_http_response, delete_workspace, duplicate_grpc_request, delete_http_response, delete_workspace, duplicate_grpc_request, duplicate_http_request,
duplicate_http_request, Environment, EnvironmentVariable, Folder, generate_model_id, generate_model_id, get_cookie_jar, get_environment, get_folder, get_grpc_connection,
get_cookie_jar, get_environment, get_folder, get_grpc_connection,
get_grpc_request, get_http_request, get_http_response, get_key_value_raw, get_grpc_request, get_http_request, get_http_response, get_key_value_raw,
get_or_create_settings, get_workspace, get_workspace_export_resources, GrpcConnection, GrpcEvent, get_or_create_settings, get_workspace, get_workspace_export_resources, list_cookie_jars,
GrpcEventType, GrpcRequest, HttpRequest, HttpResponse, list_environments, list_folders, list_grpc_connections, list_grpc_events, list_grpc_requests,
KeyValue, list_cookie_jars, list_environments, list_folders, list_grpc_connections, list_http_requests, list_responses, list_workspaces, set_key_value_raw, update_response_if_id,
list_grpc_events, list_grpc_requests, list_http_requests, list_responses, list_workspaces, update_settings, upsert_cookie_jar, upsert_environment, upsert_folder, upsert_grpc_connection,
ModelType, set_key_value_raw, Settings, update_response_if_id, update_settings, upsert_cookie_jar, upsert_grpc_event, upsert_grpc_request, upsert_http_request, upsert_workspace, CookieJar,
upsert_environment, upsert_folder, upsert_grpc_connection, upsert_grpc_event, upsert_grpc_request, upsert_http_request, upsert_workspace, Environment, EnvironmentVariable, Folder, GrpcConnection, GrpcEvent, GrpcEventType,
Workspace, WorkspaceExportResources, GrpcRequest, HttpRequest, HttpResponse, KeyValue, ModelType, Settings, Workspace,
WorkspaceExportResources,
}; };
use crate::notifications::YaakNotifier; use crate::notifications::YaakNotifier;
use crate::plugin::{ImportResult, run_plugin_export_curl, run_plugin_import}; use crate::plugin::{run_plugin_export_curl, run_plugin_import, ImportResult};
use crate::render::render_request; use crate::render::render_request;
use crate::updates::{UpdateMode, YaakUpdater}; use crate::updates::{UpdateMode, YaakUpdater};
use crate::window_menu::app_menu; use crate::window_menu::app_menu;
@@ -67,15 +67,15 @@ mod models;
mod notifications; mod notifications;
mod plugin; mod plugin;
mod render; mod render;
mod updates;
mod window_menu;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
mod tauri_plugin_mac_window; mod tauri_plugin_mac_window;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
mod tauri_plugin_windows_window; mod tauri_plugin_windows_window;
mod updates;
mod window_menu;
const DEFAULT_WINDOW_WIDTH: i32 = 1100; const DEFAULT_WINDOW_WIDTH: f64 = 1100.0;
const DEFAULT_WINDOW_HEIGHT: i32 = 600; const DEFAULT_WINDOW_HEIGHT: f64 = 600.0;
async fn migrate_db(app_handle: &AppHandle, db: &Mutex<Pool<Sqlite>>) -> Result<(), String> { async fn migrate_db(app_handle: &AppHandle, db: &Mutex<Pool<Sqlite>>) -> Result<(), String> {
let pool = &*db.lock().await; let pool = &*db.lock().await;
@@ -1511,7 +1511,12 @@ async fn cmd_new_window(app_handle: AppHandle, url: &str) -> Result<(), String>
} }
#[tauri::command] #[tauri::command]
async fn cmd_new_nested_window(window: WebviewWindow, url: &str, label: &str, title: &str) -> Result<(), String> { async fn cmd_new_nested_window(
window: WebviewWindow,
url: &str,
label: &str,
title: &str,
) -> Result<(), String> {
create_nested_window(&window, label, url, title); create_nested_window(&window, label, url, title);
Ok(()) Ok(())
} }
@@ -1548,15 +1553,18 @@ pub fn run() {
.plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_fs::init()); .plugin(tauri_plugin_fs::init());
#[cfg(target_os = "windows")] { #[cfg(target_os = "windows")]
{
builder = builder.plugin(tauri_plugin_windows_window::init()); builder = builder.plugin(tauri_plugin_windows_window::init());
} }
#[cfg(target_os = "macos")] { #[cfg(target_os = "macos")]
{
builder = builder.plugin(tauri_plugin_mac_window::init()); builder = builder.plugin(tauri_plugin_mac_window::init());
} }
builder.plugin( builder
.plugin(
tauri_plugin_log::Builder::default() tauri_plugin_log::Builder::default()
.targets([ .targets([
Target::new(TargetKind::Stdout), Target::new(TargetKind::Stdout),
@@ -1756,7 +1764,12 @@ fn is_dev() -> bool {
} }
} }
fn create_nested_window(window: &WebviewWindow, label: &str, url: &str, title: &str) -> WebviewWindow { fn create_nested_window(
window: &WebviewWindow,
label: &str,
url: &str,
title: &str,
) -> WebviewWindow {
info!("Create new nested window label={label}"); info!("Create new nested window label={label}");
let mut win_builder = tauri::WebviewWindowBuilder::new( let mut win_builder = tauri::WebviewWindowBuilder::new(
window, window,
@@ -1769,7 +1782,7 @@ fn create_nested_window(window: &WebviewWindow, label: &str, url: &str, title: &
.title(title) .title(title)
.parent(&window) .parent(&window)
.unwrap() .unwrap()
.inner_size(700.0f64, 600.0f64); .inner_size(DEFAULT_WINDOW_WIDTH * 0.5, DEFAULT_WINDOW_HEIGHT * 0.75);
// Add macOS-only things // Add macOS-only things
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
@@ -1800,11 +1813,8 @@ fn create_window(handle: &AppHandle, url: &str) -> WebviewWindow {
let window_num = handle.webview_windows().len(); let window_num = handle.webview_windows().len();
let label = format!("main_{}", window_num); let label = format!("main_{}", window_num);
info!("Create new window label={label}"); info!("Create new window label={label}");
let mut win_builder = tauri::WebviewWindowBuilder::new( let mut win_builder =
handle, tauri::WebviewWindowBuilder::new(handle, label, WebviewUrl::App(url.into()))
label,
WebviewUrl::App(url.into()),
)
.resizable(true) .resizable(true)
.fullscreen(false) .fullscreen(false)
.disable_drag_drop_handler() // Required for frontend Dnd on windows .disable_drag_drop_handler() // Required for frontend Dnd on windows
@@ -1855,7 +1865,12 @@ fn create_window(handle: &AppHandle, url: &str) -> WebviewWindow {
} }
// Commands for development // Commands for development
"dev.reset_size" => webview_window.set_size(LogicalSize::new(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT)).unwrap(), "dev.reset_size" => webview_window
.set_size(LogicalSize::new(
DEFAULT_WINDOW_WIDTH,
DEFAULT_WINDOW_HEIGHT,
))
.unwrap(),
"dev.refresh" => webview_window.eval("location.reload()").unwrap(), "dev.refresh" => webview_window.eval("location.reload()").unwrap(),
"dev.toggle_devtools" => { "dev.toggle_devtools" => {
if webview_window.is_devtools_open() { if webview_window.is_devtools_open() {
+2 -4
View File
@@ -132,10 +132,8 @@ export function GlobalHooks() {
const { interfaceScale, interfaceFontSize, editorFontSize } = settings; const { interfaceScale, interfaceFontSize, editorFontSize } = settings;
getCurrent().setZoom(interfaceScale).catch(console.error); getCurrent().setZoom(interfaceScale).catch(console.error);
document.documentElement.style.cssText = [ document.documentElement.style.setProperty('font-size', `${interfaceFontSize}px`);
`font-size: ${interfaceFontSize}px`, document.documentElement.style.setProperty('--editor-font-size', `${editorFontSize}px`);
`--editor-font-size: ${editorFontSize}px`,
].join('; ');
}, [settings]); }, [settings]);
// Handle Zoom. Note, Mac handles it in app menu, so need to also handle keyboard // Handle Zoom. Note, Mac handles it in app menu, so need to also handle keyboard