Skip to content
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

Tried compiling app using script and manual process. Getting this error when trying to build (M1 Pro MacBook Pro) #2

Closed
apotenza92 opened this issue Jun 14, 2022 · 50 comments

Comments

@apotenza92
Copy link

Hi, tried compiling app using script and manual process. Getting this error when trying to build (M1 Pro MacBook Pro)

> [email protected] build
> yackage build out/

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:372:5)
    at validateString (node:internal/validators:120:11)
    at Object.basename (node:path:1309:5)
    at packageApp (/Users/username/dock-window-preview/node_modules/yackage/lib/main.js:184:49)
    at async packageCleanApp (/Users/username/dock-window-preview/node_modules/yackage/lib/main.js:227:12)
    at async Command.build (/Users/username/dock-window-preview/node_modules/yackage/bin/yackage.js:32:3) {
  code: 'ERR_INVALID_ARG_TYPE'
}

@apotenza92
Copy link
Author

Also tried what you mentioned in #1 with no success unfortunately :(

@PepsRyuu
Copy link
Owner

Do you have the full log available from using the script approach?

@PepsRyuu
Copy link
Owner

Potentially related: yue/yackage#19

@apotenza92
Copy link
Author

Had to delete all the node lib refs in the middle to fit in a comment.

Last login: Tue Jun 14 18:15:57 on ttys000
alexpotenza@Alexs-MacBook-Pro ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/PepsRyuu/dock-window-preview/master/install.sh)"
++ dirname /bin/bash
+ SOURCE=/bin
+ cd /bin
+ '[' -d .git ']'
+ echo 'Not in git directory, cloning.'
Not in git directory, cloning.
+ git clone https://github.com/PepsRyuu/dock-window-preview.git /Users/alexpotenza/.dock-window-preview-git
Cloning into '/Users/alexpotenza/.dock-window-preview-git'...
remote: Enumerating objects: 125, done.
remote: Counting objects: 100% (125/125), done.
remote: Compressing objects: 100% (74/74), done.
remote: Total 125 (delta 65), reused 91 (delta 39), pack-reused 0
Receiving objects: 100% (125/125), 835.59 KiB | 2.43 MiB/s, done.
Resolving deltas: 100% (65/65), done.
+ cd /Users/alexpotenza/.dock-window-preview-git
+ touch .auto-generated
+ SOURCE=/Users/alexpotenza/.dock-window-preview-git
++ exportNode
+++ find . -name node
+++ grep bin/node
++ echo
+ NODE=
++ exportNpm
+++ find . -name npm-cli.js
+++ grep bin/npm-cli.js
++ echo
+ NPM=
+ echo

+ echo

+ '[' -f '' ']'
+ echo 'Node not found. Installing.'
Node not found. Installing.
+ mkdir -p node
++ uname -m
+ ARCHITECTURE=arm64
+ '[' arm64 == x86_64 ']'
+ '[' arm64 == arm64 ']'
+ curl https://nodejs.org/dist/v16.9.1/node-v16.9.1-darwin-arm64.tar.gz --output node.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 27.9M  100 27.9M    0     0  10.3M      0  0:00:02  0:00:02 --:--:-- 10.3M
+ tar -xzvf node.tgz -C node

<<bunch of node libraries>>

++ exportNode
+++ find . -name node
+++ grep bin/node
++ echo ./node/node-v16.9.1-darwin-arm64/bin/node
+ NODE=./node/node-v16.9.1-darwin-arm64/bin/node
++ exportNpm
+++ find . -name npm-cli.js
+++ grep bin/npm-cli.js
++ echo ./node/node-v16.9.1-darwin-arm64/lib/node_modules/npm/bin/npm-cli.js
+ NPM=./node/node-v16.9.1-darwin-arm64/lib/node_modules/npm/bin/npm-cli.js
+++ dirname ./node/node-v16.9.1-darwin-arm64/bin/node
++ readlink -f ./node/node-v16.9.1-darwin-arm64/bin
+ PATH=/Users/alexpotenza/.dock-window-preview-git/node/node-v16.9.1-darwin-arm64/bin:/Users/alexpotenza/.nvm/versions/node/v16.15.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin
+ ./node/node-v16.9.1-darwin-arm64/bin/node ./node/node-v16.9.1-darwin-arm64/lib/node_modules/npm/bin/npm-cli.js install

added 176 packages, and audited 178 packages in 6s

17 packages are looking for funding
  run `npm fund` for details

