Deploy multiple apps with "shared private" Qt frameworks on OS X - macos

I have a set of applications that work together. It should be possible to start each of these applications individually by the user (i.e. one application provides a monitoring feature, another a configuration feature etc), therefore I would like them to show up in the Applications folder as different applications (possibly within a directory).
The applications are based on Qt5, so I would like to package Qt along with the applications privately to ensure that Qt is present and available. On the other hand I would like to make sure that I only include a single copy of Qt to avoid bloating the system.
I am using a package installer, due to the inclusion of a LaunchDaemon as well.
How do I place the Qt frameworks needed in order to avoid having multiple copies?
Here's the naive way:
/Applications/
MyCompany/
Foo.app/
Contents/
Info.plist (must use its own plist to specify some properties)
MacOS/
foo
Frameworks/
Qt-Goes-Here??
Bar.app/
Contents/
Info.plist
MacOS/
bar
Frameworks/
Qt-Goes-Here?? - Or can this be a link to the other location?
Since I am not a Mac-guru, any input (including informing me that I am trying something stupid) is very welcome!

There are two possibilities here, the first is
/Library
and the second
/Library/Application Support
If you look there, you'll find folders with contents for various applications. You should be able to create a folder there and add the Qt Framework, then update your applications to point to that using install_name_tool
The docs state the following for /Library: -
The Library directory is the top-level directory for storing private
app-related data and preferences. There are several Library
directories scattered throughout the system but you should always use
the one located inside the current home directory. Do not store files
directly at the top-level of the Library directory. Instead, store
them in one of the specific subdirectories described in this table. In
OS X v10.7 and later, the Finder hides the Library directory in the
user’s home folder by default. Therefore, you should never store files
in this directory that you want the user to access. To get the path to
this directory use the NSLibraryDirectory search path key with the
NSUserDomainMask domain.
For /Library/Application Support: -
The Application Support directory is where your app stores any type of
file that supports the app but is not required for the app to run,
such as document templates or configuration files. The files should be
app-specific but should never store user data. This directory is
located inside the Library directory. Never store files at the top
level of this directory: Always put them in a subdirectory named for
your app or company. If the resources apply to all users on the
system, such as document templates, place them in /Library/Application
Support. To get the path to this directory use the
NSApplicationSupportDirectory search path key with the
NSLocalDomainMask domain. If the resources are user-specific, such as
workspace configuration files, place them in the current user’s
~/Library/Application Support directory. To get the path to this
directory use the NSApplicationSupportDirectory search path key with
the NSUserDomainMask domain.
The full documentation can be found here.

Related

Allowing a Macintosh application to write files

We market an application that runs on multiple platforms, including Macintosh. On the Macintosh the software gets packaged into a .dmg file, and when installed everything goes into the /Applications hierarchy.
Some of the files in our application's hierarchy are samples that users are supposed to be able to modify in place or copy to different files in the same directory. The problem is the permissions that seem to get applied within the /Applications hierarchy prevent our application from doing such operations.
So I either need to change the install so the directories and files in question within /Applications allow modification, or I need to segregate the sample files to a different location on the disk where they can be modified.
I've tried making sure the permissions on the files allow writing at the time the .dmg file is pulled together, but then when the product is installed the permissions get changed to more restrictive ones that don't allow file modification or copying.
I've been able to modify the packaging so the sample files get installed to a different location, but so far I haven't been able to find a suitable area on the Macintosh disk to put them so modification is allowed. I haven't been able to figure out how to tell the packaging that these sample files should be installed into the installer's home directory.
Anyone have any suggestions? I'm afraid I'm a bit of an Apple novice. The procedure to build the .dmg file employs a Makefile that invokes commands like pkgbuild and productbuild. The productbuild command uses a --distribution qualifier that references a .xml file. There don't seem to be any scripts invoked.

Can I put a Qt GUI process in the Resources folder under a Mac bundle

There are 2 processes. One is a GUI process that is located in MacOS folder under the Mac bundle, while the other one is a tray process that is located in Resources folder under the bundle. The tray process doesn't seem to be able to find the cocoa plugin/library. Because when I manually run it, there is an error as below
This application failed to start because it could not find or load the
Qt platform plugin "cocoa" in "".
The bundle structure looks like this
-Contents
|_MacOS
| |_gui
|
|_Resources
| |_tray
| |_qt.conf
|
|_Plugins
|_platforms
|_libqcocoa.dylib
qt.conf contains
[Paths]
Plugins = PlugIns
Imports = Resources/qml
Qml2Imports = Resources/qml
Is the right thing to do that putting tray process into resources folder within a Mac bundle?
According the Bundle Programming Guide the Resources folder is intended for resources like images, sounds, etc (see Table 2-5):
Contains all of the application’s resource files. This contents of this directory are further organized to distinguish between localized and nonlocalized resources. For more information about the structure of this directory, see The Resources Directory.
and:
The Resources directory is where you put all of your images, sounds, nib files, string resources, icon files, data files, and configuration files among others
The MacOS folder however may also contain helper executables:
Contains the application’s standalone executable code. Typically, this directory contains only one binary file with your application’s main entry point and statically linked code. However, you may put other standalone executables (such as command-line tools) in this directory as well.
Therefore, I think the MacOS folder is the best location for your tray binary. I don't know whether that solves the problem of the missing platform plugin.

