Skip to main content

Module open_files

Module open_files 

Source
Expand description

Files and URLs the app is asked to open: from the command line, from the file manager (a double-click on a document of an associated type, a drop on the Dock icon) and from a second launch forwarded by crate::single_instance. They all arrive in one queue, OpenFiles.

  • Command line (every platform): OpenFiles::push_args at startup.
  • macOS: Finder sends odoc (open documents) and GURL (open URL) Apple events, at launch and while running, instead of passing arguments. OpenFiles::listen_os installs handlers for them; call it on the main thread before the event loop starts, so the launch documents are not missed. It works alongside any windowing library: it uses the Apple event manager, not the application delegate.
  • Windows and Linux: the file manager starts the app with the files as arguments; a second launch while one runs is forwarded with crate::single_instance.

File associations themselves are declared when the app is packaged (CFBundleDocumentTypes in Info.plist, registry ProgIDs, .desktop MimeType=), not at run time.

Structs§

OpenFiles
The queue of things to open.
OpenSender
A handle that queues into an OpenFiles from any thread.

Enums§

Opened
Something to open.

Constants§

MAX_ITEMS
At most this many entries are taken from one launch or event.
MAX_LEN
Longest accepted argument or URL.

Functions§

classify
Classify one string: a URL (file: URLs become paths) or a path resolved against cwd.
file_url_to_path
A file: URL as a path (file:///Users/a/My%20Doc.txt). Only local (file:/// or file://localhost/) URLs.
from_args
What to open from command-line arguments (without the program name): flags (-x, --x, macOS’ -psn_…) are skipped, everything after -- is taken literally, relative paths are resolved against cwd. Non-UTF-8 arguments are taken as paths.