Update to tauri 2 (#665)

This commit is contained in:
Uriel
2023-08-06 01:14:24 -03:00
committed by GitHub
parent 8a6778155d
commit dad0188854
20 changed files with 1592 additions and 8669 deletions

View File

@@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-latest, macos-latest]
os: [ubuntu-22.04, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
@@ -54,11 +54,11 @@ jobs:
with:
submodules: recursive
- if: matrix.os == 'ubuntu-20.04'
- if: matrix.os == 'ubuntu-22.04'
name: Set up Linux dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf
packages: libgtk-3-dev webkit2gtk-4.1 libappindicator3-dev librsvg2-dev patchelf
# Increment to invalidate the cache
version: 1.0
# Enables a workaround to attempt to run pre and post install scripts
@@ -91,7 +91,7 @@ jobs:
# A file, directory or wildcard pattern that describes what to upload
path: target/release/slimevr.exe
- if: matrix.os == 'ubuntu-20.04'
- if: matrix.os == 'ubuntu-22.04'
name: Upload a Build Artifact (Linux)
uses: actions/upload-artifact@v3
with:

View File

@@ -85,7 +85,7 @@ jobs:
bundle-linux:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [build, test]
if: contains(fromJSON('["workflow_dispatch", "create"]'), github.event_name)
steps:
@@ -101,7 +101,7 @@ jobs:
- name: Set up Linux dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf libfuse2
packages: libgtk-3-dev webkit2gtk-4.1 libappindicator3-dev librsvg2-dev patchelf libfuse2
# Increment to invalidate the cache
version: 1.0
# Enables a workaround to attempt to run pre and post install scripts
@@ -112,7 +112,7 @@ jobs:
- name: Cache cargo dependencies
uses: Swatinem/rust-cache@v2
with:
shared-key: "ubuntu-20.04"
shared-key: "ubuntu-22.04"
- name: Use Node.js
uses: actions/setup-node@v3

1175
Cargo.lock generated

File diff suppressed because it is too large Load Diff

18
flake.lock generated
View File

@@ -5,11 +5,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1685518550,
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
"lastModified": 1689068808,
"narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
"type": "github"
},
"original": {
@@ -38,11 +38,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1686412476,
"narHash": "sha256-inl9SVk6o5h75XKC79qrDCAobTD1Jxh6kVYTZKHzewA=",
"lastModified": 1689679375,
"narHash": "sha256-LHUC52WvyVDi9PwyL1QCpaxYWBqp4ir4iL6zgOkmcb8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "21951114383770f96ae528d0ae68824557768e81",
"rev": "684c17c429c42515bafb3ad775d2a710947f3d67",
"type": "github"
},
"original": {
@@ -80,11 +80,11 @@
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1686364106,
"narHash": "sha256-h4gCQg+jizmAbdg6UPlhxQVk4A7Ar/zoLa0wx3wBya0=",
"lastModified": 1689735719,
"narHash": "sha256-HOEDWJLm+f6HSD4j7n4xc8J4FcqjJ+U7ZnMLQQrZKYg=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "ba011dd1c5028dbb880bc3b0f427e0ff689e6203",
"rev": "31d08cf9f5c3a49475e723c75c6f645171364a74",
"type": "github"
},
"original": {

View File

@@ -43,14 +43,13 @@
gobject-introspection
gtk3
harfbuzz
libayatana-appindicator-gtk3
libffi
libsoup
libsoup_3
openssl.out
pango
pkg-config
treefmt
webkitgtk
webkitgtk_4_1
zlib
gst_all_1.gstreamer
gst_all_1.gst-plugins-base

View File

@@ -8,7 +8,13 @@
"@fontsource/poppins": "^4.5.8",
"@formatjs/intl-localematcher": "^0.2.32",
"@react-three/fiber": "^8.10.0",
"@tauri-apps/api": "^1.4.0",
"@tauri-apps/api": "^2.0.0-alpha.5",
"@tauri-apps/plugin-app": "github:tauri-apps/tauri-plugin-app#v2",
"@tauri-apps/plugin-dialog": "github:tauri-apps/tauri-plugin-dialog#v2",
"@tauri-apps/plugin-fs": "github:tauri-apps/tauri-plugin-fs#v2",
"@tauri-apps/plugin-os": "github:tauri-apps/tauri-plugin-os#v2",
"@tauri-apps/plugin-shell": "github:tauri-apps/tauri-plugin-shell#v2",
"@tauri-apps/plugin-window": "github:tauri-apps/tauri-plugin-window#v2",
"@vitejs/plugin-react": "^3.0.0",
"browserslist": "^4.18.1",
"classnames": "^2.3.1",
@@ -66,7 +72,7 @@
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.3",
"@tauri-apps/cli": "^1.4.0",
"@tauri-apps/cli": "^2.0.0-alpha.10",
"@types/file-saver": "^2.0.5",
"@types/react": "18.0.25",
"@types/react-dom": "^18.0.5",

View File

@@ -21,15 +21,20 @@ default = ["custom-protocol"]
custom-protocol = ["tauri/custom-protocol"]
[build-dependencies]
tauri-build = { version = "1.2", features = [] }
tauri-build = { version = "2.0.0-alpha.6", features = [] }
cfg_aliases = "0.1"
shadow-rs = "0.23"
[dependencies]
serde_json = "1"
serde = { version = "1", features = ["derive"] }
tauri = { version = "1.4", features = ["devtools", "dialog", "dialog-save", "fs-all", "os-all", "path-all", "shell-execute", "shell-open", "window-close", "window-maximize", "window-minimize", "window-set-resizable", "window-set-size", "window-set-title", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
tauri-runtime = "0.14"
tauri = { version = "2.0.0-alpha.10", features = [] }
tauri-runtime = "0.13.0-alpha.6"
tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-fs = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-os = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-shell = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-window = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
flexi_logger = "0.25"
log-panics = { version = "2", features = ["with-backtrace"] }
log = "0.4"
@@ -44,6 +49,8 @@ shadow-rs = { version = "0.23", default-features = false }
const_format = "0.2.30"
cfg-if = "1"
color-eyre = "0.6"
rfd = "0.11.4"
dirs-next = "2.0.0"
[target.'cfg(windows)'.dependencies]
win32job = "1"

View File

@@ -11,10 +11,10 @@ use std::time::Instant;
use clap::Parser;
use color_eyre::Result;
use state::WindowState;
use tauri::api::process::{Command, CommandChild};
use tauri::Manager;
use tauri::RunEvent;
use tauri::WindowEvent;
use tauri_plugin_shell::process::CommandChild;
use crate::util::{
get_launch_path, show_error, valid_java_paths, Cli, JAVA_BIN, MINIMUM_JAVA_VERSION,
@@ -71,12 +71,27 @@ fn main() -> Result<()> {
use flexi_logger::{
Age, Cleanup, Criterion, Duplicate, FileSpec, Logger, Naming, WriteMode,
};
use tauri::api::path::app_log_dir;
use tauri::path::Error;
// Based on https://docs.rs/tauri/2.0.0-alpha.10/src/tauri/path/desktop.rs.html#238-256
#[cfg(target_os = "macos")]
let path = dirs_next::home_dir().ok_or(Error::UnknownPath).map(|dir| {
dir.join("Library/Logs")
.join(&tauri_context.config().tauri.bundle.identifier)
});
#[cfg(not(target_os = "macos"))]
let path = dirs_next::data_local_dir()
.ok_or(Error::UnknownPath)
.map(|dir| {
dir.join(&tauri_context.config().tauri.bundle.identifier)
.join("logs")
});
Logger::try_with_env_or_str("info")?
.log_to_file(FileSpec::default().directory(
app_log_dir(tauri_context.config()).expect("We need a log dir"),
))
.log_to_file(
FileSpec::default().directory(path.expect("We need a log dir")),
)
.format_for_files(util::logger_format)
.format_for_stderr(util::logger_format)
.rotate(
@@ -109,13 +124,13 @@ fn main() -> Result<()> {
if !webview2_exists() {
// This makes a dialog appear which let's you press Ok or Cancel
// If you press Ok it will open the SlimeVR installer documentation
use tauri::api::dialog::{
blocking::MessageDialogBuilder, MessageDialogButtons, MessageDialogKind,
};
use rfd::{MessageButtons, MessageDialog, MessageLevel};
let confirm = MessageDialogBuilder::new("SlimeVR", "Couldn't find WebView2 installed. You can install it with the SlimeVR installer")
.buttons(MessageDialogButtons::OkCancel)
.kind(MessageDialogKind::Error)
let confirm = MessageDialog::new()
.set_title("SlimeVR")
.set_description("Couldn't find WebView2 installed. You can install it with the SlimeVR installer")
.set_buttons(MessageButtons::OkCancel)
.set_level(MessageLevel::Error)
.show();
if confirm {
open::that("https://docs.slimevr.dev/server-setup/installing-and-connecting.html#install-the-latest-slimevr-installer").unwrap();
@@ -126,10 +141,11 @@ fn main() -> Result<()> {
// Spawn server process
let exit_flag = Arc::new(AtomicBool::new(false));
let mut backend: Option<CommandChild> = None;
let backend = Arc::new(Mutex::new(Option::<CommandChild>::None));
let backend_termination = backend.clone();
let run_path = get_launch_path(cli);
let stdout_recv = if let Some(p) = run_path {
let server_info = if let Some(p) = run_path {
log::info!("Server found on path: {}", p.to_str().unwrap());
// Check if any Java already installed is compatible
@@ -144,13 +160,7 @@ fn main() -> Result<()> {
};
log::info!("Using Java binary: {:?}", java_bin);
let (recv, child) = Command::new(java_bin.to_str().unwrap())
.current_dir(p)
.args(["-Xmx512M", "-jar", "slimevr.jar", "run"])
.spawn()
.expect("Unable to start the server jar");
backend = Some(child);
Some(recv)
Some((java_bin, p))
} else {
log::warn!("No server found. We will not start the server.");
None
@@ -158,6 +168,11 @@ fn main() -> Result<()> {
let exit_flag_terminated = exit_flag.clone();
let build_result = tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_window::init())
.invoke_handler(tauri::generate_handler![
update_window_state,
logging,
@@ -166,7 +181,7 @@ fn main() -> Result<()> {
])
.setup(move |app| {
let window_state =
WindowState::open_state(app.path_resolver().app_config_dir().unwrap())
WindowState::open_state(app.path().app_config_dir().unwrap())
.unwrap_or_default();
let window = tauri::WindowBuilder::new(
@@ -189,15 +204,32 @@ fn main() -> Result<()> {
app.manage(Mutex::new(window_state));
if let Some(mut recv) = stdout_recv {
if let Some((java_bin, p)) = server_info {
let app_handle = app.app_handle();
tauri::async_runtime::spawn(async move {
use tauri::api::process::CommandEvent;
use tauri_plugin_shell::{process::CommandEvent, ShellExt};
while let Some(cmd_event) = recv.recv().await {
let (mut rx, child) = app_handle
.shell()
.command(java_bin.to_str().unwrap())
.current_dir(p)
.args(["-Xmx512M", "-jar", "slimevr.jar", "run"])
.spawn()
.expect("Unable to start the server jar");
{
let mut lock = backend.lock().unwrap();
*lock = Some(child)
}
while let Some(cmd_event) = rx.recv().await {
let emit_me = match cmd_event {
CommandEvent::Stderr(s) => ("stderr", s),
CommandEvent::Stdout(s) => ("stdout", s),
CommandEvent::Stderr(v) => {
("stderr", String::from_utf8(v).unwrap_or_default())
}
CommandEvent::Stdout(v) => {
("stdout", String::from_utf8(v).unwrap_or_default())
}
CommandEvent::Error(s) => ("error", s),
CommandEvent::Terminated(s) => {
exit_flag_terminated.store(true, Ordering::Relaxed);
@@ -236,19 +268,19 @@ fn main() -> Result<()> {
RunEvent::ExitRequested { .. } => {
let window_state = app_handle.state::<Mutex<WindowState>>();
let lock = window_state.lock().unwrap();
let config_dir =
app_handle.path_resolver().app_config_dir().unwrap();
let config_dir = app_handle.path().app_config_dir().unwrap();
let window_state_res = lock.save_state(config_dir);
match window_state_res {
Ok(()) => log::info!("saved window state"),
Err(e) => log::error!("failed to save window state: {}", e),
}
let Some(ref mut child) = backend else { return };
let mut lock = backend_termination.lock().unwrap();
let Some(ref mut child) = *lock else { return };
let write_result = child.write(b"exit\n");
match write_result {
Ok(()) => log::info!("send exit to backend"),
Err(_) => log::info!("fail to send exit to backend"),
Err(_) => log::error!("fail to send exit to backend"),
}
let ten_seconds = Duration::from_secs(10);
let start_time = Instant::now();
@@ -268,13 +300,13 @@ fn main() -> Result<()> {
// I should log this anyways, don't want to dig a grave by not logging the error.
log::error!("CreateWebview error {}", error);
use tauri::api::dialog::{
blocking::MessageDialogBuilder, MessageDialogButtons, MessageDialogKind,
};
use rfd::{MessageButtons, MessageDialog, MessageLevel};
let confirm = MessageDialogBuilder::new("SlimeVR", "You seem to have a faulty installation of WebView2. You can check a guide on how to fix that in the docs!")
.buttons(MessageDialogButtons::OkCancel)
.kind(MessageDialogKind::Error)
let confirm = MessageDialog::new()
.set_title("SlimeVR")
.set_description("You seem to have a faulty installation of WebView2. You can check a guide on how to fix that in the docs!")
.set_buttons(MessageButtons::OkCancel)
.set_level(MessageLevel::Error)
.show();
if confirm {
open::that("https://docs.slimevr.dev/common-issues.html#webview2-is-missing--slimevr-gui-crashes-immediately--panicked-at--webview2error").unwrap();

View File

@@ -10,7 +10,7 @@ use std::{
use clap::Parser;
use const_format::concatcp;
use flexi_logger::{DeferredNow, style};
use flexi_logger::{style, DeferredNow};
use log::Record;
use shadow_rs::shadow;
use tempfile::Builder;
@@ -95,20 +95,17 @@ pub fn spawn_java(java: &OsStr, java_version: &OsStr) -> std::io::Result<Child>
#[cfg(desktop)]
pub fn show_error(text: &str) -> bool {
use rand::{seq::SliceRandom, thread_rng};
use tauri::api::dialog::{
blocking::MessageDialogBuilder, MessageDialogButtons, MessageDialogKind,
};
use rfd::{MessageButtons, MessageDialog, MessageLevel};
MessageDialogBuilder::new(
format!(
MessageDialog::new()
.set_title(&format!(
"SlimeVR GUI crashed - {}",
POSSIBLE_TITLES.choose(&mut thread_rng()).unwrap()
),
text,
)
.buttons(MessageDialogButtons::Ok)
.kind(MessageDialogKind::Error)
.show()
))
.set_description(text)
.set_buttons(MessageButtons::Ok)
.set_level(MessageLevel::Error)
.show()
}
#[cfg(mobile)]
@@ -220,11 +217,11 @@ pub fn valid_java_paths() -> Vec<(OsString, i32)> {
}
pub fn logger_format(
w: &mut dyn std::io::Write,
_now: &mut DeferredNow,
record: &Record,
w: &mut dyn std::io::Write,
_now: &mut DeferredNow,
record: &Record,
) -> Result<(), std::io::Error> {
let level = record.level();
let level = record.level();
let module_path = record.module_path().unwrap_or("<unnamed>");
// optionally print target
let target = if module_path.starts_with(record.target()) {
@@ -232,11 +229,11 @@ pub fn logger_format(
} else {
format!(", {}", record.target())
};
write!(
w,
"{} [{}{target}] {}",
style(level).paint(level.to_string()),
record.module_path().unwrap_or("<unnamed>"),
style(level).paint(record.args().to_string())
)
write!(
w,
"{} [{}{target}] {}",
style(level).paint(level.to_string()),
record.module_path().unwrap_or("<unnamed>"),
style(level).paint(record.args().to_string())
)
}

View File

@@ -50,41 +50,6 @@
"timestampUrl": ""
}
},
"updater": {
"active": false
},
"allowlist": {
"dialog": {
"all": false,
"save": true
},
"shell": {
"all": false,
"execute": true,
"open": true
},
"fs": {
"scope": ["$APP/*", "$APP"],
"all": true
},
"path": {
"all": true
},
"os": {
"all": true
},
"window": {
"setResizable": true,
"setTitle": true,
"maximize": true,
"unmaximize": true,
"minimize": true,
"unminimize": true,
"close": true,
"startDragging": true,
"setSize": true
}
},
"security": {
"csp": null
}

View File

@@ -38,7 +38,7 @@ import { TrackerSettingsPage } from './components/tracker/TrackerSettings';
import { useConfig } from './hooks/config';
import { OSCRouterSettings } from './components/settings/pages/OSCRouterSettings';
import { useLocalization } from '@fluent/react';
import { os } from '@tauri-apps/api';
import * as os from '@tauri-apps/plugin-os';
import { VMCSettings } from './components/settings/pages/VMCSettings';
import { MountingChoose } from './components/onboarding/pages/mounting/MountingChoose';
import { ProportionsChoose } from './components/onboarding/pages/body-proportions/ProportionsChoose';
@@ -46,7 +46,7 @@ import { StatusProvider } from './components/providers/StatusSystemContext';
import { VersionUpdateModal } from './components/VersionUpdateModal';
import { CalibrationTutorialPage } from './components/onboarding/pages/CalibrationTutorial';
import { AssignmentTutorialPage } from './components/onboarding/pages/assignment-preparation/AssignmentTutorial';
import { open } from '@tauri-apps/api/shell';
import { open } from '@tauri-apps/plugin-shell';
import semver from 'semver';
import { useBreakpoint } from './hooks/breakpoint';
import { VRModePage } from './components/vr-mode/VRModePage';

View File

@@ -1,4 +1,4 @@
import { appWindow } from '@tauri-apps/api/window';
import { appWindow } from '@tauri-apps/plugin-window';
import { ReactNode, useContext, useEffect, useState } from 'react';
import { NavLink, useMatch } from 'react-router-dom';
import {
@@ -14,7 +14,7 @@ import { SlimeVRIcon } from './commons/icon/SimevrIcon';
import { ProgressBar } from './commons/ProgressBar';
import { Typography } from './commons/Typography';
import { DownloadIcon } from './commons/icon/DownloadIcon';
import { open } from '@tauri-apps/api/shell';
import { open } from '@tauri-apps/plugin-shell';
import { GH_REPO, VersionContext, DOCS_SITE } from '../App';
import classNames from 'classnames';
import { QuestionIcon } from './commons/icon/QuestionIcon';

View File

@@ -3,7 +3,7 @@ import { useContext, useState } from 'react';
import { BaseModal } from './commons/BaseModal';
import { Button } from './commons/Button';
import { Typography } from './commons/Typography';
import { open } from '@tauri-apps/api/shell';
import { open } from '@tauri-apps/plugin-shell';
import semver from 'semver';
import { GH_REPO, VersionContext } from '../App';
import { error } from '../utils/logging';

View File

@@ -1,4 +1,4 @@
import { open } from '@tauri-apps/api/shell';
import { open } from '@tauri-apps/plugin-shell';
import { ReactNode } from 'react';
export function A({ href, children }: { href: string; children?: ReactNode }) {

View File

@@ -11,8 +11,8 @@ import {
} from 'solarxr-protocol';
import { useWebsocketAPI } from '../../../../hooks/websocket-api';
import saveAs from 'file-saver';
import { save } from '@tauri-apps/api/dialog';
import { writeTextFile } from '@tauri-apps/api/fs';
import { save } from '@tauri-apps/plugin-dialog';
import { writeTextFile } from '@tauri-apps/plugin-fs';
import { useIsTauri } from '../../../../hooks/breakpoint';
import { useAppContext } from '../../../../hooks/app';
import { error } from '../../../../utils/logging';

View File

@@ -1,4 +1,4 @@
import { BaseDirectory, readTextFile } from '@tauri-apps/api/fs';
import { BaseDirectory, readTextFile } from '@tauri-apps/plugin-fs';
import { createContext, useContext, useRef, useState } from 'react';
import { DeveloperModeWidgetForm } from '../components/widgets/DeveloperModeWidget';
@@ -96,7 +96,7 @@ export function useConfigProvider(): ConfigContext {
const migrated = localStorage.getItem('configMigrated');
if (!migrated) {
const oldConfig = await readTextFile('config.json', {
dir: BaseDirectory.App,
dir: BaseDirectory.AppConfig,
}).catch(() => null);
if (oldConfig) localStorage.setItem('config.json', oldConfig);

View File

@@ -9,7 +9,7 @@ import {
createContext,
useContext,
} from 'react';
import { exists, readTextFile, BaseDirectory } from '@tauri-apps/api/fs';
import { exists, readTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
import { error } from '../utils/logging';
export const defaultNS = 'translation';
@@ -114,9 +114,7 @@ export const langs = [
// AppConfig path: https://docs.rs/tauri/1.2.4/tauri/api/path/fn.config_dir.html
// We doing this only once, don't want an override check to be done on runtime,
// only on launch :P
const overrideLangExists = exists(OVERRIDE_FILENAME, {
dir: BaseDirectory.AppConfig,
}).catch(() => false);
const overrideLangExists = exists(OVERRIDE_FILENAME).catch(() => false);
// Fetch translation file
async function fetchMessages(locale: string): Promise<[string, string]> {

View File

@@ -11,9 +11,7 @@ body {
user-select: none;
background: theme('colors.background.20');
/**
* Scrollbars for Firefox
*/
/*Scrollbar for firefox */
scrollbar-color: theme('colors.background.50') theme('colors.background.60');
scrollbar-width: thin;
}

8810
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
[toolchain]
channel = "1.65"
channel = "1.71"
profile = "default"
components = ["rust-analyzer", "rust-src"]