2 high severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
+++ dirname ./node/node-v16.9.1-darwin-arm64/bin/node
++ readlink -f ./node/node-v16.9.1-darwin-arm64/bin
+ PATH=/Users/alexpotenza/.dock-window-preview-git/node/node-v16.9.1-darwin-arm64/bin:/Users/alexpotenza/.nvm/versions/node/v16.15.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin
+ ./node/node-v16.9.1-darwin-arm64/bin/node ./node/node-v16.9.1-darwin-arm64/lib/node_modules/npm/bin/npm-cli.js run build

> [email protected] build
> yackage build out/

out/dock-window-preview: internal error in Code Signing subsystem
Error: child exited with code 1
    at ChildProcess.<anonymous> (/Users/alexpotenza/.dock-window-preview-git/node_modules/await-spawn/index.js:28:21)
    at ChildProcess.emit (node:events:394:28)
    at maybeClose (node:internal/child_process:1064:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) {
  code: 1,
  stderr: '',
  stdout: ''
}
++ git rev-parse --short HEAD
+ COMMIT_ID=15528df
+ echo 15528df
/bin/bash: line 59: out/Dock Window Preview.app/Contents/Resources/commit_id: No such file or directory
+ tccutil reset Accessibility com.pepsryuu.dock-window-preview
tccutil: No such bundle identifier "com.pepsryuu.dock-window-preview": The operation couldn’t be completed. (OSStatus error -10814.)
+ tccutil reset ScreenCapture com.pepsryuu.dock-window-preview
tccutil: No such bundle identifier "com.pepsryuu.dock-window-preview": The operation couldn’t be completed. (OSStatus error -10814.)
+ echo 'Killing existing process'
Killing existing process
++ ps -e
++ grep 'Dock Window Preview'
++ grep -v grep
++ awk '{print $1}'
+ PID=
+ '[' -z ']'
+ echo 'App not running. Proceeding.'
App not running. Proceeding.
+ cp -r 'out/Dock Window Preview.app' /Users/alexpotenza/Applications
cp: out/Dock Window Preview.app: No such file or directory
+ '[' -f .auto-generated ']'
+ echo 'Deleting auto-generated directory'
Deleting auto-generated directory
+ cd /Users/alexpotenza
+ rm -rf /Users/alexpotenza/.dock-window-preview-git
+ open /Users/alexpotenza/Applications
alexpotenza@Alexs-MacBook-Pro ~ % 

@PepsRyuu
Copy link
Owner

Same error as #1 in this case.

When you say you had no success with #1 (comment), can you explain what happened in more detail? Was there an error message? What commands did you use? :)

@apotenza92
Copy link
Author

image

Commented out line 70 and it built this time... I swear before this exact thing didn't work...
Build worked but app crashes on launch and nothing happens, however as you suggested in comment I did the following:

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign -d -v out/Dock\ Window\ Preview.app
Executable=/Users/alexpotenza/dock-window-preview/out/Dock Window Preview.app/Contents/MacOS/dock-window-preview
Identifier=yode
Format=app bundle with Mach-O thin (arm64)
CodeDirectory v=20400 size=263517 flags=0x20002(adhoc,linker-signed) hashes=8232+0 location=embedded
Signature=adhoc
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements=none

I'm not entirely sure how to interpret that result.

I ran the next command you suggested both with and without sudo but ended up with an error:

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign --force --deep --sign - out/Dock\ Window\ Preview.app
out/Dock Window Preview.app: replacing existing signature
out/Dock Window Preview.app: internal error in Code Signing subsystem

alexpotenza@Alexs-MacBook-Pro dock-window-preview % sudo codesign --force --deep --sign - out/Dock\ Window\ Preview.app
Password:
out/Dock Window Preview.app: replacing existing signature
out/Dock Window Preview.app: internal error in Code Signing subsystem
alexpotenza@Alexs-MacBook-Pro dock-window-preview % 

@PepsRyuu
Copy link
Owner

Very interesting! Thanks for the extra info! Although I'm not sure where this takes us. The first command you have that says that yode was downloaded pre-signed, but there's other native binaries that I would assume are not signed at all:

codesign -d -v out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview (yode)
codesign -d -v out/Dock\ Window\ Preview.app/Contents/MacOS/res/axlib/build/Release/axlib.node
codesign -d -v out/Dock\ Window\ Preview.app/Contents/MacOS/res/node_modules/gui/gui.node
codesign -d -v out/Dock\ Window\ Preview.app/Contents/MacOS/res/node_modules/fsevents/fsevents.node

Try see if you can sign a .node file. It will be interesting to see if it's just a problem signing the one file (yode) or if you have a problem signing completely:

