jsrl icon indicating copy to clipboard operation
jsrl copied to clipboard

Using Tauri vs Electron

Open erikyuzwa opened this issue 1 year ago • 1 comments

  • THIS IS A NON-DESTRUCTIVE PR (aka. no existing functionality is removed)
  • Just an experimental PR to make use of Tauri instead of Electron for the desktop app publishing
  • JSRL is not using any real "Electron specific" functionality, other then just acting as the wrapper
  • This would help clean up a LOT of the electron-specific boilerplate
  • https://tauri.app/

To Install

  • Make sure cargo and rustup work on your system
  • configuration is in src-tauri/tauri.conf.json
  • npm run tauri dev will launch the dev build of the Tauri container, along with opening the dev tools
  • hot reloading works as you'd expect, so for example changes to src/Game.ts will trigger a reload of Tauri
  • npm run tauri build will build the app and run the Tauri packaging process
  • For Windows, .msi installers are generated in the src-tauri/target/release/bundle/msi
  • By default, it will try to install the app to c:\Program Files\jsrl but you can modify that
  • resulting app binary is ridiculously small: <5 MB on my system!

Screenshot 2023-08-19 131915

Screenshot 2023-08-19 132549

erikyuzwa avatar Aug 19 '23 19:08 erikyuzwa

I was able to get a "Quit" working from my own Javascript frontend with passing an event back to Tauri. I did it in a way to detect if you're running on the web vs. inside Tauri

in the main.rs:

use tauri::Manager;

fn main() {
  tauri::Builder::default()
    .setup(|app| {
      let _window = app.get_window("main").unwrap();
      #[cfg(debug_assertions)] // only include this code on debug builds
      {
        _window.open_devtools();
        _window.close_devtools();
      }
      Ok(())
    })
    .invoke_handler(tauri::generate_handler![exit_app]) //register the exit_app handler
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

#[tauri::command]
fn exit_app() {
  std::process::exit(0x0);
}

then from the JS side:

import {invoke} from '@tauri-apps/api/tauri'

// using ROT.js - if Tauri is on the window, provide a QUIT option
if (window.__TAURI__) {
  display.drawText(hw - 8, hh + 4, '%c{yellow}[Q]uit');
 }

// snip
if (inputData.keyCode === ROT.KEYS.VK_Q) {
   invoke('exit_app')
}

erikyuzwa avatar Aug 24 '23 15:08 erikyuzwa

I've got another idea for this and want to kill this PR @slashman - Been using electron-forge quite a bit, and I think it would help the development cycle of using JSRL "feel" better (IMHO)

erikyuzwa avatar Mar 30 '24 14:03 erikyuzwa