Git Product home page Git Product logo

unity-wakatime's Introduction

unity-wakatime

A WakaTime plugin for Unity.

Screenshot

About

Existing solutions didn't work for me (https://github.com/bengsfort/WakaTime-Unity is obsolete and https://github.com/josec89/wakatime-unity requires Python), so I decided to implement my own variant.

Installation using the Unity Package Manager (Unity 2018.1+)

The Unity Package Manager (UPM) is a new method to manage external packages. It keeps package contents separate from your main project files.

  1. Modify your project's Packages/manifest.json file adding this line:

    "com.vladfaust.unitywakatime": "https://github.com/vladfaust/unity-wakatime.git#package"

    Make sure it's still a valid JSON file. For example:

    {
        "dependencies": {
            "com.unity.ads": "2.0.8",
            "com.vladfaust.unitywakatime": "https://github.com/vladfaust/unity-wakatime.git#package"
        }
    }
  2. To update the package you need to delete the package lock entry in the lock section in Packages/manifest.json. The entry to delete could look like this:

    "com.vladfaust.unitywakatime": {
      "hash": "31fe84232fc9f9c6e9606dc9e5a285886a94f26b",
      "revision": "package"
    }

Installation (all other Unity versions)

If you don't use the Unity Package Manager, you may copy the Editor folder from inside Assets/com.vladfaust.unitywakatime into your project's Assets folder.

