Skip to content

Commit

Permalink
Fix build problem on non-Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 30, 2024
1 parent 28b0562 commit 0ebec41
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@ import preGyp from '@mapbox/node-pre-gyp';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const require = createRequire(import.meta.url);
const getAddon = () => {
const require = createRequire(import.meta.url);

const bindingPath = preGyp.find(path.resolve(path.join(__dirname, '../package.json')));
const bindingPath = preGyp.find(path.resolve(path.join(__dirname, '../package.json')));

const addon = (fs.existsSync(bindingPath)) ? require(bindingPath) : {
getActiveWindow() {},
getOpenWindows() {},
return (fs.existsSync(bindingPath)) ? require(bindingPath) : {
getActiveWindow() {},
getOpenWindows() {},
};
};

export async function activeWindow() {
return addon.getActiveWindow();
return getAddon().getActiveWindow();
}

export function activeWindowSync() {
return addon.getActiveWindow();
return getAddon().getActiveWindow();
}

export function openWindows() {
return addon.getOpenWindows();
return getAddon().getOpenWindows();
}

export function openWindowsSync() {
return addon.getOpenWindows();
return getAddon().getOpenWindows();
}

0 comments on commit 0ebec41

Please sign in to comment.