codesign --sign - out/Dock\ Window\ Preview.app/Contents/MacOS/res/axlib/build/Release/axlib.node (and with sudo if that didn't work)

@apotenza92
Copy link
Author

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign --sign - out/Dock\ Window\ Preview.app/Contents/MacOS/res/axlib/build/Release/axlib.node
out/Dock Window Preview.app/Contents/MacOS/res/axlib/build/Release/axlib.node: is already signed

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign --sign - out/Dock\ Window\ Preview.app/Contents/MacOS/res/axlib/build/Release/axlib.node
out/Dock Window Preview.app/Contents/MacOS/res/axlib/build/Release/axlib.node: is already signed

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign --sign - out/Dock\ Window\ Preview.app/Contents/MacOS/res/node_modules/fsevents/fsevents.node
out/Dock Window Preview.app/Contents/MacOS/res/node_modules/fsevents/fsevents.node: is already signed

Signed them all successfully. When I try to sign again it says they're all signed.

After doing these 3 the app still won't launch. Here's the other outputs:

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign -d -v out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview
Executable=/Users/alexpotenza/dock-window-preview/out/Dock Window Preview.app/Contents/MacOS/dock-window-preview
Identifier=yode
Format=app bundle with Mach-O thin (arm64)
CodeDirectory v=20400 size=263517 flags=0x20002(adhoc,linker-signed) hashes=8232+0 location=embedded
Signature=adhoc
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements=none

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign -d -v out/Dock\ Window\ Preview.app/Contents/MacOS/res/axlib/build/Release/axlib.node
Executable=/Users/alexpotenza/dock-window-preview/out/Dock Window Preview.app/Contents/MacOS/res/axlib/build/Release/axlib.node
Identifier=axlib-55554944db42339d641d3823b56774da55d9116a
Format=Mach-O thin (arm64)
CodeDirectory v=20400 size=679 flags=0x2(adhoc) hashes=15+2 location=embedded
Signature=adhoc
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements count=0 size=12

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign -d -v out/Dock\ Window\ Preview.app/Contents/MacOS/res/node_modules/gui/gui.node
Executable=/Users/alexpotenza/dock-window-preview/out/Dock Window Preview.app/Contents/MacOS/res/node_modules/gui/gui.node
Identifier=gui-55554944c32bb57a41d33ee6a50df05b0733cd50
Format=Mach-O thin (arm64)
CodeDirectory v=20400 size=16773 flags=0x2(adhoc) hashes=518+2 location=embedded
Signature=adhoc
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements count=0 size=12

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign -d -v out/Dock\ Window\ Preview.app/Contents/MacOS/res/node_modules/fsevents/fsevents.node
Executable=/Users/alexpotenza/dock-window-preview/out/Dock Window Preview.app/Contents/MacOS/res/node_modules/fsevents/fsevents.node
Identifier=fsevents-55554944a20b17f291ba3be59ba2738b36bbbd37
Format=Mach-O universal (x86_64 arm64)
CodeDirectory v=20400 size=714 flags=0x2(adhoc) hashes=16+2 location=embedded
Signature=adhoc
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements count=0 size=12
alexpotenza@Alexs-MacBook-Pro dock-window-preview % 

@PepsRyuu
Copy link
Owner

PepsRyuu commented Jun 14, 2022

Amazing! This is really narrowing it down now. :) What happens with these:

codesign -d -v out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview (confirm signature)

codesign --sign - out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview

codesign --force --sign - out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview

I assume the first signing command says it's already signed, and the second one will throw an error with the vague internal error?

@apotenza92
Copy link
Author

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign -d -v out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview
Executable=/Users/alexpotenza/dock-window-preview/out/Dock Window Preview.app/Contents/MacOS/dock-window-preview
Identifier=yode
Format=app bundle with Mach-O thin (arm64)
CodeDirectory v=20400 size=263517 flags=0x20002(adhoc,linker-signed) hashes=8232+0 location=embedded
Signature=adhoc
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements=none

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign --sign - out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview
out/Dock Window Preview.app/Contents/MacOS/dock-window-preview: internal error in Code Signing subsystem

alexpotenza@Alexs-MacBook-Pro dock-window-preview % codesign --force --sign - out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview
out/Dock Window Preview.app/Contents/MacOS/dock-window-preview: replacing existing signature
out/Dock Window Preview.app/Contents/MacOS/dock-window-preview: internal error in Code Signing subsystem
alexpotenza@Alexs-MacBook-Pro dock-window-preview % 

Not exactly but kind of.

@PepsRyuu
Copy link
Owner

Excellent! Thanks again for your help on this! I think this all just comes down to how Yode is bundled.

One last thing to try if you don't mind:

codesign --force --no-strict --sign - out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview

@apotenza92
Copy link
Author