Setup

  1. Run the Unity editor, go to Window/WakaTime, and insert your API key (grab one from https://wakatime.com/settings/account)
  2. Press Save Preferences
  3. Check if "Unity" editor appears at https://wakatime.com/api/v1/users/current/user_agents (may be a bit delayed)
  4. Enjoy!

Usage

The plugin will automatically send heartbeats to WakaTime after following events:

  • DidReloadScripts
  • EditorApplication.playModeStateChanged
  • EditorApplication.contextualPropertyMenu
  • EditorApplication.hierarchyWindowChanged
  • EditorSceneManager.sceneSaved
  • EditorSceneManager.sceneOpened
  • EditorSceneManager.sceneClosing
  • EditorSceneManager.newSceneCreated

Development

Use the manual installation method, so the changes you make are immediately reflected in the editor. But please keep the repository sane, omitting any unnecessary files. When added a new file, move its .meta counterpart generated by Unity into the /CI/Meta folder.

Become Patron

unity-wakatime's People

Contributors

alanhamlett avatar hermesiss avatar kshaibani avatar nifukivisk avatar vladfaust avatar zeh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity-wakatime's Issues

<WakaTime> Got response Error

This is what i get

<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx</center>
</body>
</html>

instead of this

<WakaTime> Got response
{"data":{"id":"***************************************"}}

Native Collection has not been disposed, resulting in a memory leak.

This happened in 2021.1. Every time I press "Play" button, they appear in console. I used com.unity.jobs and caught these:

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator)
UnityEngine.Networking.UploadHandlerRaw:.ctor(Byte[])
WakaTime.Plugin:SendHeartbeat(Boolean) (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:145)
WakaTime.Plugin:OnSceneClosing(Scene, Boolean) (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:205)
UnityEditor.SceneManagement.EditorSceneManager:Internal_SceneClosing(Scene, Boolean)

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator)
UnityEngine.Networking.UploadHandlerRaw:.ctor(Byte[])
WakaTime.Plugin:SendHeartbeat(Boolean) (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:145)
WakaTime.Plugin:Initialize() (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:62)
WakaTime.Plugin:OnScriptReload() (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:181)

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator)
UnityEngine.Networking.UploadHandlerRaw:.ctor(Byte[])
WakaTime.Plugin:SendHeartbeat(Boolean) (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:145)
WakaTime.Plugin:OnPlaymodeStateChanged(PlayModeStateChange) (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:185)
UnityEditor.EditorApplication:Internal_PlayModeStateChanged(PlayModeStateChange)
UnityEditor.EditorApplication:set_isPlaying(Boolean)
Unity.Entities.Editor.LiveLinkToolbar:TogglePlaying() (at Library\PackageCache\[email protected]\Unity.Entities.Editor\LiveLink\LiveLinkToolbar.cs:94)
Unity.Entities.Editor.LiveLinkToolbar:DrawPlaybar(CommandExecuteContext) (at Library\PackageCache\[email protected]\Unity.Entities.Editor\LiveLink\LiveLinkToolbar.cs:60)
UnityEditor.CommandService:ExecuteCommand(String, CommandHint, Object[])
UnityEditor.CommandService:Execute(String, CommandHint, Object[])
UnityEditor.ModeService:Execute(String, CommandHint, Object[])
UnityEditor.ModeService:Execute(String, Object[])
UnityEditor.Toolbars.PlayModeButtons:OverrideGUIHandler()
UnityEngine.UIElements.IMGUIContainer:DoOnGUI(Event, Matrix4x4, Rect, Boolean, Rect, Action, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Matrix4x4, Rect, Action, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Action, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Boolean)
UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUIRaw(EventBase, Boolean, Boolean)
UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUI(EventBase, Boolean, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleEvent(EventBase)
UnityEngine.UIElements.CallbackEventHandler:HandleEventAtTargetPhase(EventBase)
UnityEngine.UIElements.MouseCaptureDispatchingStrategy:DispatchEvent(EventBase, IPanel)
UnityEngine.UIElements.EventDispatcher:ApplyDispatchingStrategies(EventBase, IPanel, Boolean)
UnityEngine.UIElements.EventDispatcher:ProcessEvent(EventBase, IPanel)
UnityEngine.UIElements.EventDispatcher:ProcessEventQueue()
UnityEngine.UIElements.EventDispatcher:OpenGate()
UnityEngine.UIElements.EventDispatcherGate:Dispose()
UnityEngine.UIElements.EventDispatcher:ProcessEvent(EventBase, IPanel)
UnityEngine.UIElements.EventDispatcher:Dispatch(EventBase, IPanel, DispatchMode)
UnityEngine.UIElements.BaseVisualElementPanel:SendEvent(EventBase, DispatchMode)
UnityEngine.UIElements.UIElementsUtility:DoDispatch(BaseVisualElementPanel)
UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent(Int32, IntPtr, Boolean&)
UnityEngine.UIElements.UIEventRegistration:ProcessEvent(Int32, IntPtr)
UnityEngine.UIElements.<>c:<.cctor>b__1_2(Int32, IntPtr)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Handle HTTP status codes

I have an editor component that actively updates while selected, causing very often heartbeats. After a few seconds System.ArgumentException: JSON parse error: Invalid value. starts to appear. Server responses with

<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx</center>
</body>
</html>

Looks like we need to check for response type and react to errors respectively. Like with temporal timeout for 405 and consider other reactions

Alternatively, in case of 405, we can increase Plugin.HEARTBEAT_COOLDOWN

Can implement after understanding Wakatime server responses or hints from @wakatime members

Periodical heartbeats

Improve the code so it sends heartbeats every N seconds in the background? I'm not extra good at WakaTime philosophy and don't know whether is it needed or not...

ArgumentException: JSON parse error: Invalid value.

Full stacktrace:

ArgumentException: JSON parse error: Invalid value.
UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at C:/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:50)
UnityEngine.JsonUtility.FromJson[T] (System.String json) (at C:/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:33)
WakaTime.Plugin+<>c__DisplayClass21_0.<SendHeartbeat>b__0 (UnityEngine.AsyncOperation operation) (at Library/PackageCache/com.vladfaust.unitywakatime@b8a1d9f726608a3517fade7d045c7c629a57c302/Editor/Plugin.cs:157)
UnityEngine.AsyncOperation.InvokeCompletionEvent () (at C:/buildslave/unity/build/Runtime/Export/AsyncOperation.cs:21)

It spams like crazy when I run the game, but I've seen the same exception in edit mode too. (but from a different event, I'm guessing)

Unity 2018.3.7f1

Are you still there??

@vladfaust Your handling of this repository has been pretty infuriating. You haven't made any commits to this repo nor responded to any issues for at least 13 months, despite 4 open issues from the community since 2018, and 4 open Pull Requests since 2019, including one from me. Is it really too much to ask for you to glance at this repo and merge a PR to remove some compiler warnings? You've actually built a pretty handy Wakatime integration here, what with the Unity Package Manager support and removal of Python as a dependency. But good lord, the constant Console warnings from this package when reimporting assets in Unity, mixed with the bugs reported by others, mixed with your laughable project maintenance, has completely soured my taste for this tool, and I have uninstalled it from all of my Unity projects. For a maintainer of multiple other high-starred repos, and for someone with a link to their Patreon account in the README, I would have expected better.