Windows equivalent of a MacOS.app with a contents directory

This may sound like I'm just looking for a .exe file, but I'm not all that familiar with windows. I have been using pyinstaller to turn my apps into binaries. My app relies on a lot data directories and third party binaries that I package within the same directory as the executable binary. For Mac, this makes things easy because the user only has to click on MyApp.app inside the applications directory which is like a link to MyApp.app/Contents/MacOs/MyApp. This way MyApp never has to be touched and is all bundled together with the data directories (also loaded inside of MyApp.app/Contents/MacOs/).
However, I can't really find a windows equivalent. While Pyinstaller can create a directory with my data directories and executable inside of it, if the user ever moves the .exe file inside the directory, the app will never work (because it loses its relative location to the data directories). Is there such a thing that can package this directory like on MacOS so the user just has to click on a single .exe file that links to the .exe inside the directory packaged within it? That way we can just pass around one directory. Like a Mac.app?
Win32 apps store data within the executable file as resources, which allows the single file solution, but they can't be accessed using normal file APIs, there are a separate set of functions for resource handling. (This implies that resources aren't so useful for things that absolutely have to be files, like images of helper executables.)
Win32 also has alternate data streams, which are more similar to what you're used to with .app packages, separating a local identifier from the actual filename by $DATA:. But those only work on NTFS, get lost by many file management applications, never have been very popular, and are now effectively deprecated by Microsoft (by preventing access from Windows Store apps).

Where do I store reports created by my application on OSX

My application stores logs in /Users/username/Library/Logs/appname and preferences in /Users/username/Library/Preferences/appname but where I should store the reports it creates.
Originally they were in Logs, but they are not really logs. I then thought about putting them in /Users/username/Library/Reports/appname but the Reports folder does not exist under Library and it seems bad practise to create additional folders at this level.
What is the correct mac-friendly way to do things ?
A good candidate would be your app's folder in ~/Library/Application Support/
You may need to create it, and you should really use the bundle identifier for your app as the folder name.
~/Library/Application Support/com.bundleIdentifier.something/
In there you can create whatever you need to to support your app.
File System Programming Guide
Important: The files in the user’s Documents and Desktop directories
should reflect only the documents that the user created and works with
directly. Similarly, the media directories should contain only the
user’s media files. Those directories must never be used to store data
files that your app creates and manages automatically. If you need a
place to store automatically generated files, use the Library
directory, which is designated specifically for that purpose. For
information on where to put files in the Library directory, see “The
Library Directory Stores App-Specific Files.”
Application Support Use this directory to store all app data files except those associated with the user’s documents. For example, you
might use this directory to store app-created data files,
configuration files, templates, or other fixed or modifiable resources
that are managed by the app. An app might use this directory to store
a modifiable copy of resources contained initially in the app’s
bundle. A game might use this directory to store new levels purchased
by the user and downloaded from a server. All content in this
directory should be placed in a custom subdirectory whose name is that
of your app’s bundle identifier or your company. In iOS, the contents
of this directory are backed up by iTunes.
As far as I figured, those are reports that are the end result of the app itself and are something the user needs to have access to.
Even more so, the reports are HTML (so a valid recognizable format)?
I think that constitutes them as documents.
I would put a folder in documents named after the app and put the reports there.
A lot of apps do that (Office comes to mind at the moment).

Mac OS folder locations

We have an application that we're porting to Mac OS from Windows. Once installed, the user can customize the functionality of the application by editing certain approved "data files" with a text editor. Once saved, the application can be reloaded to compile and load the contents. A core part of the program is the editing and sharing of these data files, and the program provides a friendly interface to allow the user to edit them.
On Windows, these folders are located under a standard folder, accessed through a shell constant, that our installer makes accessible to all users. Once installed, any user can run the application and edit the data files it uses.
What is the equivalent folder to use for the mac? Is there somewhere we can put stuff that is accessible to all users normally, or do we have to flag it as "all users can access" somehow?
Edit: A couple of users have suggested /Users/Shared. Aren't files in /Users/Shared still limited somehow to the user who created them? I remember trying to copy files between accounts in /Users/Shared, and I had to "take ownership" of the files in /Users/Shared before I could do anything with them.
Read this document. It has a section on where to put application files. I doubt /Users/Shared is the right directory for what you want to do; a subdirectory within /Library/Application Support/ is probably more appropriate. Remember, though, that non-admin users will not be able to write there by default. In that case, you can fall back to using the corresponding directory in the user's home folder.
Don't hardcode paths to special directories. Rather, you should use the NSFileManager methods URLsForDirectory:inDomains: or URLForDirectory:inDomain:appropriateForURL:create:error:, or the Folder Manager from Carbon if you're not using Objective-C.
/Users/Shared on a Mac is a folder available to any user. Hope this helps.
Use /Users/Shared/your_application_name .

Resources