latex-stickies 1.3.4 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "latex-stickies",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "Sticky notes for your desktop that render LaTeX and Markdown.",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
@@ -18,6 +18,17 @@ const fs = require('fs');
18
18
  const path = require('path');
19
19
 
20
20
  const NAME = 'LaTeX Stickies';
21
+ /**
22
+ * Our own bundle identifier, matching the packaged builds.
23
+ *
24
+ * The Electron shell ships as com.github.Electron, and LaunchServices keys its
25
+ * database by identifier rather than by path. So on a machine that has seen any
26
+ * other Electron -- another project's node_modules, an old npx copy, a
27
+ * different Electron app entirely -- the Dock can serve that record's name,
28
+ * "Electron", however carefully this script renames our copy. Taking our own
29
+ * identifier is what stops the collision; renaming alone cannot.
30
+ */
31
+ const APP_ID = 'com.kevinjusak.latexsticky';
21
32
 
22
33
  /**
23
34
  * Makes LaunchServices re-read a bundle.
@@ -61,7 +72,10 @@ function main() {
61
72
  }
62
73
  };
63
74
 
64
- if (read('CFBundleName') === NAME) {
75
+ const binary = path.join(appPath, 'Contents', 'MacOS', NAME);
76
+ if (read('CFBundleName') === NAME
77
+ && read('CFBundleIdentifier') === APP_ID
78
+ && fs.existsSync(binary)) {
65
79
  // Already named, so a wrong name in the Dock can only be a stale cache.
66
80
  refreshLaunchServices(appPath);
67
81
  // Say so rather than exiting in silence. A user reporting "the Dock still
@@ -75,14 +89,35 @@ function main() {
75
89
 
76
90
  const backup = fs.readFileSync(plist);
77
91
  try {
78
- for (const key of ['CFBundleName', 'CFBundleDisplayName']) {
92
+ const fields = [
93
+ ['CFBundleName', NAME],
94
+ ['CFBundleDisplayName', NAME],
95
+ ['CFBundleIdentifier', APP_ID],
96
+ ['CFBundleExecutable', NAME],
97
+ ];
98
+ for (const [key, value] of fields) {
79
99
  try {
80
- execFileSync('plutil', ['-replace', key, '-string', NAME, plist]);
100
+ execFileSync('plutil', ['-replace', key, '-string', value, plist]);
81
101
  } catch (_) {
82
- execFileSync('plutil', ['-insert', key, '-string', NAME, plist]);
102
+ execFileSync('plutil', ['-insert', key, '-string', value, plist]);
83
103
  }
84
104
  }
85
105
 
106
+ // Rename the executable too. macOS takes the Dock label from the running
107
+ // executable, not only from the plist -- which is why the packaged builds
108
+ // have always shown the right name (electron-builder renames it) while
109
+ // every npm install showed "Electron" however the plist was rewritten.
110
+ const oldBinary = path.join(appPath, 'Contents', 'MacOS', 'Electron');
111
+ if (fs.existsSync(oldBinary) && !fs.existsSync(binary)) {
112
+ fs.renameSync(oldBinary, binary);
113
+ }
114
+ // require('electron') reads this file for the path it returns, so it has
115
+ // to follow the rename or every launcher breaks.
116
+ const pathTxt = path.join(path.dirname(appPath), '..', 'path.txt');
117
+ if (fs.existsSync(pathTxt)) {
118
+ fs.writeFileSync(pathTxt, `Electron.app/Contents/MacOS/${NAME}`);
119
+ }
120
+
86
121
  // The bundle icon is what shows before the app can set its own.
87
122
  const icon = path.join(__dirname, '..', 'build', 'icon.icns');
88
123
  const target = path.join(appPath, 'Contents', 'Resources', 'electron.icns');