Generate a .reg file to set image Edit action

main
Isaiah Odhner 2019-02-17 18:56:31 -05:00
parent a778ba5ca8
commit 2a863a94cb
2 changed files with 27 additions and 8 deletions

14
TODO.md
View File

@ -206,29 +206,29 @@ might be a pointer events spec interpretation issue, and it could easily be that
### Desktop App (Electron)
Boilerplate:
Electron boilerplate stuff:
* [`electron-forge start` has a bug that prevents it from exiting when the window is closed.](https://github.com/electron-userland/electron-forge/issues/545)
Should I update to the beta so that `npm start` can quit normally?
* [`electron-forge start` has a bug where it won't exit.](https://github.com/electron-userland/electron-forge/issues/545)
Should I update to the beta so that `npm start` can quit normally when you close the window?
* [Set up Content-Security-Policy](https://electronjs.org/docs/tutorial/security)
* Remember window position/state
* Add icon to built executable
* Set up autoupdating
* Keep window hidden until loaded (`show: false`) ([`ready-to-show`](https://electronjs.org/docs/api/browser-window#event-ready-to-show))
* Ideally name executable `jspaint.exe` rather than `JS Paint.exe`
* Keep window hidden until loaded (`show: false`, [`ready-to-show`](https://electronjs.org/docs/api/browser-window#event-ready-to-show))
* Ideally name the executable `jspaint.exe` instead of `JS Paint.exe`
Functionality:
* File association support (allow setting jspaint as default image editor)
* A dialog when closing
* Subwindows as separate windows
* Document recovery without having to know File > Manage Storage exists (pop up contextually with a dialog when you need it)
* Document recovery without having to know about File > Manage Storage - pop up contextually with a dialog when you need it
* Show link URLs when you hover over them, in the status bar (because we have a status bar! haha) (there's this API: [event: update-target-url](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#event-update-target-url), which gave me the idea, or it could be implemented with mouse events)
* Recent files (could also be implemented for 98.js.org in the future)
* Create a landing page / home page for the desktop app (similar to https://desktop.webamp.org/ or https://desktop.github.com/) - (perhaps https://desktop.jspaint.app/) - and/or for JS Paint in general (perhaps https://jspaint.app/about/)
* Remove usage of `prompt` (and ideally `alert`/`confirm` too! shouldn't be using these anyways!)
* macOS: `open-file` event, `setRepresentedFilename`, `setDocumentEdited` etc.
* Windows: maybe handle `session-end` event and ask to save?
* Detect if file changes on disk, ask if you want to reload it?
### Also

View File

@ -4,13 +4,32 @@
// so libraries don't get confused and export to `module` instead of the `window`
global.module = undefined;
var is_dev = require("electron-is-dev");
var dialog = require("electron").remote.dialog;
var fs = require("fs");
var path = require("path");
var argv = require("electron").remote.process.argv;
// TODO: let user apply this setting somewhere in the UI
// (and ideally revert it)
// (Note: it would be better to use REG.EXE to apply the change, rather than a .reg file)
// This registry modification changes the right click > Edit option for images in Windows Explorer
var reg_contents = `Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\edit\command]
@="\\\"${argv[0].replace(/\\/g, "\\\\")}\\\" ${is_dev ? "\\\".\\\" " : ""}\\\"%1\\\""
`; // oof \\\\
var reg_file_path = path.join(is_dev ? "." : path.dirname(argv[0]), `set-jspaint${is_dev ? "-DEV-MODE" : ""}-as-default-image-editor.reg`);
if(process.platform == "win32" && !is_dev){
fs.writeFile(reg_file_path, reg_contents, function(err){
if(err){
return console.error(err);
}
});
}
if (process.platform == "win32" && argv.length >= 2) {
if (argv[1] === ".") { // in development, "path/to/electron.exe" "." "maybe/a/file.png" ...maybe?
if (is_dev) { // in development, "path/to/electron.exe" "." "maybe/a/file.png"
window.document_file_path_to_open = argv[2];
} else { // in production, "path/to/JS Paint.exe" "maybe/a/file.png"
window.document_file_path_to_open = argv[1];