Skip to content

Commit 9f43069

Browse files
committed
feature: open directory by system contextMenu
1 parent b9e1f85 commit 9f43069

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

build/installer.nsh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
;install
2+
!macro customInstall
3+
WriteRegExpandStr HKCU "Software\Classes\Directory\shell\Photolisting" "" "以 Photolisting 中開啟"
4+
WriteRegExpandStr HKCU "Software\Classes\Directory\shell\Photolisting" "Icon" "$INSTDIR\photolisting.exe"
5+
WriteRegExpandStr HKCU "Software\Classes\Directory\shell\Photolisting\command" "" '"$INSTDIR\photolisting.exe" "%1"'
6+
7+
WriteRegExpandStr HKCU "Software\Classes\Directory\Background\shell\Photolisting" "" "以 Photolisting 中開啟"
8+
WriteRegExpandStr HKCU "Software\Classes\Directory\Background\shell\Photolisting" "Icon" "$INSTDIR\photolisting.exe"
9+
WriteRegExpandStr HKCU "Software\Classes\Directory\Background\shell\Photolisting\command" "" '"$INSTDIR\photolisting.exe" "%1"'
10+
11+
!macroend
12+
13+
;uninstall
14+
!macro customUninstall
15+
DeleteRegKey HKCU "Software\Classes\Directory\shell\Photolisting"
16+
DeleteRegKey HKCU "Software\Classes\Directory\Background\shell\Photolisting"
17+
!macroend

main.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const { app, BrowserWindow, screen } = require("electron");
1111
const path = require("path");
1212
const { default: axios } = require("axios");
1313

14+
let readinPath = "";
15+
1416
function createWindow() {
1517
// 創建瀏覽器窗口
1618
const mainWindow = new BrowserWindow({
@@ -79,9 +81,9 @@ function createWindow() {
7981
try {
8082
// const d = "C:\\Users\\narut\\Desktop\\test";
8183

82-
console.log(appPath);
84+
// console.log(appPath);
8385

84-
const d = appPath;
86+
const d = readinPath ? readinPath : appPath;
8587
const fileList = fs.readdirSync(d);
8688
const files = [];
8789

@@ -186,9 +188,20 @@ function createWindow() {
186188
// mainWindow.webContents.openDevTools();
187189
}
188190

191+
app.on("ready", function () {
192+
if (process.argv.length > 1) {
193+
const temp = process.argv[1];
194+
195+
if (fs.existsSync(temp) && fs.lstatSync(temp).isDirectory()) {
196+
readinPath = temp;
197+
}
198+
}
199+
});
200+
189201
// 這段程序將會在 Electron 結束初始化
190202
// 和創建瀏覽器窗口的時候調用
191203
// 部分 API 在 ready 事件觸發後才能使用。
204+
192205
app.whenReady().then(() => {
193206
createWindow();
194207

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "photolisting",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"main": "main.js",
55
"scripts": {
66
"dev": "cross-env NODE_ENV=dev vite",
@@ -41,7 +41,8 @@
4141
"dist/**/*",
4242
"assets/",
4343
"main.js",
44-
"preload.js"
44+
"preload.js",
45+
"build/**/*"
4546
],
4647
"asar": false,
4748
"win": {
@@ -59,6 +60,10 @@
5960
"repo": "photolisting",
6061
"owner": "huibizhang",
6162
"releaseType": "release"
63+
},
64+
"nsis": {
65+
"allowElevation": true,
66+
"include": "build/installer.nsh"
6267
}
6368
}
6469
}

0 commit comments

Comments
 (0)