Tried it - gave the same error of "internal error in Code Signing subsystem".

App still won't open but hopefully I've give you some more clues as to why :)

What's meant to happen if the app launches? Is there a menubar icon or dock icon? On mine it looks like the dock icon is about to appear - a small gap starts to open but then it disappears. To me that's always happened on macOS if something is just crashing on launch.

@PepsRyuu
Copy link
Owner

PepsRyuu commented Jun 14, 2022

Will have to research more, and open a ticket on yackage to see if the author has been encountering this issue. The lack of access to an M1 makes it difficult to try more low-level debugging. :(

Final thing to try for now I promise: codesign --verify -v out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview

So on first launch, you will see it open in the dock and then close, but then it's supposed to show a modal asking for permissions. Once granted, it appears as a menubar icon. If you're not seeing the permissions modal, it's likely that it did crash somewhere, likely on signature verification. :( What I think is happening is that Yode is downloaded pre-signed, but on build, it modifies Yode and combines it together with the compiled app code, which makes the signature invalid. And I think it's failing to re-sign the code because it's not liking the fact there's "hidden data" attached to the binary, which M1 is probably very strict about. It seems like it should be a very common problem for multiple apps but I'm not finding much in terms in solutions.

Hypothetically I think I can create a custom build script that avoids combining the files together and signs the .node files which seems to work...

If you're comfortable with it, you could try using npm start and see if that goes further. You might need to sign node_modules/axlib/build/Release/axlib.node, node_modules/fsevents/fsevents.node and node_modules/gui/gui.node before running it though. No need to grant the permissions and I would not recommend using the app this way, but if it asks for permissions, it means that it's the build process that's broken.

@apotenza92
Copy link
Author

That command shows "invalid signature (code or signature have been modified)
In architecture: arm64"

Ran it as npm start with those signed - showed up with permissions window that I couldn't sign, even when I manually added the app in System Preferences. Would refuse to open the app even after allowing the permissions.

@apotenza92
Copy link
Author

Unfortunately I’m a structural engineer not a software engineer so I’m not much help in terms of knowing where to look next! But if you point me in a direction to read up more I’d be keen to keep trying to fix it in my spare time 😄 I do some basic coding in the background when I bored from designing buildings anyway..

@PepsRyuu
Copy link
Owner

You could have fooled me, would have assumed you were a software engineer! 😂

That confirms it so, it's not liking the fact that yode was modified. The permissions work differently when using npm start. You have to grant the permission to Terminal instead, which you should remove afterwards just incase as it grants the permission to everything that runs in the terminal. 🙂

Not much else I can think of that could be looked into at the moment. I'll research later this evening. Might just have to bit the bullet and write that custom build script from scratch. At least I have a lot more information now that really helps to narrow it down! Your help has been very much appreciated, learned so much! 😁

@apotenza92
Copy link
Author

Me too mate. I just got it running by giving Terminal the permissions temporarily. Finally saw the little DWP appear up in the menu bar. But alas... no previews are appearing in the dock 😄. The debugger is running in the terminal and showed this:

[DEBUG] 1655210186001 Config: {"aliases":{"Visual Studio Code":"Code"},"theme":{"preview":{"border:color":"#ffffff","background:color":"#cc000000","background:color:hover":"#cc777777","caption:color":"#ffffff"}}}
[DEBUG] 1655210186022 Permissions: {"accessibility":1,"screen_recording":1}
[DEBUG] 1655210187130 Local Mouse Click
[DEBUG] 1655210190128 Global Mouse Click
[DEBUG] 1655210190129 Outside Preview Mouse Down
[DEBUG] 1655210197601 Global Mouse Click
[DEBUG] 1655210197602 Outside Preview Mouse Down
[DEBUG] 1655210199928 Global Mouse Click

What does Visual Studio Code have to do with the app running?

@apotenza92
Copy link
Author

Oh, one piece of information that I probably should've mentioned way earlier. I'm on the macOS 13.0 Ventura beta 1, so there could be heaps of bugs inherent in my OS that wouldn't affect others.

@PepsRyuu
Copy link
Owner

It's possible 13.0 breaks some of the native Objective-C code. This app uses some private APIs, so it's possible those have changed. Although I would have expected to see an error log of some sort if that was the case. 🤔 You could try throw a bunch of DEBUG_LOG function calls throughout the preview.js file to narrow it down. I'm stuck on 12.4 so I've no way of trying this myself. 🙁

Aliases are an important feature. Sometimes what an app is called in the dock, is not the same as the name of the app according to the system processes. For example, Visual Studio Code is called "Visual Studio Code" on the dock, but when you get a list of running processes, it's called "Code". This occurs fairly rarely though, most apps are usually the same name, but the config is available should it happen for another app. 🙂

@PepsRyuu
Copy link
Owner

Updated the code to include some additional useful debug messages. :)

