mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-12-01 07:24:56 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a61849d783 | ||
|
|
aa4a5d9b76 | ||
|
|
88cbfa4877 | ||
|
|
ba4ab66d47 | ||
|
|
0f9239bf36 |
No files matched your search
@@ -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
|
||||
|
||||
Generated
+14
-1
@@ -2099,6 +2099,8 @@ name = "graphite-desktop-platform-win"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"graphite-desktop",
|
||||
"windows 0.62.2",
|
||||
"windows-registry 0.6.1",
|
||||
"winres",
|
||||
]
|
||||
|
||||
@@ -2447,7 +2449,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
"windows-registry",
|
||||
"windows-registry 0.5.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6866,6 +6868,17 @@ dependencies = [
|
||||
"windows-strings 0.4.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-registry"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
|
||||
dependencies = [
|
||||
"windows-link 0.2.1",
|
||||
"windows-result 0.4.1",
|
||||
"windows-strings 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.2.0"
|
||||
|
||||
@@ -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;
|
||||
@@ -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>
|
||||
@@ -15,5 +15,9 @@ path = "src/main.rs"
|
||||
[dependencies]
|
||||
graphite-desktop = { path = "../.." }
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
windows-registry = "0.6"
|
||||
windows = { version = "0.62", features = ["Win32_UI_Shell"] }
|
||||
|
||||
[target.'cfg(target_os = "windows")'.build-dependencies]
|
||||
winres = "0.1"
|
||||
@@ -0,0 +1,103 @@
|
||||
// This is a bit of a hack to get file associations working without an installer.
|
||||
// TODO: Replace this with a proper installer that can set up file associations.
|
||||
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
use windows::Win32::UI::Shell::{SHCNE_ASSOCCHANGED, SHCNF_IDLIST, SHChangeNotify};
|
||||
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"];
|
||||
|
||||
pub fn write() {
|
||||
if let Err(e) = FileAssociationWriter::new(&env::current_exe().unwrap())
|
||||
.document_type(PROG_ID, DOCUMENT_FRIENDLY_NAME)
|
||||
.application(EXECUTABLE_NAME, APP_FRIENDLY_NAME, SUPPORTED_EXTENSIONS)
|
||||
.extension(FILE_EXTENSION, PROG_ID, MIME_TYPE)
|
||||
.write()
|
||||
{
|
||||
eprintln!("Failed to register file associations: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
struct FileAssociationWriter {
|
||||
open_command: String,
|
||||
icon_value: String,
|
||||
entries: Vec<RegistryEntry>,
|
||||
}
|
||||
|
||||
struct RegistryEntry {
|
||||
path: String,
|
||||
name: String,
|
||||
value: String,
|
||||
}
|
||||
|
||||
impl FileAssociationWriter {
|
||||
fn new(executable: &Path) -> Self {
|
||||
let exe_string = executable.to_string_lossy();
|
||||
Self {
|
||||
open_command: format!("\"{exe_string}\" \"%1\""),
|
||||
icon_value: format!("{exe_string},0"),
|
||||
entries: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn document_type(mut self, prog_id: &str, friendly_name: &str) -> Self {
|
||||
let base = format!("Software\\Classes\\{prog_id}");
|
||||
self.push(&base, "", friendly_name);
|
||||
self.push(&format!("{base}\\DefaultIcon"), "", &self.icon_value.clone());
|
||||
self.push(&format!("{base}\\shell\\open\\command"), "", &self.open_command.clone());
|
||||
self
|
||||
}
|
||||
|
||||
fn application(mut self, executable_name: &str, friendly_name: &str, supported_extensions: &[&str]) -> Self {
|
||||
let base = format!("Software\\Classes\\Applications\\{executable_name}");
|
||||
self.push(&base, "FriendlyAppName", friendly_name);
|
||||
self.push(&format!("{base}\\shell\\open\\command"), "", &self.open_command.clone());
|
||||
|
||||
let supported_path = format!("{base}\\SupportedTypes");
|
||||
for extension in supported_extensions {
|
||||
self.push(&supported_path, extension, "");
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
fn extension(mut self, extension: &str, prog_id: &str, mime_type: &str) -> Self {
|
||||
let path = format!("Software\\Classes\\{extension}");
|
||||
self.push(&path, "", prog_id);
|
||||
self.push(&path, "Content Type", mime_type);
|
||||
self
|
||||
}
|
||||
|
||||
fn push(&mut self, path: &str, name: &str, value: &str) {
|
||||
self.entries.push(RegistryEntry {
|
||||
path: path.to_owned(),
|
||||
name: name.to_owned(),
|
||||
value: value.to_owned(),
|
||||
});
|
||||
}
|
||||
|
||||
fn write(self) -> windows_registry::Result<()> {
|
||||
let mut changed = false;
|
||||
|
||||
for entry in &self.entries {
|
||||
let key = CURRENT_USER.create(&entry.path)?;
|
||||
if key.get_string(&entry.name).ok().as_deref() == Some(entry.value.as_str()) {
|
||||
continue;
|
||||
}
|
||||
key.set_string(&entry.name, &entry.value)?;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if changed {
|
||||
unsafe { SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, None, None) };
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,11 @@
|
||||
#![windows_subsystem = "windows"]
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod file_associations;
|
||||
|
||||
fn main() {
|
||||
#[cfg(target_os = "windows")]
|
||||
file_associations::write();
|
||||
|
||||
graphite_desktop::start();
|
||||
}
|
||||
Reference in new issue
Block a user