Skip to content

Commit

Permalink
feat(bld): add languageCode option for Windows (#1175)
Browse files Browse the repository at this point in the history
* Set Windows properties correctly (previously version property was used
to incorrectly set ProductVersion)
  • Loading branch information
WankkoRee authored Jul 27, 2024
1 parent 949c4b7 commit 96ad585
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,20 @@ This object defines additional properties used for building for a specific platf
| ---- | ------- | --------- | ----------- |
| `icon` | `string` | `undefined` | The path to the icon file. It should be a .ico file. |
| `name` | `string` | Value of `name` in app's `package.json` | The name of the application |
| `version` | `string` | Value of `version` in app's `package.json` | The version of the application |
| `version` | `string` | Value of `version` in app's `package.json` | (deprecated, Use `fileVersion` instead) The version of the application |
| `comments` | `string` | `undefined` | Additional information that should be displayed for diagnostic purposes. |
| `company` | `string` | `undefined` | Company that produced the file—for example, Microsoft Corporation or Standard Microsystems Corporation, Inc. This string is required. |
| `company` | `string` | Value of `author` in app's `package.json` | Company that produced the file—for example, Microsoft Corporation or Standard Microsystems Corporation, Inc. This string is required. |
| `fileDescription` | `string` | Value of `description` in app's `package.json` | File description to be presented to users. This string may be displayed in a list box when the user is choosing files to install. For example, Keyboard Driver for AT-Style Keyboards. This string is required. |
| `fileVersion` | `string` | Value of `version` in app's `package.json` | Version number of the file. For example, 3.10 or 5.00.RC2. This string is required. |
| `internalName` | `string` | `undefined` |Internal name of the file, if one exists—for example, a module name if the file is a dynamic-link library. If the file has no internal name, this string should be the original filename, without extension. This string is required. |
| `fileVersion` | `string` | Value of `version` option or value of `version` in app's `package.json` | Version number of the file. For example, 3.10 or 5.00.RC2. This string is required. |
| `internalName` | `string` | Value of `name` in app's `package.json` |Internal name of the file, if one exists—for example, a module name if the file is a dynamic-link library. If the file has no internal name, this string should be the original filename, without extension. This string is required. |
| `legalCopyright` | `string` | NW.js' copyright info | Copyright notices that apply to the file. This should include the full text of all notices, legal symbols, copyright dates, and so on. This string is optional. |
| `legalTrademark` | `string` | `undefined` | Trademarks and registered trademarks that apply to the file. This should include the full text of all notices, legal symbols, trademark numbers, and so on. This string is optional. |
| `originalFilename` | `string` | Value of `name` option | Original name of the file, not including a path. This information enables an application to determine whether a file has been renamed by a user. The format of the name depends on the file system for which the file was created. This string is required. |
| `privateBuild` | `string` | `undefined` | Information about a private version of the file—for example, Built by TESTER1 on \\TESTBED. |
| `productName` | `string` | Matches the package name defined in app's `package.json` | Name of the product with which the file is distributed. This string is required. |
| `productVersion` | `string` | Value of `version` in app's `package.json` | Version of the product with which the file is distributed—for example, 3.10 or 5.00.RC2. |
| `specialBuild` | `string` | `undefined` | Text that specifies how this version of the file differs from the standard version—for example, Private build for TESTER1 solving mouse problems on M250 and M250E computers. |
| `languageCode` | `number` | `1033` | Language of the file, defined by Microsoft, see: https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a |

#### Linux-specific options (`LinuxRc`)

Expand Down
31 changes: 20 additions & 11 deletions src/bld.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import util from "./util.js";
*
* @typedef {object} WinRc Windows configuration options. More info
* @property {string} name The name of the application
* @property {string} version The version of the application
* @property {string} version @deprecated Use {@link fileVersion} instead. The version of the application
* @property {string} comments Additional information that should be displayed for diagnostic purposes.
* @property {string} company Company that produced the file—for example, Microsoft Corporation or Standard Microsystems Corporation, Inc. This string is required.
* @property {string} fileDescription File description to be presented to users. This string may be displayed in a list box when the user is choosing files to install. For example, Keyboard Driver for AT-Style Keyboards. This string is required.
Expand All @@ -82,6 +82,7 @@ import util from "./util.js";
* @property {string} productName Name of the product with which the file is distributed. This string is required.
* @property {string} productVersion Version of the product with which the file is distributed—for example, 3.10 or 5.00.RC2. This string is required.
* @property {string} specialBuild Text that specifies how this version of the file differs from the standard version—for example, Private build for TESTER1 solving mouse problems on M250 and M250E computers. This string should be present only if VS_FF_SPECIALBUILD is specified in the fileflags parameter of the root block.
* @property {string} languageCode Language of the file, defined by Microsoft, see: https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a
*/

/**
Expand Down Expand Up @@ -295,17 +296,17 @@ const setLinuxConfig = async ({ app, outDir }) => {
const setWinConfig = async ({ app, outDir }) => {
let versionString = {
Comments: app.comments,
CompanyName: app.author,
CompanyName: app.company,
FileDescription: app.fileDescription,
FileVersion: app.fileVersion,
InternalName: app.name,
InternalName: app.internalName,
LegalCopyright: app.legalCopyright,
LegalTrademarks: app.legalTrademark,
OriginalFilename: app.name,
PrivateBuild: app.name,
ProductName: app.name,
ProductVersion: app.version,
SpecialBuild: app.name,
OriginalFilename: app.originalFilename,
PrivateBuild: app.privateBuild,
ProductName: app.productName,
ProductVersion: app.productVersion,
SpecialBuild: app.specialBuild,
};

Object.keys(versionString).forEach((option) => {
Expand All @@ -332,10 +333,18 @@ const setWinConfig = async ({ app, outDir }) => {
);
}
const [vi] = resedit.Resource.VersionInfo.fromEntries(res.entries);
const [major, minor, patch] = app.version.split(".");
vi.setFileVersion(major, minor, patch, 0, EN_US);
if (app.languageCode !== EN_US) {
res.removeResourceEntry(16, 1, EN_US);
vi.removeAllStringValues({
lang: EN_US,
codepage: 1200,
});
vi.lang=app.languageCode;
}
vi.setFileVersion(app.fileVersion, app.languageCode);
vi.setProductVersion(app.productVersion, app.languageCode);
vi.setStringValues({
lang: EN_US,
lang: app.languageCode,
codepage: 1200
}, versionString);
vi.outputToResourceEntries(res.entries);
Expand Down
42 changes: 22 additions & 20 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type AppOptions<P extends SupportedPlatform> =
: (WindowsAppOptions | OsxAppOptions | LinuxAppOptions);

/** Windows configuration options
*
*
* References:
* - https://learn.microsoft.com/en-us/windows/win32/msi/version
* - https://learn.microsoft.com/en-gb/windows/win32/sbscs/application-manifests
Expand All @@ -59,7 +59,7 @@ export type AppOptions<P extends SupportedPlatform> =
export interface WindowsAppOptions {
/** The name of the application */
name?: string,
/** The version of the application */
/** @deprecated Use {@link fileVersion} instead. The version of the application */
version?: string,
/** Additional information that should be displayed for diagnostic purposes. */
comments?: string,
Expand Down Expand Up @@ -87,28 +87,30 @@ export interface WindowsAppOptions {
productVersion: string,
/** Text that specifies how this version of the file differs from the standard version—for example, Private build for TESTER1 solving mouse problems on M250 and M250E computers. This string should be present only if VS_FF_SPECIALBUILD is specified in the fileflags parameter of the root block. */
specialBuild?: string,
/** Language of the file, defined by Microsoft, see: https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a */
languageCode?: number,
}

/** Linux configuration options
*
*
* References:
* https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
*/
export interface LinuxAppOptions {
/** Name of the application */
name?: string,
name?: string,
/** Generic name of the application */
genericName?: string,
genericName?: string,
/** If true the application is not displayed */
noDisplay?: boolean,
noDisplay?: boolean,
/** Tooltip for the entry, for example "View sites on the Internet". */
comment?: string,
comment?: string,
/** Icon to display in file manager, menus, etc. */
icon?: string,
icon?: string,
/** A list of strings identifying the desktop environments that should (/not) display a given desktop entry */
onlyShowIn?: string[],
onlyShowIn?: string[],
/** A list of strings identifying the desktop environments that should (/not) display a given desktop entry */
notShowIn?: string[],
notShowIn?: string[],
/** A boolean value specifying if D-Bus activation is supported for this application */
dBusActivatable?: boolean,
/** Path to an executable file on disk used to determine if the program is actually installed */
Expand Down Expand Up @@ -140,31 +142,31 @@ export interface LinuxAppOptions {
}

/** OSX resource configuration options
*
*
* References:
* https://developer.apple.com/documentation/bundleresources/information_property_list
*/
export interface OsxAppOptions {
/** The name of the application */
name?: string,
/** The path to the icon file. It should be a .icns file. */
icon?: string,
icon?: string,
/** The category that best describes your app for the App Store. */
LSApplicationCategoryType?: string,
LSApplicationCategoryType?: string,
/** A unique identifier for a bundle usually in reverse DNS format. */
CFBundleIdentifier?: string,
CFBundleIdentifier?: string,
/** A user-visible short name for the bundle. */
CFBundleName?: string,
CFBundleName?: string,
/** The user-visible name for the bundle. */
CFBundleDisplayName?: string,
CFBundleDisplayName?: string,
/** A replacement for the app name in text-to-speech operations. */
CFBundleSpokenName?: string,
CFBundleSpokenName?: string,
/** The version of the build that identifies an iteration of the bundle. */
CFBundleVersion?: string,
CFBundleVersion?: string,
/** The release or version number of the bundle. */
CFBundleShortVersionString?: string,
CFBundleShortVersionString?: string,
/** A human-readable copyright notice for the bundle. */
NSHumanReadableCopyright?: string,
NSHumanReadableCopyright?: string,
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,16 @@ export const parse = async (options, pkg) => {
options.app.company = options.app.company ?? pkg.author;
options.app.fileDescription =
options.app.fileDescription ?? pkg.description;
options.app.fileVersion = options.app.fileVersion ?? pkg.version;
options.app.fileVersion = options.app.fileVersion ?? options.app.version ?? pkg.version;
options.app.internalName = options.app.internalName ?? pkg.name;
options.app.legalCopyright = options.app.legalCopyright ?? undefined;
options.app.legalTrademark = options.app.legalTrademark ?? undefined;
options.app.originalFilename = options.app.originalFilename ?? pkg.name;
options.app.originalFilename = options.app.originalFilename ?? options.app.name;
options.app.privateBuild = options.app.privateBuild ?? undefined;
options.app.productName = options.app.productName ?? pkg.name;
options.app.productVersion = options.app.productVersion ?? pkg.version;
options.app.specialBuild = options.app.specialBuild ?? undefined;
options.app.languageCode = options.app.languageCode ?? 1033;
}

if (options.platform === "osx") {
Expand Down

0 comments on commit 96ad585

Please sign in to comment.