@PepsRyuu
Copy link
Owner

Another test to try. I noticed that sometimes Mac doesn't let you sign over binaries if they have an issue with their existing signature. Try to remove the signature first, then see if you can sign it.

codesign --remove-signature out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview
codesign --force --no-strict --sign - out/Dock\ Window\ Preview.app/Contents/MacOS/dock-window-preview

@apotenza92
Copy link
Author

Gave it a go - no luck. App won't open yet without using npm start. If I do run with npm start window previews aren't appearing yet either. More work to be done! 😀

@PepsRyuu
Copy link
Owner

PepsRyuu commented Jun 15, 2022

Did the additional debug messages show additional information when using npm start? Did the --remove-signature command throw any error at all? If you used codesign -d -v will it say that the code isn't signed?

@PepsRyuu
Copy link
Owner

Custom build script that in theory, should allow signing.

  • Clone the repo.
  • If dependencies have not been installed with npm install, install them.
  • Create a file called build.js in the root of the repository.
  • Create a file with the below content.
  • In your terminal, cd into the repository, run node build.js, should not throw an error.
  • Theoretically, if all goes to plan, should have a compiled binary that can run in out.

If this works, I'll update the normal build script to use this approach instead. 🤞

let fs = require('fs-extra');
let path = require('path');
let config = require('./package.json');
let spawn = require('await-spawn')

// Clean output directory
if (fs.existsSync('out')) {
    console.log('Cleaning out directory');
    fs.removeSync('out');
}

if (!fs.existsSync('out')) {
    console.log('Creating out directory');
    fs.mkdirSync('out');
}

let appDir = 'out/' + config.build.productName + '.app';

// Create the standard Mac app directories
console.log('Creating app folder structure');
fs.mkdirSync(appDir);
fs.mkdirSync(appDir + '/Contents');
fs.mkdirSync(appDir + '/Contents/MacOS');
fs.mkdirSync(appDir + '/Contents/Resources');

console.log('Creating PList');
fs.writeFileSync(appDir + '/Contents/Info.plist', `
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
        <dict>
            <key>CFBundlePackageType</key>
            <string>APPL</string>
            <key>CFBundleIdentifier</key>
            <string>${config.build.appId}</string>
            <key>CFBundleDisplayName</key>
            <string>${config.build.productName}</string>
            <key>CFBundleName</key>
            <string>${config.build.productName}</string>
            <key>CFBundleExecutable</key>
            <string>yode</string>
            <key>CFBundleVersion</key>
            <string>${config.version}</string>
            <key>CFBundleShortVersionString</key>
            <string>${config.version}</string>
            <key>CFBundleIconFile</key>
            <string>icon.icns</string>
            <key>LSMinimumSystemVersion</key>
            <string>10.10.0</string>
            <key>NSHighResolutionCapable</key>
            <true/>
            <key>NSSupportsAutomaticGraphicsSwitching</key>
            <true/>
        </dict>
    </plist>
`.trim());

// Copy icon to correct location
console.log('Copying App icon');
fs.copySync('node_modules/yackage/resources/icon.icns', appDir + '/Contents/Resources/icon.icns');

// Copy all of the source code and dependencies
[
    'index.js',
    'package.json',
    'config.json',
    'node_modules',
    'lib',
    'axlib'
].forEach(entry => {
    console.log('Copying File: ' + entry);
    fs.copySync(entry, appDir + '/Contents/MacOS/' + entry);
});

// Patch yode to load in local file instead of showing REPL
(() => {
    console.log('Patching Yode');
    let mark = '// Not an ASAR archive, continue to Node\'s default routine.';
    let code = fs.readFileSync('node_modules/fetch-yode/bin/yode');

    let pos = code.indexOf(Buffer.from(mark));
    if (pos <= 0)
        throw new Error('Failed to find mark. Invalid version of Yode.');
    
    code.write(`return execPath + '/../index.js';`.padEnd(mark.length, ' '), pos);
    fs.writeFileSync(appDir + '/Contents/MacOS/yode', code);
    fs.chmodSync(appDir + '/Contents/MacOS/yode', '755');
    console.log('Patched Yode');
})();

// Signing
(async() => {
    let files = [
        appDir + '/Contents/MacOS/yode',
        appDir + '/Contents/MacOS/axlib/build/Release/axlib.node',
        appDir + '/Contents/MacOS/node_modules/fsevents/fsevents.node',
        appDir + '/Contents/MacOS/node_modules/gui/gui.node'
    ];

    // Copying out first, then sign, then copy back in.
    // For some reason, Mac doesn't like signing files inside .app directory.
    for (let i = 0; i < files.length; i++) {
        console.log('Signing ' + files[i]);
        let tempFile = 'out/' + path.basename(files[i]);
        fs.copySync(files[i], tempFile);
        await spawn('codesign', ['--remove-signature', tempFile], { stdio: 'inherit' });
        await spawn('codesign', ['--sign', '-', tempFile], { stdio: 'inherit' });
        fs.copySync(tempFile, files[i]);
        fs.removeSync(tempFile);
    }
})();

@apotenza92
Copy link
Author

Hi, finally got to try this out now. Yes that script worked to create an app that could launch. It launches with the permissions dialog - but even once I give it Accessibility and Screen Recording permission it doesn't let me go beyond that screen.

@PepsRyuu
Copy link
Owner

Brilliant! I'll update the installation script, thanks for confirming! :)

As for it not showing anything beyond that, when you try running through the terminal, what do the logs say when you try to hover over the dock items? The latest version should show more debug logs. :)

@apotenza92
Copy link
Author

apotenza92 commented Jun 18, 2022

Just gave it a go. Seeing nothing unfortunately. I don't see any previews. I ran it and clicked around a little. Could be an issue with Ventura that I'm seeing nothing?

[DEBUG] 1655542732096 Config: {"aliases":{"Visual Studio Code":"Code"},"theme":{"preview":{"border:color":"#ffffff","background:color":"#cc000000","background:color:hover":"#cc777777","caption:color":"#ffffff"}}}
[DEBUG] 1655542732508 Permissions: {"accessibility":1,"screen_recording":1}
[DEBUG] 1655542738194 Global Mouse Click
[DEBUG] 1655542738195 Outside Preview Mouse Down
[DEBUG] 1655542747835 Global Mouse Click
[DEBUG] 1655542747835 Outside Preview Mouse Down
[DEBUG] 1655542748707 Global Mouse Click
[DEBUG] 1655542748709 Outside Preview Mouse Down
[DEBUG] 1655542750240 Global Mouse Click
[DEBUG] 1655542750241 Outside Preview Mouse Down
[DEBUG] 1655542751173 Global Mouse Click
[DEBUG] 1655542751173 Outside Preview Mouse Down
[DEBUG] 1655542753478 Global Mouse Click
[DEBUG] 1655542753479 Outside Preview Mouse Down
[DEBUG] 1655542754186 Global Mouse Click
[DEBUG] 1655542754187 Outside Preview Mouse Down
[DEBUG] 1655542754672 Global Mouse Click
[DEBUG] 1655542754673 Outside Preview Mouse Down
[DEBUG] 1655542754843 Global Mouse Click
[DEBUG] 1655542754844 Outside Preview Mouse Down
[DEBUG] 1655542755014 Global Mouse Click
[DEBUG] 1655542755015 Outside Preview Mouse Down
[DEBUG] 1655542755973 Global Mouse Click
[DEBUG] 1655542755974 Outside Preview Mouse Down
[DEBUG] 1655542758417 Global Mouse Click
[DEBUG] 1655542758418 Outside Preview Mouse Down
[DEBUG] 1655542768376 Local Mouse Click
[DEBUG] 1655542770544 Config file changed.
[DEBUG] 1655542770545 Config: {"aliases":{"Visual Studio Code":"Code"},"theme":{"preview":{"border:color":"#ffffff","background:color":"#cc000000","background:color:hover":"#cc777777","caption:color":"#ffffff"}}}
[DEBUG] 1655542776148 Global Mouse Click
[DEBUG] 1655542776149 Outside Preview Mouse Down
[DEBUG] 1655542777643 Local Mouse Click

@PepsRyuu
Copy link
Owner

I would have expected to see something like this here:

[DEBUG] 1655545235652 Config: {"aliases":{"Visual Studio Code":"Code"},"theme":{"preview":{"border:color":"#ffffff","background:color":"#cc000000","background:color:hover":"#cc777777","caption:color":"#ffffff"}}}
[DEBUG] 1655545235693 Permissions: {"accessibility":1,"screen_recording":1}
[DEBUG] 1655545237342 Global Mouse Click
[DEBUG] 1655545237342 Outside Preview Mouse Down
[DEBUG] 1655545238456 Hovering Dock App: Terminal
[DEBUG] 1655545238456 App is running: 1
[DEBUG] 1655545238470 Found windows: 1
[DEBUG] 1655545238502 Preview Windows: 1
[DEBUG] 1655545238502 Show Preview

