mirror of
https://github.com/servo/servo.git
synced 2025-06-22 08:08:59 +01:00
Add Desktop Notifications for Long builds. Supported for Linux & Windows platforms.
Incorporate suggestions from Code review. Change function name to lower case.
This commit is contained in:
parent
045831748e
commit
73832175f4
1 changed files with 52 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import os.path as path
|
import os.path as path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -16,6 +17,48 @@ from servo.command_base import CommandBase, cd
|
||||||
def is_headless_build():
|
def is_headless_build():
|
||||||
return int(os.getenv('SERVO_HEADLESS', 0)) == 1
|
return int(os.getenv('SERVO_HEADLESS', 0)) == 1
|
||||||
|
|
||||||
|
# Function to generate desktop notification once build is completed & limit exceeded!
|
||||||
|
def notify(elapsed):
|
||||||
|
if elapsed < 300:
|
||||||
|
return
|
||||||
|
|
||||||
|
if sys.platform.startswith('linux'):
|
||||||
|
try:
|
||||||
|
import dbus
|
||||||
|
bus = dbus.SessionBus()
|
||||||
|
notify_obj = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
|
||||||
|
method = notify_obj.get_dbus_method('Notify', 'org.freedesktop.Notifications')
|
||||||
|
method('Servo Build System', 0, '', ' Servo build complete!', '', [], [], -1)
|
||||||
|
except:
|
||||||
|
print("[Warning] Could not generate notification! Please make sure that the python dbus module is installed!")
|
||||||
|
|
||||||
|
elif sys.platform.startswith('win'):
|
||||||
|
try:
|
||||||
|
from ctypes import Structure, windll, POINTER, sizeof
|
||||||
|
from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT
|
||||||
|
class FLASHWINDOW(Structure):
|
||||||
|
_fields_ = [("cbSize", UINT),
|
||||||
|
("hwnd", HANDLE),
|
||||||
|
("dwFlags", DWORD),
|
||||||
|
("uCount", UINT),
|
||||||
|
("dwTimeout", DWORD)]
|
||||||
|
FlashWindowExProto = WINFUNCTYPE(BOOL, POINTER(FLASHWINDOW))
|
||||||
|
FlashWindowEx = FlashWindowExProto(("FlashWindowEx", windll.user32))
|
||||||
|
FLASHW_CAPTION = 0x01
|
||||||
|
FLASHW_TRAY = 0x02
|
||||||
|
FLASHW_TIMERNOFG = 0x0C
|
||||||
|
params = FLASHWINDOW(sizeof(FLASHWINDOW),
|
||||||
|
windll.kernel32.GetConsoleWindow(),
|
||||||
|
FLASHW_CAPTION | FLASHW_TRAY | FLASHW_TIMERNOFG, 3, 0)
|
||||||
|
FlashWindowEx(params)
|
||||||
|
except:
|
||||||
|
print("[Warning] Could not generate notification! Please make sure that the required libraries are installed!")
|
||||||
|
|
||||||
|
elif sys.platform.startswith('darwin'):
|
||||||
|
# Notification code for Darwin here! For the time being printing simple msg
|
||||||
|
print("[Warning] : Darwin System! Notifications not supported currently!")
|
||||||
|
|
||||||
|
|
||||||
@CommandProvider
|
@CommandProvider
|
||||||
class MachCommands(CommandBase):
|
class MachCommands(CommandBase):
|
||||||
@Command('build',
|
@Command('build',
|
||||||
|
@ -102,6 +145,9 @@ class MachCommands(CommandBase):
|
||||||
env=env, cwd=self.servo_crate())
|
env=env, cwd=self.servo_crate())
|
||||||
elapsed = time() - build_start
|
elapsed = time() - build_start
|
||||||
|
|
||||||
|
# Generate Desktop Notification if elapsed-time > some threshold value
|
||||||
|
notify(elapsed)
|
||||||
|
|
||||||
print("Build completed in %0.2fs" % elapsed)
|
print("Build completed in %0.2fs" % elapsed)
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
@ -135,6 +181,9 @@ class MachCommands(CommandBase):
|
||||||
env=self.build_env())
|
env=self.build_env())
|
||||||
elapsed = time() - build_start
|
elapsed = time() - build_start
|
||||||
|
|
||||||
|
# Generate Desktop Notification if elapsed-time > some threshold value
|
||||||
|
notify(elapsed)
|
||||||
|
|
||||||
print("CEF build completed in %0.2fs" % elapsed)
|
print("CEF build completed in %0.2fs" % elapsed)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
@ -170,6 +219,9 @@ class MachCommands(CommandBase):
|
||||||
ret = subprocess.call(["cargo", "build"] + opts, env=env)
|
ret = subprocess.call(["cargo", "build"] + opts, env=env)
|
||||||
elapsed = time() - build_start
|
elapsed = time() - build_start
|
||||||
|
|
||||||
|
# Generate Desktop Notification if elapsed-time > some threshold value
|
||||||
|
notify(elapsed)
|
||||||
|
|
||||||
print("Gonk build completed in %0.2fs" % elapsed)
|
print("Gonk build completed in %0.2fs" % elapsed)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue