Skip to content

Latest commit

 

History

History
181 lines (125 loc) · 7.01 KB

DEV.md

File metadata and controls

181 lines (125 loc) · 7.01 KB

V1.9: Developer Guide

PREREQUISITES

Make sure the following programs are installed:

  1. Node JS (with NPM)
  2. Rust (Optional - only required if editing steamworks-rs/steamworks.js dependencies)
  3. git (Optional)

BASIC INSTALLATION

ℹ Rust is not required for basic installation

  1. Clone the repository:
git clone https://github.com/SteamAchievementNotifier/SteamAchievementNotifier.git -b master

ℹ If you do not have git installed, select Code > Download ZIP and extract it.

  1. In the project root, run the following command to build all dependencies:
npm i
  1. Once complete, run the following command to start Steam Achievement Notifier in devmode:
npm run dev
  1. On Windows, run the following command to build the executable:
npm run win

🐧 Linux coming soon!

The output directory for executables is _release.

PROJECT STRUCTURE

The project follows a standard TS structure:

  • Source .ts files are located under ./src
  • Compiled .js files are located under ./dist

Within src/dist, there are several subfolders to separate core app functionality from additional features:

  • app: Contains .ts/.js files and associated HTML/CSS for core BrowserWindow instances used for in-app pages, menus and dialogs. Also contains:

    • app.ts: The entry point to the Electron app
    • main.ts: The "Main process"
    • listeners.ts: An extension of main.ts that focuses on managing various event listeners
    • worker.ts: A background BrowserWindow instance that initialises Steamworks when a game process is detected. Dynamically spawned/destroyed in order to initialise/release Steamworks between game instances
  • lang: Contains modules for each supported app language.

ℹ These files only provide translation strings via the exported object - ./src/app/language.ts contains the logic to apply these translations to elements within the app

  • notify: Contains .ts/.js to control BrowserWindow instances that are used by notification windows

STEAMWORKS OVERVIEW

In Steam Achievement Notifier (V1.9), there are two projects that provide Steamworks integration via Rust - steamworks-rs and steamworks.js.

steamworks-rs converts the original Steamworks functions into Rust.

steamworks.js takes the functions provided by steamworks-rs, and converts them from Rust to Javascript using a .node addon. This then allows the original Steamworks functions to be made available for use in Electron apps.

Both of these projects have been customised specifically for use within Steam Achievement Notifier, both by extending functionality in terms of achievement info, and removing certain functions beyond the scope of this application (e.g. unlocking/relocking achievements, UGC/Workshop content, networking etc.)

⚠ Under normal circumstances, if you only want to edit Steam Achievement Notifier itself, you will not need to install the Steamworks dependencies outlined below - the Basic Installation section will be enough!

ADVANCED INSTALLATION: STEAMWORKS

Clone both the steamworks-rs and steamworks.js repositories into ./deps:

cd deps
git clone https://github.com/SteamAchievementNotifier/san_steamworks-rs.git
git clone https://github.com/SteamAchievementNotifier/san_steamworks.js.git

Adding existing Steamworks functions to steamworks-rs

The ./deps/san_steamworks-rs/steamworks-sys/src/windows_bindings.rs file makes the current Steamworks functions (written in C) available for use in Rust.

  • You can add other available Steamworks functions by checking the existing mappings and mimicking them (although most are already available).
  • The current Steamworks SDK version is 1.57.

steamworks.js requires the Steamworks functions present in steamworks-rs to enable their use in JS, so any required functionality that is not present in steamworks.js needs to be written into steamworks-rs first.

  • The two projects here are linked via ./deps/san_steamworks.js/cargo.toml.
  • You shouldn't need to rebuild steamworks-rs when building steamworks.js (as it will rebuild automatically), so it's okay to just save the files you have changed in steamworks-rs without running cargo build --release.

Adding existing steamworks-rs functions to steamworks.js

If you have written a function in steamworks-rs that you want to make available to JS (via steamworks.js), you'll need to create a new function like so:

// Example
#[napi]
pub fn shutdown() {
    unsafe { sys::SteamAPI_Shutdown() }
}

The steamworks.js build script does all the Rust > JS conversion for you, so as long as you're not getting any errors, your function should be available in JS after building.

Building steamworks.js

To build a release version of steamworks.js,navigate to ./deps/san_steamworks.js and run:

npm run build

This will generate a release (i.e. optimised) .node file in ./deps/san_steamworks/dist/win64 (or ./deps/san_steamworks/dist/linux on Linux), which is the module needed to load the functions created in steamworks.js into Node/Electron.

Creating the release project

Including the entirety of both the `steamworks-rs`/`steamworks.js` projects would make GitHub repos/application executables way too big.

A better way to do this is to just include the required dependencies for steamworks.js to work as a Node module.

  • The steamworks-rs/steamworks.js project files are only required to edit the functions and build the resulting module.
// TODO: This could probably be automated via a `package.json` command...

Method

  1. Go into ./deps/san_steamworks.js and copy the following:
  • dist folder (and all contents)
  • callback.d.ts
  • client.d.ts
  • index.d.ts
  • index.js
  • LICENSE
  • package.json
  • README.md
  1. Paste into ./deps/steamworks.js (create if not present)
  2. Go back to the project root
  3. If not done already, open package.json and add the following:
"dependencies": {
    "steamworks.js": "./deps/steamworks.js"
}
  1. Run the following command in the root directory:
npm i

This will add ./deps/steamworks.js as a dependency (and recreate it in ./node_modules/steamworks.js), so you can now use steamworks.js within Electron - including all your changes!