dock-window-preview icon indicating copy to clipboard operation
dock-window-preview copied to clipboard

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

Open apotenza92 opened this issue 2 years ago • 45 comments

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 avatar Jun 14 '22 08:06 apotenza92

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

apotenza92 avatar Jun 14 '22 08:06 apotenza92

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

PepsRyuu avatar Jun 14 '22 08:06 PepsRyuu

Potentially related: https://github.com/yue/yackage/issues/19

PepsRyuu avatar Jun 14 '22 08:06 PepsRyuu

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 ~ % 

apotenza92 avatar Jun 14 '22 08:06 apotenza92

Same error as #1 in this case.

When you say you had no success with https://github.com/PepsRyuu/dock-window-preview/issues/1#issuecomment-1149583072, can you explain what happened in more detail? Was there an error message? What commands did you use? :)

PepsRyuu avatar Jun 14 '22 08:06 PepsRyuu

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 % 

apotenza92 avatar Jun 14 '22 09:06 apotenza92

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)

PepsRyuu avatar Jun 14 '22 10:06 PepsRyuu

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 % 

apotenza92 avatar Jun 14 '22 10:06 apotenza92

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?

PepsRyuu avatar Jun 14 '22 10:06 PepsRyuu

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.

apotenza92 avatar Jun 14 '22 10:06 apotenza92

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

PepsRyuu avatar Jun 14 '22 11:06 PepsRyuu

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.

apotenza92 avatar Jun 14 '22 11:06 apotenza92

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.

PepsRyuu avatar Jun 14 '22 11:06 PepsRyuu

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 avatar Jun 14 '22 11:06 apotenza92

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..

apotenza92 avatar Jun 14 '22 12:06 apotenza92

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! 😁

PepsRyuu avatar Jun 14 '22 12:06 PepsRyuu

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 avatar Jun 14 '22 12:06 apotenza92

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.

apotenza92 avatar Jun 14 '22 12:06 apotenza92

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 avatar Jun 14 '22 17:06 PepsRyuu

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

PepsRyuu avatar Jun 14 '22 17:06 PepsRyuu

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

PepsRyuu avatar Jun 14 '22 19:06 PepsRyuu

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! 😀

apotenza92 avatar Jun 15 '22 03:06 apotenza92

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 avatar Jun 15 '22 07:06 PepsRyuu

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);
    }
})();

PepsRyuu avatar Jun 15 '22 18:06 PepsRyuu

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.

apotenza92 avatar Jun 18 '22 03:06 apotenza92

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. :)

PepsRyuu avatar Jun 18 '22 07:06 PepsRyuu

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

apotenza92 avatar Jun 18 '22 09:06 apotenza92

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?

PepsRyuu avatar Jun 18 '22 09:06 PepsRyuu

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

apotenza92 avatar Jun 18 '22 10:06 apotenza92

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... 🤔

PepsRyuu avatar Jun 18 '22 10:06 PepsRyuu