ActivityWatch / activitywatch

The best free and open-source automated time tracker. Cross-platform, extensible, privacy-focused.
https://activitywatch.net/
Mozilla Public License 2.0
11.98k stars 544 forks source link

"Module aw-watcher-window quit unexpectedly." #918

Closed schackbrian2012 closed 1 year ago

schackbrian2012 commented 1 year ago

Describe the bug

I use the ActivityWatch app to track the time that I spend on the computer. I am running v0.12.2 which is the latest version. When I restart the computer, it displays an error message. The error message says, "Module aw-watcher-window quit unexpectedly." It has three buttons: Hide Details..., Cancel, and Restart. The details pane says the following:

2023-07-03 12:33:23 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
2023-07-03 12:33:24 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
2023-07-03 12:33:24 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:436)

I searched in the documentation, but I did not find this error message. I asked about this issue on the Ask Different website from the Stack Exchange network, and the comments referred me to contact the developer. I found a related issue on GitHub "AW crashed unexpectedly after BSOD". That issue occurs on Windows, and my issue occurs on macOS. I tried the solution for that issue –– deleting the Application Support folder –– but that did not work.

How can I prevent this error from occurring? Please find attached a screenshot of the error message.

To Reproduce

Restart the computer.

Expected behavior

No error message.

Documentation

Please find attached a screenshot of the error message. The log file at ~/Library/Logs/activitywatch/aw-watcher-window/aw-watcher-window_2023-07-11T10-47-27.log says:

2023-07-11 10:47:27 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
2023-07-11 10:47:28 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
2023-07-11 10:47:28 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:436)

Additional context

github-actions[bot] commented 1 year ago

Hi there! As you're new to this repo, please make sure you've used an appropriate issue template and searched for duplicates (it helps us focus on actual development!). We'd also like to suggest that you read our contribution guidelines and our code of conduct. Thanks a bunch for opening your first issue! 🙏

BelKed commented 1 year ago

I can also confirm that this problem occurs on my Mac, but only when my computer crashes (usually when it runs out of RAM because 8 GB is not enough).

The cause is probably the same as in the Windows issue — ActivityWatch doesn't quit properly, and on reboot when the application starts it can't because the instance of ActivityWatch from before the reboot is still/already running.

If it happens next time, you could manually force quit the running processes of ActivityWatch in the Activity Monitor app, and launch it normally from the Applications folder.

Screenshot 2023-07-12 at 15 21 33
schackbrian2012 commented 1 year ago

@BelKed Thank you for your interest in helping with this issue. I checked under Apple menu –> About This Mac, and I have 16 GB of memory. You said, "[T]he instance of ActivityWatch from before the reboot is still/already running." I don't understand this. I thought that rebooting would quit everything. How could ActivityWatch still be running? I tried following your instructions. I force quit ActivityWatch in Activity Monitor. Then I relaunched ActivityWatch. Unfortunately, the Activity view shows, "No data." I can wait to see whether the data takes some time to accumulate.

BelKed commented 1 year ago

I thought that rebooting would quit everything.

If you leave the Reopen windows when logging back in checkbox checked, the system will save every single application that is currently running so that it can shut itself down. Then, when you reboot, it will reopen windows that were open before you rebooted. At least, that's how I think it works :)

Screenshot

