Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .nix/pkgs/graphite.nix
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ deps.crane.lib.buildPackage (
cp target/${if dev then "debug" else "release"}/graphite $out/bin/graphite

mkdir -p $out/share/applications
cp $src/desktop/assets/*.desktop $out/share/applications/
cp $src/desktop/assets/art.graphite.Graphite.desktop $out/share/applications/

mkdir -p $out/share/mime/packages
cp $src/desktop/assets/art.graphite.Graphite.xml $out/share/mime/packages/

mkdir -p $out/share/icons/hicolor/scalable/apps
cp ${branding}/app-icons/graphite.svg $out/share/icons/hicolor/scalable/apps/art.graphite.Graphite.svg
Expand Down
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion desktop/assets/art.graphite.Graphite.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Name=Graphite
GenericName=Vector & Raster Graphics Editor
Comment=Open-source vector & raster graphics editor. Featuring node based procedural nondestructive editing workflow.
Exec=graphite
Exec=graphite %F
Terminal=false
Type=Application
Icon=art.graphite.Graphite
Categories=Graphics;VectorGraphics;RasterGraphics;
Keywords=graphite;editor;vector;raster;procedural;design;
StartupWMClass=art.graphite.Graphite
MimeType=application/graphite+json;image/svg+xml;image/png;image/jpeg;image/gif;image/bmp;image/tiff;image/webp;image/x-portable-pixmap;image/x-portable-graymap;image/x-portable-bitmap;image/vnd.microsoft.icon;
9 changes: 9 additions & 0 deletions desktop/assets/art.graphite.Graphite.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/graphite+json">
<comment>Graphite Document</comment>
<sub-class-of type="application/json"/>
<glob pattern="*.graphite"/>
<icon name="art.graphite.Graphite"/>
</mime-type>
</mime-info>
3 changes: 3 additions & 0 deletions desktop/platform/win/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ path = "src/main.rs"
[dependencies]
graphite-desktop = { path = "../.." }

[target.'cfg(target_os = "windows")'.dependencies]
windows-registry = "0.6"

[target.'cfg(target_os = "windows")'.build-dependencies]
winres = "0.1"
48 changes: 48 additions & 0 deletions desktop/platform/win/src/file_associations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::env;
use std::error::Error;

use windows_registry::CURRENT_USER;

const PROG_ID: &str = "Graphite.Document";
const EXECUTABLE_NAME: &str = "Graphite.exe";
const APP_FRIENDLY_NAME: &str = "Graphite";
const DOCUMENT_FRIENDLY_NAME: &str = "Graphite Document";
const MIME_TYPE: &str = "application/graphite+json";
const FILE_EXTENSION: &str = ".graphite";
const SUPPORTED_EXTENSIONS: &[&str] = &[FILE_EXTENSION, ".svg", ".png", ".jpg", ".jpeg"];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The list of supported extensions for Windows is inconsistent with the MIME types declared for Linux in desktop/assets/art.graphite.Graphite.desktop. To ensure feature parity across platforms, consider adding the missing supported file extensions.

The Linux desktop file includes support for GIF, BMP, TIFF, WebP, PNM (PPM, PGM, PBM), and ICO formats.

Suggested change
const SUPPORTED_EXTENSIONS: &[&str] = &[FILE_EXTENSION, ".svg", ".png", ".jpg", ".jpeg"];
const SUPPORTED_EXTENSIONS: &[&str] = &[FILE_EXTENSION, ".svg", ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tif", ".tiff", ".webp", ".ppm", ".pgm", ".pbm", ".ico"];


pub fn register() {
if let Err(e) = register_inner() {
eprintln!("Failed to register file associations: {e}");
}
}

fn register_inner() -> Result<(), Box<dyn Error>> {
let exe = env::current_exe()?;
let exe_string = exe.to_string_lossy();
let open_command = format!("\"{exe_string}\" \"%1\"");
let icon_value = format!("{exe_string},0");

let prog_id = CURRENT_USER.create(format!("Software\\Classes\\{PROG_ID}"))?;
prog_id.set_string("", DOCUMENT_FRIENDLY_NAME)?;
let prog_id_icon = CURRENT_USER.create(format!("Software\\Classes\\{PROG_ID}\\DefaultIcon"))?;
prog_id_icon.set_string("", &icon_value)?;
let prog_id_command = CURRENT_USER.create(format!("Software\\Classes\\{PROG_ID}\\shell\\open\\command"))?;
prog_id_command.set_string("", &open_command)?;

let app_base = format!("Software\\Classes\\Applications\\{EXECUTABLE_NAME}");
let app = CURRENT_USER.create(&app_base)?;
app.set_string("FriendlyAppName", APP_FRIENDLY_NAME)?;
let app_command = CURRENT_USER.create(format!("{app_base}\\shell\\open\\command"))?;
app_command.set_string("", &open_command)?;
let supported = CURRENT_USER.create(format!("{app_base}\\SupportedTypes"))?;
for extension in SUPPORTED_EXTENSIONS {
supported.set_string(extension, "")?;
}

let extension = CURRENT_USER.create(format!("Software\\Classes\\{FILE_EXTENSION}"))?;
extension.set_string("", PROG_ID)?;
extension.set_string("Content Type", MIME_TYPE)?;

Ok(())
}
7 changes: 7 additions & 0 deletions desktop/platform/win/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#![windows_subsystem = "windows"]

#[cfg(target_os = "windows")]
mod file_associations;

fn main() {
#[cfg(target_os = "windows")]
file_associations::register();

graphite_desktop::start();
}
Loading