Skip to content

Commit

Permalink
feat(bld): add NSLocalNetworkUsageDescription option for MacOS (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
beaugunderson authored Sep 20, 2024
1 parent 6135682 commit eea3f69
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ This object defines additional properties used for building for a specific platf
| CFBundleVersion | `string` | The version of the build that identifies an iteration of the bundle. |
| CFBundleShortVersionString | `string` | The release or version number of the bundle. |
| NSHumanReadableCopyright | `string` | A human-readable copyright notice for the bundle. |
| NSLocalNetworkUsageDescription | `string` | A human-readable description of why the application needs access to the local network. |


## Guides
Expand Down
23 changes: 12 additions & 11 deletions src/bld.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ import setOsxConfig from './bld/osx.js';
/**
* References:
* https://developer.apple.com/documentation/bundleresources/information_property_list
* @typedef {object} OsxRc OSX resource configuration options
* @property {string} name The name of the application
* @property {string} icon The path to the icon file. It should be a .icns file.
* @property {string} LSApplicationCategoryType The category that best describes your app for the App Store.
* @property {string} CFBundleIdentifier A unique identifier for a bundle usually in reverse DNS format.
* @property {string} CFBundleName A user-visible short name for the bundle.
* @property {string} CFBundleDisplayName The user-visible name for the bundle.
* @property {string} CFBundleSpokenName A replacement for the app name in text-to-speech operations.
* @property {string} CFBundleVersion The version of the build that identifies an iteration of the bundle.
* @property {string} CFBundleShortVersionString The release or version number of the bundle.
* @property {string} NSHumanReadableCopyright A human-readable copyright notice for the bundle.
* @typedef {object} OsxRc OSX resource configuration options
* @property {string} name The name of the application
* @property {string} icon The path to the icon file. It should be a .icns file.
* @property {string} LSApplicationCategoryType The category that best describes your app for the App Store.
* @property {string} CFBundleIdentifier A unique identifier for a bundle usually in reverse DNS format.
* @property {string} CFBundleName A user-visible short name for the bundle.
* @property {string} CFBundleDisplayName The user-visible name for the bundle.
* @property {string} CFBundleSpokenName A replacement for the app name in text-to-speech operations.
* @property {string} CFBundleVersion The version of the build that identifies an iteration of the bundle.
* @property {string} CFBundleShortVersionString The release or version number of the bundle.
* @property {string} NSHumanReadableCopyright A human-readable copyright notice for the bundle.
* @property {string} NSLocalNetworkUsageDescription A human-readable description of why the application needs access to the local network.
*/

/**
Expand Down
1 change: 1 addition & 0 deletions src/bld/osx.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export default async function setOsxConfig({ app, outDir, releaseInfo }) {
contentsInfoPlistJson.CFBundleVersion = app.CFBundleVersion;
contentsInfoPlistJson.CFBundleShortVersionString = app.CFBundleShortVersionString;
contentsInfoPlistJson.CFBundleExecutable = app.name;
contentsInfoPlistJson.NSLocalNetworkUsageDescription = app.NSLocalNetworkUsageDescription;

/* Remove properties that were not updated by the user. */
Object.keys(contentsInfoPlistJson).forEach((option) => {
Expand Down
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ export interface OsxAppOptions {
CFBundleShortVersionString?: string,
/** A human-readable copyright notice for the bundle. */
NSHumanReadableCopyright?: string,
/** A human-readable description of why the application needs access to the local network. */
NSLocalNetworkUsageDescription?: string,
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ export const parse = async (options, pkg) => {
options.app.CFBundleShortVersionString ?? pkg.version;
options.app.NSHumanReadableCopyright =
options.app.NSHumanReadableCopyright ?? undefined;
options.app.NSLocalNetworkUsageDescription =
options.app.NSLocalNetworkUsageDescription ?? undefined;
}

return { ...options };
Expand Down
4 changes: 3 additions & 1 deletion tests/specs/osx.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe.runIf(process.platform === 'darwin')('bld/setOsxConfig', async function
CFBundleSpokenName: 'Demo',
CFBundleVersion: '0.0.0',
CFBundleShortVersionString: '0.0.0',
NSHumanReadableCopyright: 'Copyright (c) 2024 NW.js Utilities'
NSHumanReadableCopyright: 'Copyright (c) 2024 NW.js Utilities',
NSLocalNetworkUsageDescription: 'This test application needs to access the local network for testing purposes.'
},
outDir: outDir,
releaseInfo: {
Expand Down Expand Up @@ -157,6 +158,7 @@ describe.runIf(process.platform === 'darwin')('bld/setOsxConfig', async function
expect(ContentsInfoPlistJson.CFBundleVersion).toEqual('0.0.0');
expect(ContentsInfoPlistJson.CFBundleShortVersionString).toEqual('0.0.0');
expect(ContentsInfoPlistJson.CFBundleExecutable).toEqual('nwapp');
expect(ContentsInfoPlistJson.NSLocalNetworkUsageDescription).toEqual('This test application needs to access the local network for testing purposes.');

const HelperAlertsAppJson = plist.parse(
await fs.promises.readFile(
Expand Down

0 comments on commit eea3f69

Please sign in to comment.