Simplified installation instructions

In newer versions of Unity, you can directly add packages from a git url:

image

I entered in https://github.com/vladfaust/unity-wakatime.git#package like the README suggests and it seems to have worked.

[Suggestion] Work as a Unity Package (using the Unity Package Manager)

Unity is moving towards a "package" architecture with UPM, the Unity Package Manager. Now, features can be "installed" in projects and be managed externally, as packages, without polluting the game's code base. While this is on early days, the intention is for this to work similarly to NPM packages: that is, you should be able to install third-party dependencies at will. Unity 2018.1 is the first one to feature UPM.

WakaTime support is an ideal target for that, in my opinion. Pasting WakaTime-specific code into a game codebase just so you can get stats seems kind of icky.

Here's an introduction to the changes:
https://blogs.unity3d.com/2018/05/04/project-management-is-evolving-unity-package-manager-overview/
https://docs.unity3d.com/Packages/[email protected]/manual/index.html
https://forum.unity.com/forums/package-manager.150/

Currently, only official (Unity-created) packages are allowed, while they're moving official Unity features into packages. However, the intention is to support packages by simply "installing" them from a Git URL in the future.

In the meantime, we can "install" packages by copying them locally and referring to them by their relative path location. They would be out of the project's folder.

Here's instructions on how to do that:
https://gist.github.com/LotteMakesStuff/6e02e0ea303030517a071a1c81eb016e

This should serve as a great preparation for a Git UPM package for WakaTime.

TL;DR:

In the future, developers will be able to use WakaTime inside Unity by just pasting one line of code into their manifest.json, rather than downloading scripts and placing them inside the project. Making this available should probably be a priority for WakaTime Unity plugin maintainers.

Plan

Since this a "pure" extension that is 100% based on C#, I can help with that with PRs in case it's not already in the roadmap. My plan is this:

  1. Document how to install locally, but on a separate folder, UPM style (since this already works). It will requires some changes to the codebase (adding a package.json).
  2. Document how to install using a Git URL, once that feature is available. It will probably require changes to the codebase structure, depending on whether this upcoming Git support will be able to target a folder or not.

Let me know if this plan is OK or otherwise if you're already working on it.

Broken on Linux. Network is unreachable.

My unity editor 2018.2.16f1 on Fedora 29 (kernel version 4.18.16-300) throws this warning after having set the api key in Wakatime preferences. It then fails to log my time.

<WakaTime> Initializing...
<WakaTime> Sending heartbeat...
<WakaTime> Network is unreachable. Consider disabling completely if you're working offline

Perhaps this is an issue only related to Linux, not tested on Windows or Mac.

Disable logs

Hi.

How do I disable the constant heartbeat logging? It gets in the way of my actual development.

logs

Thanks

Failed to fetch versions information

Installed by first choice
Working fine, but console log error while opening package manager:

Error with package details: Failed to fetch versions information:
  404 Not Found: com.vladfaust.unitywakatime
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

image

Heartbeats Spamming

I am on using Unity 2019.1.2f1. This plugin sends many requests.

Screenshots

image

2019-10-25_06-11-13

Also, when spamming, the API returns 429 Too Many Requests, so JSON parsing may fail.

ArgumentException: JSON parse error: Invalid value.
UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at C:/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:42)
UnityEngine.JsonUtility.FromJson[T] (System.String json) (at C:/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:30)
WakaTime.Plugin+<>c__DisplayClass21_0.<SendHeartbeat>b__0 (UnityEngine.AsyncOperation operation) (at Library/PackageCache/com.vladfaust.unitywakatime@b8a1d9f726608a3517fade7d045c7c629a57c302/Editor/Plugin.cs:157)
UnityEngine.AsyncOperation.InvokeCompletionEvent () (at C:/buildslave/unity/build/Runtime/Export/Scripting/AsyncOperation.cs:21)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.