ActivityWatch is probably saved as the application that was running before you rebooted. And if ActivityWatch is set as the application to open on login (which is the default, if I'm right), this would be a second instance of ActivityWatch running. When it tries to launch, it crashes with Module aw-watcher-window quit unexpectedly.

So could you try restarting with the Reopen windows when logging back in checkbox unchecked?

Screenshot


Unfortunately, the Activity view shows, "No data."

Then, please check if the ActivityWatch modules are running — a checkmark will appear in front of the module name if it's running. I'm using aw-server-rust as the ActivityWatch server. If you're using the default Python server, you should have a checkmark in front of aw-server.

Screenshot

BelKed commented 1 year ago

Thinking deeply about it now, maybe you have ActivityWatch twice in your Login Items, maybe as two separate versions or something...

Screenshot

schackbrian2012 commented 1 year ago

@BelKed I have been traveling overseas without Internet service, so I could not reply to your message earlier. I will try the troubleshooting ideas that you suggested.

tomzx commented 1 year ago

Running aw-watcher-window on BigSur 11.7.8 results in the following output:

2023-07-25 13:07:51 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
usage: aw-watcher-window [-h] [--host HOST] [--port PORT] [--testing] [--exclude-title] [--verbose] [--poll-time POLL_TIME] [--strategy {jxa,applescript,swift}]
aw-watcher-window: error: unrecognized arguments: -B -S -E -s -c from multiprocessing.resource_tracker import main;main(5)
usage: aw-watcher-window [-h] [--host HOST] [--port PORT] [--testing] [--exclude-title] [--verbose] [--poll-time POLL_TIME] [--strategy {jxa,applescript,swift}]
aw-watcher-window: error: unrecognized arguments: --multiprocessing-fork tracker_fd=6 pipe_handle=8
2023-07-25 13:07:52 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
dyld: Library not loaded: /usr/lib/swift/libswift_Concurrency.dylib
  Referenced from: /Applications/ActivityWatch.app/Contents/MacOS/aw_watcher_window/aw-watcher-window-macos
  Reason: image not found
2023-07-25 13:07:52 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:436)

The file /usr/lib/swift/libswift_Concurrency.dylib does not exist. After a bit of search, it appears that libswift_Concurrency.dylib is available with XCode 13 and/or MacOS 12.

BelKed commented 1 year ago

@tomzx There is already an open issue for the problem you mention :)

schackbrian2012 commented 1 year ago

Rebooting: Using Command-Tab, Command-W, and Command-Q, I closed the open windows and applications. Then under Apple menu –> Restart..., I unchecked "Reopen windows when logging back in," and clicked the Restart button.

aw-server: Under ActivityWatch menu –> Modules, the aw-server menu item is checked.

Login Items: Under Apple menu –> System Preferences... –> Users & Groups –> Login Items, I removed and re-added ActivityWatch from the Applications folder.

@BelKed Unfortunately, I am still getting the error message and no data.

BelKed commented 1 year ago

Okay, I can think of one more thing. (No idea why I didn't start with that...)

Could you please try to run the aw-watcher-window from the Terminal using the following command?

/Applications/ActivityWatch.app/Contents/MacOS/aw-watcher-window

This should tell us exactly what is causing the problem.

And then please restart your computer and try to run it again from Terminal after the error message pops up :)

schackbrian2012 commented 1 year ago

@BelKed I ran aw-watcher-window from the Terminal as you suggested, and I got the following error:

% /Applications/ActivityWatch.app/Contents/MacOS/aw-watcher-window
2023-08-05 17:04:23 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
usage: aw-watcher-window [-h] [--host HOST] [--port PORT] [--testing]
                         [--exclude-title] [--verbose] [--poll-time POLL_TIME]
                         [--strategy {jxa,applescript,swift}]
aw-watcher-window: error: unrecognized arguments: --multiprocessing-fork tracker_fd=6 pipe_handle=8
usage: aw-watcher-window [-h] [--host HOST] [--port PORT] [--testing]
                         [--exclude-title] [--verbose] [--poll-time POLL_TIME]
                         [--strategy {jxa,applescript,swift}]
aw-watcher-window: error: unrecognized arguments: -B -S -E -s -c from multiprocessing.resource_tracker import main;main(5)
2023-08-05 17:04:24 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
dyld: Library not loaded: /usr/lib/swift/libswift_Concurrency.dylib
  Referenced from: /Applications/ActivityWatch.app/Contents/MacOS/aw_watcher_window/aw-watcher-window-macos
  Reason: image not found
2023-08-05 17:04:24 [INFO ]: Connection to aw-server established by aw-watcher-window  (aw_client.client:436)
BelKed commented 1 year ago

Okay, so the problem is the same as in https://github.com/ActivityWatch/activitywatch/issues/801. Could you please close this issue, since it's a duplicate of the mentioned one? :)

schackbrian2012 commented 1 year ago

As advised by @BelKed, I am closing this issue as a duplicate of "dyld: Library not loaded: /usr/lib/swift/libswift_Concurrency.dylib on v0.12.1 for macOS 11.6."

doranmartinez commented 1 year ago

@BelKed I ended up getting the same message from the beginning of this thread. I'm not sure if I am having the same problem as above though.

I am following the steps in Installing from source Attempting to run /Applications/ActivityWatch.app/Contents/MacOS/aw-watcher-window doesn't work for me, I end up getting: No such file or directory

Running: ~/dev/activitywatch $ aw-watcher-window yields:

2023-08-11 23:09:56 [INFO ]: aw-watcher-window started  (aw_watcher_window.main:62)
2023-08-11 23:09:57 [INFO ]: Using swift strategy, calling out to swift binary  (aw_watcher_window.main:67)
2023-08-11 23:09:57 [WARNING]: Not connected to server, 0 requests in queue  (aw_client.client:502)
2023-08-11 23:09:57 [ERROR]: Unhandled exception  (root:50)
Traceback (most recent call last):
  File "/Users/doranmartinez/dev/activitywatch/venv/bin/aw-watcher-window", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/doranmartinez/dev/activitywatch/aw-watcher-window/aw_watcher_window/main.py", line 73, in main
    p = subprocess.Popen(
        ^^^^^^^^^^^^^^^^^
  File "/Users/doranmartinez/.pyenv/versions/3.11.4/lib/python3.11/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Users/doranmartinez/.pyenv/versions/3.11.4/lib/python3.11/subprocess.py", line 1950, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/doranmartinez/dev/activitywatch/aw-watcher-window/aw_watcher_window/aw-watcher-window-macos'

I can't build the aw-watcher-window:

$ make build
...
Installing the current project: aw-watcher-window (0.2.0)
# if macOS, build swift
if [ "Darwin" = "Darwin" ]; then \
        make build-swift; \
    fi
swiftc aw_watcher_window/macos.swift -o aw_watcher_window/aw-watcher-window-macos
aw_watcher_window/macos.swift:192:53: error: 'upload(for:from:delegate:)' is only available in macOS 12.0 or newer
    let (_, response) = try await URLSession.shared.upload(for: urlRequest, from: payload)
                                                    ^
aw_watcher_window/macos.swift:192:53: note: add 'if #available' version check
    let (_, response) = try await URLSession.shared.upload(for: urlRequest, from: payload)
                                                    ^
aw_watcher_window/macos.swift:183:6: note: add @available attribute to enclosing global function
func createBucket() {
     ^
aw_watcher_window/macos.swift:258:51: error: 'upload(for:from:delegate:)' is only available in macOS 12.0 or newer
  let (_, response) = try await URLSession.shared.upload(for: urlRequest, from: payload)
                                                  ^
aw_watcher_window/macos.swift:258:51: note: add 'if #available' version check
  let (_, response) = try await URLSession.shared.upload(for: urlRequest, from: payload)
                                                  ^
aw_watcher_window/macos.swift:250:6: note: add @available attribute to enclosing global function
func sendHeartbeatSingle(_ heartbeat: Heartbeat, pulsetime: Double) async throws {
     ^
aw_watcher_window/macos.swift:295:24: error: 'now' is only available in macOS 12 or newer
    let nowTime = Date.now
                       ^
aw_watcher_window/macos.swift:295:24: note: add 'if #available' version check
    let nowTime = Date.now
                       ^
aw_watcher_window/macos.swift:279:8: note: add @available attribute to enclosing instance method
  func windowTitleChanged(
       ^
aw_watcher_window/macos.swift:267:7: note: add @available attribute to enclosing class
class MainThing {
      ^
aw_watcher_window/macos.swift:321:76: warning: left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used
            error("tab title diff: \(tabTitle), window title: \(data.title ?? "")")
                                                                ~~~~~~~~~~ ^~~~~

aw_watcher_window/macos.swift:340:74: warning: left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used
          error("tab title diff: \(tabTitle), window title: \(data.title ?? "")")
                                                              ~~~~~~~~~~ ^~~~~

make[2]: *** [aw_watcher_window/aw-watcher-window-macos] Error 1
make[1]: *** [build] Error 2
make: *** [build] Error 2

I can't upgrade my MacOS due to financial constraints of buying a new machine that can support it, I'm running a mid 2014, one of the last MacBooks that doesn't qualify for V12 😭

BelKed commented 1 year ago

You are facing exactly the same issue :)

The easiest workaround I can think of is to install an older version of ActivityWatch. Or install the latest version and use the aw-watcher-window from the older version.

Anyways, if you have any other questions regarding this issue, please write them here: https://github.com/ActivityWatch/activitywatch/issues/801