The only way you can't see the logs there, is either something going wrong with listening to mouse moves, or potentially the mouse position is being calculated incorrectly. Is your dock located on the bottom of the screen? Is there something unusual about your monitor setup or anything?

@apotenza92
Copy link
Author

Dock is on the bottom and there's nothing unusual going on with monitors or anything, except that I'm on Ventura beta 1 😄

@PepsRyuu
Copy link
Owner

The only other thing you can do is try is added in additional DEBUG_LOG calls into the code and try running it again using ``npm start``` and narrow down the problem that way. 🤔 Perhaps there's some conditional inside https://github.com/PepsRyuu/dock-window-preview/blob/master/lib/preview.js#L239 that's breaking.

The only other explanation is that Apple changed how accessibility works, but that would be a massive breaking change for them to make... 🤔

@apotenza92
Copy link
Author

I had a bit of a play by adding some more debug messages in but nothing I did made debug show more information than the following:

[DEBUG] 1655702084854 Global Mouse Click
[DEBUG] 1655702084855 Outside Preview Mouse Down

As I said though, I'm not much of a programmer, so I was kind of just playing around in the dark with it 😄

@apotenza92
Copy link
Author

BTW an alternate app to this that works decently but has also been kind of abandoned is DockMate. It's more modern than HyperDock. I have emailed the developers asking if they'd be willing to open source it too as it seems to not be maintained anymore, so if that ever happened there'd be a much larger foundation to build upon for this project.

@PepsRyuu
Copy link
Owner

I just find it really weird you're not seeing anything additional in the logs. What changes did you try to make exactly? Can you outline the steps? Try throw in something near the very beginning of the preview.js file just to make sure your changes are actually going through (eg. adding DEBUG_LOG('hello') to L35).

I'm aware of the alternatives, but like you said, they're often abandoned, closed source, and charge a fee, and for a work laptop, that's just a no go. 🙂

@apotenza92
Copy link
Author

It's definitely working when I make changes to the existing debug messages I get, so my changes are going through. But I still haven't been able to get it to display anything other than those two I previously mentioned. If I was to guess it's simply not detecting whether the mouse cursor is over a dock icon. Might be an issue with axlib and Ventura. This is the only part of the code at the moment that actually seems to work:
Screenshot 2022-06-23 at 8 35 46 pm

@PepsRyuu
Copy link
Owner

Not much I can do from here unfortunately. 🙁

Only thing I can suggest is to keep throwing in debug calls throughout the code (add them everywhere), and printing out the variables, until you spot something unusual.

As you suggested, it sounds like it's not picking up on the fact it's hovering over the dock. Did the DEBUG_LOG you add show anything odd about the co-ordinates? Try maybe adding DEBUG_LOG(JSON.stringify(el)); to see more information about the element that's coming back.

@apotenza92
Copy link
Author

Ok, I'll give it a go when I have more time on my hands 😄 As I said my day job is structural engineering 🏗️

@apotenza92
Copy link
Author

Hi - I'm back on Monterey now, was having too many issues and bugs with Ventura. The app is still having the same issues as when I was on Ventura - App is not detecting anything I mouse over. This all makes me think the problem may be with Apple Silicone compatibility as I'm on an M1 Pro.

@PepsRyuu
Copy link
Owner

It does sound like it, but none of the code to my knowledge is Intel specific... 🙁 And if part of the native modules is working which appears to be the case, would be odd for another part to not work...

@apotenza92
Copy link
Author

Mmm yeah I'm unsure unfortunately 😞 likely have to wait until you buy an Apple Silicon Mac 😆 do itttt

@DavidKaub
Copy link

Hi, tried compiling app using script and manual process. Getting this error when trying to build (M1 Pro MacBook Pro)

> [email protected] build
> yackage build out/

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:372:5)
    at validateString (node:internal/validators:120:11)
    at Object.basename (node:path:1309:5)
    at packageApp (/Users/username/dock-window-preview/node_modules/yackage/lib/main.js:184:49)
    at async packageCleanApp (/Users/username/dock-window-preview/node_modules/yackage/lib/main.js:227:12)
    at async Command.build (/Users/username/dock-window-preview/node_modules/yackage/bin/yackage.js:32:3) {
  code: 'ERR_INVALID_ARG_TYPE'
}

I'm curious I've got this error after I ran ´npm audit fix´ due to some vulnerabilities. If I did not run the npm fix command I've get the error from issue #1 (also M1). Was this the same with you @apotenza92

@PepsRyuu
Copy link
Owner

PepsRyuu commented Aug 9, 2022

@DavidKaub Have you tried the script I've posted in #2 (comment) ?

@DavidKaub
Copy link

I just ran the script you suggested. It definitely fixes the signing errors. But I also don't get any preview when hovering over the dock. Running npm start also reveals that the app does not really recognize the cursor position, since opening any app from the dock only yields

[DEBUG] 1660115523529 Global Mouse Click
[DEBUG] 1660115523530 Outside Preview Mouse Down

I will tinker the debug output to narrow it down but, since I'm very new to Mac, I don't expect too much....

@DavidKaub
Copy link

BTW an alternate app to this that works decently but has also been kind of abandoned is DockMate. It's more modern than HyperDock. I have emailed the developers asking if they'd be willing to open source it too as it seems to not be maintained anymore, so if that ever happened there'd be a much larger foundation to build upon for this project.

@apotenza92 Any updates from here?

@PepsRyuu
Copy link
Owner

I just ran the script you suggested. It definitely fixes the signing errors. But I also don't get any preview when hovering over the dock. Running npm start also reveals that the app does not really recognize the cursor position, since opening any app from the dock only yields

[DEBUG] 1660115523529 Global Mouse Click
[DEBUG] 1660115523530 Outside Preview Mouse Down

I will tinker the debug output to narrow it down but, since I'm very new to Mac, I don't expect too much....

That's perfect, means the situation is reproducible consistently on M1. :)

If you can debug it further, would be much appreciated. I have no access to an M1 so I'm completely locked out of helping on this issue, but happy to answer questions where I can. I'm very new to Macs as well, so it wouldn't be surprising if I done something silly somewhere. 🙂 It sounds like axlib.AXObserveGlobalMouseMove is not being called correctly?

@DavidKaub
Copy link

While I wish I would be able to help you with this issue and really appreciate the effort, I have to admit that I have given up on this app since I found another open source alternative that works good for me (AltTab + DockAltTab). Maybe this can help somebody, or taking a look into the code might also help with development here. Regards

@t1m0thyj
Copy link
Contributor

t1m0thyj commented Jan 26, 2024

That's perfect, means the situation is reproducible consistently on M1. :)

If you can debug it further, would be much appreciated. I have no access to an M1 so I'm completely locked out of helping on this issue, but happy to answer questions where I can. I'm very new to Macs as well, so it wouldn't be surprising if I done something silly somewhere. 🙂 It sounds like axlib.AXObserveGlobalMouseMove is not being called correctly?

I've been able to reproduce this behavior on an M2 as well. I'm a developer but have no experience with Objective C or developing MacOS apps 😅 I'm happy to help with debugging wherever I can.

So far I've observed that axlib.AXObserveGlobalMouseMove is getting called, but AXUIElementCopyAttributeValue ignores the presence of the dock. When hovering over the dock, both kAXSubroleAttribute and kAXTitleAttribute return -25212 which is kAXErrorNoValue.

I've also tried to inspect the dock as an AXUIElementRef:

AXUIElementRef appElement = AXUIElementCreateApplication([[[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"] lastObject] processIdentifier]);

This returns an element with kAXTitleAttribute = "Dock", but kAXChildrenAttribute is an empty array which is surprising because I expected it to return an array of items with kxAXSubroleAttribute = "AXApplicationDockItem".

Any ideas what might be going wrong? I'm kind of stumped ATM. It seems like AXApplicationDockItem is inaccessible through the Accessibility API, but I have a hard time believing that MacOS would make such a change since 3rd party apps have valid reason to access dock items for accessibility purposes.

@PepsRyuu
Copy link
Owner

Still no M1-type device to test with unfortunately, so I can still only speculate.

I wonder if it's some sort of security permission that's required, that has a different default between Intel and M1 chips... Like you said, it would be baffling if they just removed the functionality entirely, but it would make sense to me if they changed a default permission somewhere like how code signing became mandatory...

@t1m0thyj
Copy link
Contributor

So I got it working...noticed that axlib.AXObserveGlobalMouseMove was receiving the wrong mouse position because x was always 0. Apparently on M1 type Macs the NSInteger type is 32-bit instead of 64-bit.

After changing all the instances of napi_get_value_int64 to napi_get_value_int32 now the app is working great 🙂 Happy to open a PR if you want.

@PepsRyuu
Copy link
Owner

Nice job!!

Very interesting discovery. I noticed I'm using a combination of int32 and int64, can't remember why, probably just wasn't thinking when I was playing around with it. 🤔

Do open a PR, I'll give a try on my Intel Mac over the weekend and merge if all is good! Thanks for looking into this!

@apotenza92
Copy link
Author

Can confirm this worked for me too, did a simple find and replace as per @t1m0thyj comment. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants