change-image-suffix 2.1.6 → 2.1.7

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [2.1.7](https://github.com/GuoSirius/change-image-suffix/compare/v2.1.6...v2.1.7) (2026-05-25)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * add %1 to context menu bat commands so selected files are passed ([db6cf30](https://github.com/GuoSirius/change-image-suffix/commit/db6cf300839e12ec0229057b25299e50f37f4b6b))
11
+
5
12
  ### [2.1.6](https://github.com/GuoSirius/change-image-suffix/compare/v2.1.5...v2.1.6) (2026-05-25)
6
13
 
7
14
 
package/dist/index.js CHANGED
@@ -120,37 +120,42 @@ endlocal
120
120
  { verb: 'avif', label: '📺 AVIF' },
121
121
  { verb: 'tiff', label: '📋 TIFF' },
122
122
  ];
123
- // ── 使用 inline shell 子菜单(比 ExtendedSubCommandsKey 更可靠地传递参数)──
123
+ // ── 使用 ExtendedSubCommandsKey 方式 ──
124
+ // 文件右键和目录右键均使用 bat 脚本,混合选择时自动分类文件和目录
124
125
  const menuBases = [
125
- {
126
- base: 'HKCU\\Software\\Classes\\*\\shell\\cis',
127
- cmd: (fmt) => `"${batPath}" ${fmt} "%1"`,
128
- multiSelect: true,
129
- },
130
- {
131
- base: 'HKCU\\Software\\Classes\\Directory\\shell\\cis',
132
- cmd: (fmt) => `"${batPath}" ${fmt} "%1"`,
133
- multiSelect: false,
134
- },
135
- {
136
- base: 'HKCU\\Software\\Classes\\Directory\\Background\\shell\\cis',
137
- cmd: (fmt) => `"${cisCmd}" -t ${fmt} -p "%V"`,
138
- multiSelect: false,
139
- },
126
+ { base: 'HKCU\\Software\\Classes\\Directory\\Background\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis', arg: '-p "%V"' },
127
+ { base: 'HKCU\\Software\\Classes\\Directory\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis_dir', useBat: true },
128
+ { base: 'HKCU\\Software\\Classes\\*\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis_file', useBat: true },
140
129
  ];
130
+ // 1. 注册公共子菜单(每种菜单类型独立注册)
131
+ const REG_ROOT = 'HKCU\\Software\\Classes\\';
132
+ for (const menu of menuBases) {
133
+ for (const fmt of formats) {
134
+ const shellKey = `${REG_ROOT}${menu.subMenu}\\shell\\${fmt.verb}`;
135
+ let cmd;
136
+ if (menu.useBat) {
137
+ // bat 脚本接收格式参数,%1 为 Windows 传入的文件/目录路径
138
+ cmd = `"${batPath}" ${fmt.verb} "%1"`;
139
+ }
140
+ else {
141
+ cmd = `"${cisCmd}" -t ${fmt.verb} ${menu.arg}`;
142
+ }
143
+ execSync(`reg add "${shellKey}" /ve /d "${fmt.label}" /f`, { stdio: 'ignore' });
144
+ execSync(`reg add "${shellKey}" /v Icon /d "${iconPath}" /f`, { stdio: 'ignore' });
145
+ execSync(`reg add "${shellKey}\\command" /ve /d "${cmd}" /f`, { stdio: 'ignore' });
146
+ }
147
+ }
148
+ // 2. 注册主菜单项(使用 ExtendedSubCommandsKey 关联各自的子菜单)
141
149
  for (const menu of menuBases) {
142
- // 注册主菜单项
143
150
  execSync(`reg add "${menu.base}" /ve /d "🖼 转换图片 (cis)" /f`, { stdio: 'ignore' });
144
151
  execSync(`reg add "${menu.base}" /v Icon /d "${iconPath}" /f`, { stdio: 'ignore' });
145
- if (menu.multiSelect) {
146
- execSync(`reg add "${menu.base}" /v MultiSelectModel /d Player /f`, { stdio: 'ignore' });
147
- }
148
- // 注册格式子菜单(inline shell 子键,确保参数正确传递)
149
- for (const fmt of formats) {
150
- const subKey = `${menu.base}\\shell\\${fmt.verb}`;
151
- execSync(`reg add "${subKey}" /ve /d "${fmt.label}" /f`, { stdio: 'ignore' });
152
- execSync(`reg add "${subKey}" /v Icon /d "${iconPath}" /f`, { stdio: 'ignore' });
153
- execSync(`reg add "${subKey}\\command" /ve /d "${menu.cmd(fmt.verb)}" /f`, { stdio: 'ignore' });
152
+ execSync(`reg add "${menu.base}" /v ExtendedSubCommandsKey /d "${menu.subMenu}" /f`, { stdio: 'ignore' });
153
+ // 使用 bat 的菜单(文件右键和目录右键):设置 command 接收文件路径 %1
154
+ // Windows 会将父命令收到的 %1 自动传递给子命令
155
+ if (menu.useBat) {
156
+ execSync(`reg add "${menu.base}\\command" /ve /d "cmd /c echo %1 > nul" /f`, { stdio: 'ignore' });
157
+ // 注意:不添加 AppliesTo 限制,让菜单始终显示
158
+ // bat 脚本会检查文件扩展名,自动忽略非图片文件
154
159
  }
155
160
  }
156
161
  // 写入版本标记,用于检测 npm update 后自动刷新菜单
@@ -178,6 +183,18 @@ function uninstallContextMenu() {
178
183
  }
179
184
  catch { /* ignore */ }
180
185
  }
186
+ // 删除公共子菜单(三个:目录空白、目录图标、文件)
187
+ const subMenuRoots = [
188
+ 'HKCU\\Software\\Classes\\Directory\\ContextMenus\\cis',
189
+ 'HKCU\\Software\\Classes\\Directory\\ContextMenus\\cis_dir',
190
+ 'HKCU\\Software\\Classes\\Directory\\ContextMenus\\cis_file',
191
+ ];
192
+ for (const root of subMenuRoots) {
193
+ try {
194
+ execSync(`reg delete "${root}" /f`, { stdio: 'ignore' });
195
+ }
196
+ catch { /* ignore */ }
197
+ }
181
198
  // 删除批处理文件、图标和版本标记
182
199
  const appDataDir = path.join(os.homedir(), 'AppData', 'Roaming', 'change-image-suffix');
183
200
  const batPath = path.join(appDataDir, 'cis_file.bat');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "change-image-suffix",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "type": "module",
5
5
  "description": "批量转换图片格式的CLI工具,支持递归搜索、深度限制、指定后缀、Windows右键菜单等功能",
6
6
  "main": "dist/index.js",