Module: Everywhere::DesktopAssets
- Defined in:
- lib/everywhere/desktop_assets.rb
Overview
Compiles an app's native/desktop/assets/ tree into the flat assets/ folder
the desktop shell reads at runtime — Resources/assets/ inside a packaged
.app, or the source tree itself under every dev (NATIVE_ASSETS_DIR).
Unlike iOS and Android there is no platform resource format to generate: macOS has no catalog for a Tauri bundle's loose resources, so "compiling" here means validating the names and copying. The filenames stay exactly as written, because the shell resolves variants itself (see assets_dir / asset_path in the shell's main.rs) — it is the one consumer, and it can read a suffix as cheaply as we can rewrite one.
Filenames are the whole API, matching AssetCatalog:
These assets are for the SHELL, not for your pages: window and tray icons, splash artwork, and anything extension Rust loads. Images your HTML references should keep coming from the asset pipeline, which already fingerprints and serves them.
Constant Summary collapse
- RASTER =
What the shell can actually decode. Deliberately narrower than AssetCatalog's: these are handed to tauri::image::Image or read by extension Rust, and neither speaks PDF or SVG.
%w[.png .jpg .jpeg].freeze
- PASSTHROUGH =
Windows tray icons are conventionally .ico; it's passed through untouched for an extension that wants to hand one to the platform directly.
%w[.ico].freeze
- EXTENSIONS =
(RASTER + PASSTHROUGH).freeze
- VECTOR =
%w[.pdf .svg].freeze
- SHELL_NAMES =
Names the shell gives meaning to on its own. Not reserved — providing one is exactly how you override a default — but worth naming here so the list has one home.
tray the menu-bar / system-tray icon, drawn as-is tray-template same, but declared a macOS template image: black + alpha, recoloured by the system so it stays legible in a light menu bar, a dark one, and under a highlight. Wins over `tray` when both are present. %w[tray tray-template].freeze
- VALID_NAME =
/\A[A-Za-z0-9_][A-Za-z0-9_.-]*\z/
Class Method Summary collapse
-
.write!(source, dest) ⇒ Object
Copy every image under
sourceintodest.
Class Method Details
.write!(source, dest) ⇒ Object
Copy every image under source into dest. Returns [names, errors];
nothing is written when errors is non-empty, so a broken assets/ tree
can't half-stamp a bundle.
dest is regenerated wholesale — this module owns that directory, and
an asset deleted from the app repo has to stop shipping.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/everywhere/desktop_assets.rb', line 57 def write!(source, dest) files, errors = plan(source) return [[], errors] unless errors.empty? FileUtils.rm_rf(dest) return [[], []] if files.empty? FileUtils.mkdir_p(dest) files.each { |file| FileUtils.cp(file[:path], File.join(dest, File.basename(file[:path]))) } [files.map { |file| file[:name] }.uniq.sort, []] end |