lwouis / alt-tab-macos

Windows alt-tab on macOS
https://alt-tab-macos.netlify.app
GNU General Public License v3.0
10.85k stars 326 forks source link

Error loading preferences from JSON file on disk #51

Closed xakraz closed 5 years ago

xakraz commented 5 years ago

Error

When installing the latest version on my workstation, the app does not start.

By CLI, it seems to be an issue with the config file parsing.

"Error loading preferences from JSON file on disk" "Optional contained nil"

Data

➜  ~ cat ~/Library/Preferences/alt-tab-macos.json
{
  "windowDisplayDelay" : "200",
  "cellPadding" : "6",
  "thumbnailMaxHeight" : "0",
  "metaModifierFlag" : "262144",
  "maxScreenUsage" : "0.8",
  "cellBorderWidth" : "2",
  "thumbnailMaxWidth" : "0",
  "highlightColor" : "white",
  "maxThumbnailsPerRow" : "4",
  "fontHeight" : "15",
  "thumbnailQuality" : "4",
  "interItemPadding" : "4",
  "metaKey" : "59",
  "tabKey" : "48",
  "iconSize" : "32",
  "windowPadding" : "20"
}%
➜  ~ cat ~/Library/Preferences/alt-tab-macos-defaults.json
{
  "windowDisplayDelay" : "200",
  "cellPadding" : "6",
  "thumbnailMaxHeight" : "0",
  "metaModifierFlag" : "262144",
  "maxScreenUsage" : "0.8",
  "cellBorderWidth" : "2",
  "thumbnailMaxWidth" : "0",
  "highlightColor" : "white",
  "maxThumbnailsPerRow" : "4",
  "fontHeight" : "15",
  "thumbnailQuality" : "4",
  "interItemPadding" : "4",
  "metaKey" : "59",
  "tabKey" : "48",
  "iconSize" : "32",
  "windowPadding" : "20"
}%

Info

➜  ~ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G103
25 › <key>CFBundleVersion</key>
 26 › <string>1.5.1</string>
lwouis commented 5 years ago

Hey @xakraz, sorry about this issue.

I had some very primitive logic for handling migration. That is: you download a new version of the app, and it tries to detect that your preferences.json file is not an existing file, but a previous version of an existing file. I was just counting the lines and assuming the file will only get bigger (i.e. retrocompatible forever).

However, in 1.6.0, I simplified the preferences a lot in order to be more user friendly. I also added a version key in the file so that detecting older version is clear and no longer a guess.

Anyway, could you please check out the new version? Hopefully it will fix your issue. It also features a new macOS theme, and better preferences!

I will close this ticket in the meanwhile. Of course, please re-open it if you face the issue after booting the new version :)

gingerr commented 5 years ago

I got the same issue and identified 1.4.7 as the last working version. Ive cloned the project and tried to track it down in xcode but iam not familiar with xcode and swift.

But the issue is internationalization and converting a double/float. Ive deleted both json files and let the application generate them with default values. It fails in updateAndValidateFromString at the maxScreenUsage value. It has a default of 0.8 which fails but works if i change the file or the code to work with 0,8.

In my locale the decimal seperator is a , comma instead of . point. It looks like the NumberFormatter explained here could be the solution: https://stackoverflow.com/a/27595925/4767781

Thanks for your awesome alt-tab switcher!

gingerr commented 5 years ago

@lwouis named mention cause i don't know if you get a notification otherwise.

gingerr commented 5 years ago

xakraz is from Paris and France is also using the comma sign as decimal separator.

gingerr commented 5 years ago

By 'it works' i meant it does not crash anymore. But the ui gets not triggered for me. There arent any errors and the output shows: "preActivate" "focusTarget"

Ive tried "maxScreenUsage" : "1" in the json & code defaults and different meta keys but it had no effect.

gingerr commented 5 years ago

llright, the possibly unrelated issue of the ui not triggering happened between version 1.6.1 and 1.7.0.

Ive checked out different versions and always deleted both .json files, changed maxScreenUsage in the code to 1 (workaround for the decimal separator issue) and let it run twice (security settings allowance).

Console output: `1.6.1 "meta down" "meta+tab down" "meta up"

1.7.0 "meta down" "meta up" `

It looks like since 1.7.0 the tab key is somehow not recognized on my system (latest macOS, German locale).

lwouis commented 5 years ago

@gingerr Thanks a lot for the detective work! I checked commits between 1.6.1 and 1.7.0 (semantic-release made this really easy) and noticed the root cause in b6e4826e408847a3c30c2cde7192904012c05c6b:

I switched the tab keyCode from 48 to 58 by accident during a refactor. Because my local JSON file kept 48, I didn't see the breaking change. Thanks a lot for noticing that. There are many broken versions from 1.7.0 to 1.9.3 for new installs (people upgrading like me will not be affected). I will remove these releases from github to avoid people having a bad experience.

I just released 1.9.4 which should work properly. I also worked around the localization issue by replacing 0.8 with 80 (%)

Can you check out that release? Hopefully you have a good experience finally!

gingerr commented 5 years ago

Nice, you are fast! Iam glad i could help a little and am thankful for your application. I was going to attempt a fix myself next but i have zero experience in xcode and swift (java, javascript, intellij guy) so i don't know if i had a chance.

1.9.4 works almost out of the box. Both changes (tab key code) and decimal separator workaround work perfectly. One little issue i noticed is the option meta key (which is the default for fresh installs) does not trigger on my system (no output in the console and nothing happening). But the other meta keys work perfectly. Does the option key trigger for you?

Thanks! Oh, iam having a good experience. Switching between multiple windows is finally possible (including window previews as in windows) without any additional key combinations, thanks to you!

lwouis commented 5 years ago

Oh wow you are right! I use control so didn't notice. I remember testing all macro keys previously though... I will check what happened. Maybe another mixup with the keyCode? Man I don't understand why Apple doesn't provide an enum for this. Something like 20 years and people still hardcode ints their apps or add their own enums like I did because Apple didn't bother making an enum.

i have zero experience in xcode and swift (java, javascript, intellij guy) so i don't know if i had a chance

I have a similar background! One of my goal for this project is to minimize dependency on XCode as much as possible. I'm using AppCode (IntelliJ for Swift; for some reason there is no plugin for Ultimate here) to work on this. I made no use of Interface Builder for UIs (which probably explains why I'm struggling so much to make the Preferences panel look good).

I discovered Swift with this project. I think the language is utter garbage, especially its evolution and stewardship. Fun fact: I started this project as an Electron project because electron has an API to capture other windows. However after my POC was working I started bumping into limitations like having to use Applescript to give focus to another window. In the end I got hard stuck on some features that were only available through the old C APIs. I could have gotten Electron to call some compiled code but at this point I thought ok let me write everything in Swift using the objc and C bridges. This way it's one language, I get max performance, access to all APIs, and the UI is native looking.

So In short, don't get intimidated. I really pushed hard to keep the code here simple and small. I'm confident you would be able to make changes fast if you wanted to add stuff ;)

lwouis commented 5 years ago

Update: I fixed the issue with option. It was from the same commit. I refactored the keyCodes and made many mistakes unfortunately. If it was a webapp I would add e2e tests to prevent regressions like these, but to be honest testing something as integrated and nuance as this background process app is something I have little hopes on doing one day 😅

Check out the latest release if you wanna use the option key.

gingerr commented 5 years ago

Agree, an keycode enum import of some sort would have been nice.

Between our messages i was already on jetbrains to check if they have something for macos development so i dont have to stumble around in xcode 😄 and began to download AppCode.

Nice coincidence with our backgrounds! Iam an angular/react in the frontend and java in the backend guy. Iam happy and sad at the same time you tried web technologies first but had to change to native development bringing us the lowest memory and cpu usage 🚀

I had no chance to try electron yet, curious about that one. Thanks for sharing your findings on this trip and encouragement, appreciate it!

I see you also fixed the option issue aswell. Yeah e2e tests would be a little overkill 😃 but since you went opensource you dont have to do and test everything by yourself. Thanks! 👍

lwouis commented 5 years ago

began to download AppCode

I'm not intending on buying it for this lone project, so I had to resort to some measures that you may fine useful in a few weeks 🌝

gingerr commented 5 years ago

Oh i had to get to know this measures in my past adventures aswell 😄 but are luckily nowadays provided with an jetbrains 'all products license' by my employer. For spare time projects i would also not buy it. I think you can get an license for opensource projects if i remember correctly.

After googling: Yes you can, could be an option for you, iam not sure about the limitations / restrictions: https://www.jetbrains.com/community/opensource/

lwouis commented 5 years ago

Wow I forgot they had this program! I'll apply, thanks!