Skip to content

Commit

Permalink
Print human-readable time
Browse files Browse the repository at this point in the history
  • Loading branch information
jenskutilek committed May 15, 2024
1 parent 3f41605 commit ca1da87
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Favourites.glyphsPlugin/Contents/Resources/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
NSWindowDidResignMainNotification,
NSWindowWillCloseNotification,
)
from datetime import datetime
from GlyphsApp import Glyphs, WINDOW_MENU
from GlyphsApp.plugins import GeneralPlugin
from glyphsFavourites import FavouritesUI, libkey
Expand All @@ -22,6 +23,11 @@
DEBUG = False


def print_time(action: str, timestamp: int) -> None:
t = datetime.fromtimestamp(timestamp).strftime("%I:%M:%S")
print(f"Glyphs {action} at {t}")


class Favourites(GeneralPlugin):
@objc.python_method
def settings(self) -> None:
Expand All @@ -37,7 +43,7 @@ def start(self) -> None:
self.launch_time = int(time())
self.became_active_time = self.launch_time
if DEBUG:
print(f"Glyphs launched at {self.became_active_time}")
print_time("launched", self.became_active_time)

# Initialize the time counter
for key in ("TimeSession", "TimeTotal"):
Expand Down Expand Up @@ -147,13 +153,13 @@ def showWindow_(self, sender) -> None:
def appActivated_(self, info) -> None:
self.became_active_time = int(time())
if DEBUG:
print(f"Glyphs became active at {self.became_active_time}")
print_time("became active", self.became_active_time)

def appDeactivated_(self, info) -> None:
# Save time in seconds
became_inactive_time = int(time())
if DEBUG:
print(f"Glyphs became inactive at {became_inactive_time}")
print_time("became inactive",became_inactive_time)
if self.became_active_time < self.launch_time:
if DEBUG:
print(
Expand Down

0 comments on commit ca1da87

Please sign in to comment.