-
-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting Error: spawn ENOTDIR with activeWindow() #185
Comments
same problem here, did you find a solution? |
nope, I get this error on macos, not sure if it's supposed to ask for permissions or the user need to set it manually (didn't try this yet) |
@Ladvace The app is working fine using electron start but not with the build, Not sure if the terminal has the permissions. BTW, what you are building with this? |
same for me, you mean what I'm using to build it? |
No, I mean what purpose you're using this package? |
how is this related to he problem? |
Filing a bug report for a native dependency without even specifying the OS is just asking to never get it addressed. |
@Nantris It's in MacOS(Silicon chip), and happening when creating build, Dev mode with electron is working fine. |
@qualwebs did you see this? #99 (comment) If this fixes the issue, there probably needs to be a note in the README for macOS too. |
I just tried this and it doesn't seem to fix it to me |
I'm planning to try this myself on macOS tomorrow, though not Silicon. Any other findings at all that might be helpful towards debugging? I wonder what version of macOS you're on as well and if your application is signed? |
@Nantris Also, Can I fetch browser URLs in linux and windows? if not, why and if that can be achieved? |
It works for me on macOS 14.5 - but specifically I tested with the optional permissions disabled. I suspect the app needs to be signed and notarized to work. I can't answer about URLs because we don't need them, sorry. Can't speak to whether this works on Silicon. |
I had the same error:
I use an M1 Macbook Pro (16GB) & Sonoma 14.5 What worked for me was modifying the node-modules directly and changing this file:
Here's the code: import path from "node:path";
import { promisify } from "node:util";
import childProcess from "node:child_process";
import { fileURLToPath } from "node:url";
import fs from "node:fs";
import process from "node:process";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const execFile = promisify(childProcess.execFile);
// Detect if running in packaged mode using process.resourcesPath
const isPackaged = process.resourcesPath !== process.cwd();
console.log("isPackaged:", isPackaged);
// Set the binary path dynamically for both development and packaged (production) mode
let binary = isPackaged
? path.join(
process.resourcesPath,
"app.asar.unpacked",
"node_modules",
"get-windows",
"main",
) // Packaged environment
: path.join(__dirname, "../main"); // Development environment
console.log("Binary path:", binary);
// Ensure the binary exists
if (!fs.existsSync(binary)) {
console.error("Binary file does not exist:", binary);
binary = path.join(__dirname, "../main");
}
const parseMac = (stdout) => {
try {
return JSON.parse(stdout);
} catch (error) {
console.error(error);
throw new Error("Error parsing window data");
}
};
const getArguments = (options) => {
const args = [];
if (options?.accessibilityPermission === false) {
args.push("--no-accessibility-permission");
}
if (options?.screenRecordingPermission === false) {
args.push("--no-screen-recording-permission");
}
return args;
};
export async function activeWindow(options) {
const { stdout } = await execFile(binary, getArguments(options));
return parseMac(stdout);
}
export function activeWindowSync(options) {
const stdout = childProcess.execFileSync(binary, getArguments(options), {
encoding: "utf8",
});
return parseMac(stdout);
}
export async function openWindows(options) {
const { stdout } = await execFile(binary, [
...getArguments(options),
"--open-windows-list",
]);
return parseMac(stdout);
}
export function openWindowsSync(options) {
const stdout = childProcess.execFileSync(
binary,
[...getArguments(options), "--open-windows-list"],
{ encoding: "utf8" },
);
return parseMac(stdout);
} Note: some of the logic is meant for use with building an Electron app, but shouldn't be an issue. Afterwards, I can get the activeWindow info with no issues. I'm considering raising a PR if this is a more common issue. |
@timeowilliams - thanks for the tip, could you raise the PR though, I'm curious to see what the fix is? Also are you using |
https://github.com/Tech-Nest-Ventures/get-windows/blob/main/lib/macos.js Something similar to this. I use |
I'm using |
I just tried to replace
because |
actually building it, I don't get the error, I just get this:
|
I can confirm that giving the right permission and the changes from @timeowilliams, it works! |
Ended up straying away quite a bit from this repo, but if you're interested in just using the dependency without having to mess with the code/just install, feel free to use this dependency: https://github.com/Tech-Nest-Ventures/get-windows ^ Specifically optimized for MacOS at this time. |
one thing I forgot to mention is that it worked fine in production, but for some reason |
@Ladvace , 100%! Was using the wrong method. Please change this in const isPackaged = process.main?.filename.indexOf("app.asar") !== undefined; to this: const isPackaged = process.resourcesPath !== process.cwd(); |
seems working great now! |
No description provided.
The text was updated successfully, but these errors were encountered: