Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13,544 changes: 0 additions & 13,544 deletions power_time_tracking_electron/package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion power_time_tracking_electron/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "PowerTimeTracking",
"productName": "PowerTimeTracking",
"version": "0.9.6",
"version": "0.9.7",
"description": "An app to improve productivity by blocking apps that waste time and showing where time goes.",
"main": "src/index.js",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions power_time_tracking_electron/package_intel_and_arm
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
npm run package-arm
sleep 2
pkgbuild --scripts src/scripts/ --component out/PowerTimeTracking-darwin-arm64/PowerTimeTracking.app/ --install-location /Applications/ --sign "Developer ID Installer: Clearpoint Management LLC (6KK9M46VM2)" out/PowerTimeTracking-arm-0.9.6.pkg
pkgbuild --scripts src/scripts/ --component out/PowerTimeTracking-darwin-arm64/PowerTimeTracking.app/ --install-location /Applications/ --sign "Developer ID Installer: Clearpoint Management LLC (6KK9M46VM2)" out/PowerTimeTracking-arm-0.9.7.pkg
spctl -a -vv out/PowerTimeTracking-darwin-arm64/PowerTimeTracking.app/
xcrun stapler validate out/PowerTimeTracking-darwin-arm64/PowerTimeTracking.app/
sleep 2
xcrun notarytool submit out/PowerTimeTracking-arm-0.9.6.pkg --wait --keychain-profile "appleid.apple.com (shoryamalani@icloud.com)"
xcrun notarytool submit out/PowerTimeTracking-arm-0.9.7.pkg --wait --keychain-profile "appleid.apple.com (shoryamalani@icloud.com)"
sleep 2
xcrun stapler staple out/PowerTimeTracking-arm-0.9.6.pkg
xcrun stapler staple out/PowerTimeTracking-arm-0.9.7.pkg

npm run package-int
spctl -a -vv out/PowerTimeTracking-darwin-x64/PowerTimeTracking.app/
xcrun stapler validate out/PowerTimeTracking-darwin-x64/PowerTimeTracking.app/
sleep 2
pwd
pkgbuild --scripts src/scripts/ --component out/PowerTimeTracking-darwin-x64/PowerTimeTracking.app/ --install-location /Applications/ --sign "Developer ID Installer: Clearpoint Management LLC (6KK9M46VM2)" out/PowerTimeTracking-intel-0.9.6.pkg
pkgbuild --scripts src/scripts/ --component out/PowerTimeTracking-darwin-x64/PowerTimeTracking.app/ --install-location /Applications/ --sign "Developer ID Installer: Clearpoint Management LLC (6KK9M46VM2)" out/PowerTimeTracking-intel-0.9.7.pkg
pwd
sleep 2
xcrun notarytool submit out/PowerTimeTracking-intel-0.9.6.pkg --wait --keychain-profile "appleid.apple.com (shoryamalani@icloud.com)"
xcrun notarytool submit out/PowerTimeTracking-intel-0.9.7.pkg --wait --keychain-profile "appleid.apple.com (shoryamalani@icloud.com)"
sleep 2
xcrun stapler staple out/PowerTimeTracking-intel-0.9.6.pkg
xcrun stapler staple out/PowerTimeTracking-intel-0.9.7.pkg
55 changes: 8 additions & 47 deletions power_time_tracking_electron/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,6 @@ var path = require('path')
// const { app, BrowserWindow } = require('electron');
// const path = require('path');

// // Handle creating/removing shortcuts on Windows when installing/uninstalling.
// if (require('electron-squirrel-startup')) {
// // eslint-disable-line global-require
// app.quit();
// }

// const createWindow = () => {
// // Create the browser window.
// const mainWindow = new BrowserWindow({
// width: 800,
// height: 600,
// });

// // and load the index.html of the app.
// mainWindow.loadFile(path.join(__dirname, 'index.html'));

// // Open the DevTools.
// mainWindow.webContents.openDevTools();
// };

// // This method will be called when Electron has finished
// // initialization and is ready to create browser windows.
// // Some APIs can only be used after this event occurs.
// app.on('ready', createWindow);

// // Quit when all windows are closed, except on macOS. There, it's common
// // for applications and their menu bar to stay active until the user quits
// // explicitly with Cmd + Q.
// app.on('window-all-closed', () => {
// if (process.platform !== 'darwin') {
// app.quit();
// }
// });

// app.on('activate', () => {
// // On OS X it's common to re-create a window in the app when the
// // dock icon is clicked and there are no other windows open.
// if (BrowserWindow.getAllWindows().length === 0) {
// createWindow();
// }
// });

// // In this file you can include the rest of your app's specific main process
// // code. You can also put them in separate files and import them here.
const {BrowserWindow} = require('electron');
var VERSION = app.getVersion();
// const {PythonShell} = require('python-shell');
Expand All @@ -75,7 +31,7 @@ let tray = null
app.whenReady().then(() => {
tray = new Tray(resolvePath('assets/tray.png'))
setUpTray();
setInterval(keepUpTray,3000);
setInterval(keepUpTray,1000);
})
async function keepUpTray(){
setUpTray();
Expand Down Expand Up @@ -118,8 +74,13 @@ async function setUpTray() {
if(response.ok){
const data = await response.json();
if(data.logger_running_status == true){
tray.setTitle('Logging')
logging = true;
if(data.in_focus_mode.status == true){
tray.setTitle(data.in_focus_mode['Name'] + ' ' + data.in_focus_mode['Time Remaining'])
logging = true;
}else{
tray.setTitle('Logging')
logging = true;
}
}else{
tray.setTitle('Not Logging')
logging = false;
Expand Down
63 changes: 54 additions & 9 deletions power_time_tracking_electron/src/py/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
global FOCUS_MODE
FOCUS_MODE = False

global LAST_FEW_SECONDS
LAST_FEW_SECONDS = []


# import web_app_stuff.app as web_app
Expand Down Expand Up @@ -71,13 +73,14 @@ def search_close_and_log_apps():
apps_in_name_form = [app[1] for app in apps]
last_thirty_mins_distracting = 0
whole_time = 0
global LAST_FEW_SECONDS
while True:

# # logger.debug(front_app)
# if front_app != None:
#Getting data replaced by JXA and applescript for macos
# try:
# # logger.debug(front_app)
# if front_app != None:

#Getting data replaced by JXA and applescript for macos
# try:
app = systemDataHandler.get_current_frontmost_app()
distracting_apps = get_distracting_apps()
current_app_name = app['app_name']
Expand All @@ -100,6 +103,11 @@ def search_close_and_log_apps():
apps_in_name_form.append(short_tab)
if short_tab in distracting_apps['apps_to_close']:
last_thirty_mins_distracting += 1
LAST_FEW_SECONDS.append(False)
else:
LAST_FEW_SECONDS.append(True)
if len(LAST_FEW_SECONDS) > 10:
LAST_FEW_SECONDS = []
# except Exception as err:
# logger.debug(err)
# tabname = None
Expand All @@ -109,8 +117,13 @@ def search_close_and_log_apps():
if app["app_name"] not in UNRECORDED_APPS:
database_worker.add_application_to_db(app["app_name"],"app",0,0)
apps_in_name_form.append(app["app_name"])
if app["app_name"] in distracting_apps['apps_to_close']:
last_thirty_mins_distracting += 1
if app["app_name"] in distracting_apps['apps_to_close']:
last_thirty_mins_distracting += 1
LAST_FEW_SECONDS.append(False)
else:
LAST_FEW_SECONDS.append(True)
if len(LAST_FEW_SECONDS) > 10:
LAST_FEW_SECONDS = []
whole_time +=1
if whole_time == 60*30: # 30 mins
whole_time = 0
Expand All @@ -122,7 +135,9 @@ def search_close_and_log_apps():
last_mouse_movement = database_worker.get_time_of_last_mouse_movement()
if datetime.datetime.now()- last_mouse_movement > datetime.timedelta(seconds=INACTIVE_TIME):
active = False
LAST_FEW_SECONDS.pop()
database_worker.log_current_app(current_app_name,tabname,active,title)
print(LAST_FEW_SECONDS)
check_if_server_must_be_updated()
# logger.debug(current_app_name)
if sys.platform != "win32":
Expand All @@ -133,8 +148,15 @@ def search_close_and_log_apps():

def check_if_server_must_be_updated():
to_update = database_worker.server_update_required()
global LAST_FEW_SECONDS
vals = {}
if to_update:
ppt_api_worker.update_server_data(to_update)
for a in to_update:
if a[1] == "live_focus_mode":
vals['focused'] = all(LAST_FEW_SECONDS)
vals['seconds'] = len(LAST_FEW_SECONDS)
LAST_FEW_SECONDS = []
ppt_api_worker.update_server_data(to_update,vals)


def make_url_to_base(full_url):
Expand Down Expand Up @@ -252,12 +274,28 @@ def stop_focus_mode(id):


def boot_up_checker():
logger.add(constants.LOGGER_LOCATION,backtrace=True,diagnose=True, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",rotation="5MB")
# check if too many items in logger folder
try:
path = os.path.dirname(constants.LOGGER_LOCATION)
# get the folder of the file
folder = path

if not os.path.exists(folder):
os.mkdir(folder)
else:
if len(os.listdir(folder)) > 5:
for file in os.listdir(folder):
os.remove(folder+"/"+file)
except Exception as e:
logger.debug(e)
return e
logger.add(constants.LOGGER_LOCATION,backtrace=True,diagnose=True, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",rotation="5MB", retention=5)
try:
if not os.path.exists(constants.DATABASE_LOCATION):
os.mkdir(constants.DATABASE_LOCATION)
elif not os.path.exists(constants.DATABASE_LOCATION + "/"+constants.DATABASE_NAME):
create_time_database()

database_created = check_if_database_created()
if not database_created:
time_table = create_time_database()
Expand Down Expand Up @@ -295,6 +333,12 @@ def boot_up_checker():
if database_created[1] == "1.8":
database_worker.update_to_database_version_1_9()
database_created[1] = "1.9"
if database_created[1] == "1.9":
database_worker.update_to_database_version_1_10()
database_created[1] = "1.10"
if database_created[1] == "1.10":
database_worker.update_to_database_version_1_11()
database_created[1] = "1.11"
print(database_worker.get_current_user_data())
print("HEREERERER")
if 'device_id' not in database_worker.get_current_user_data():
Expand Down Expand Up @@ -361,5 +405,6 @@ def get_current_user():
if user_id == None:
return {"status":True,'device_id':device_id, "user_id":None}
return {"status":True, "user_id":user_id, 'device_id':device_id, "user_data":database_worker.get_current_user_data()}

if __name__ == "__main__":
boot_up_checker()
74 changes: 71 additions & 3 deletions power_time_tracking_electron/src/py/database_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,32 @@ def update_to_database_version_1_9():
conn.commit()
conn.close()

def update_to_database_version_1_10():
"""
Updates the database to version 1.10
"""
# version adds many more update times
conn = connect_to_db()
c = conn.cursor()
add_live_focus_mode_update_time = make_write_to_db([(["5","live_focus_mode",get_time_in_format(),2,get_time_in_format()])],"server_update_times",["id","name","next_time","seconds_between_updates","last_updated"])
c.execute(add_live_focus_mode_update_time)
c.execute("UPDATE database_and_application_version SET database_version = '1.10' WHERE id=1")
conn.commit()
conn.close()

def update_to_database_version_1_11():
"""
Updates the database to version 1.11
"""
# add a user to user table
conn = connect_to_db()
c = conn.cursor()
c.execute("INSERT INTO user (id,name) VALUES (?,?)",(2,"live_focus_mode"))
# c.execute("UPDATE user SET name = 'default',data = ? WHERE id=1",[json.dumps({})])
c.execute("UPDATE database_and_application_version SET database_version = '1.11' WHERE id=1")
conn.commit()
conn.close()
set_live_focus_mode_data({})

def get_time_in_format():
return datetime.datetime.now().strftime(get_time_format())
Expand All @@ -214,7 +240,7 @@ def get_time_format():
return "%Y-%m-%d %H:%M:%S"

def get_all_time_logs():
logger.add(constants.LOGGER_LOCATION,backtrace=True,diagnose=True, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",rotation="5MB")
logger.add(constants.LOGGER_LOCATION,backtrace=True,diagnose=True, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",rotation="5MB",retention=5)
conn = connect_to_db()
c = conn.cursor()
c.execute("SELECT * FROM log")
Expand Down Expand Up @@ -250,7 +276,7 @@ def get_logs_between_times(start_time,end_time):
"""
Returns the logs between two times
"""
logger.add(constants.LOGGER_LOCATION,backtrace=True,diagnose=True, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",rotation="5MB")
logger.add(constants.LOGGER_LOCATION,backtrace=True,diagnose=True, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",rotation="5MB", retention=5)
conn = connect_to_db()
c = conn.cursor()
# c.execute(f"SELECT * FROM log WHERE time BETWEEN convert({full_time_format},{start_time}) AND convert({full_time_format},{end_time})")
Expand Down Expand Up @@ -588,4 +614,46 @@ def reset_database(update_id,update_time):
c = conn.cursor()
c.execute("UPDATE server_update_times SET next_time = ?, last_updated = ? WHERE id = ?",[datetime.datetime.strftime(datetime.datetime.now() + datetime.timedelta(seconds=update_time),get_time_format()),get_time_in_format(),update_id])
conn.commit()
conn.close()
conn.close()

def start_updating_live_focus_mode():
"""
Starts updating the live focus mode
"""
conn = connect_to_db()
c = conn.cursor()
c.execute("UPDATE server_update_times SET next_time = ?, last_updated = ? WHERE name = ?",[datetime.datetime.strftime(datetime.datetime.now(),get_time_format()),get_time_in_format(),"live_focus_mode"])
conn.commit()
conn.close()

def set_live_focus_mode_data(data):
"""
Sets the live focus mode data
"""
conn = connect_to_db()
c = conn.cursor()
final_data = {"time":get_time_in_format(),"data":data}
c.execute("UPDATE user SET data = ? WHERE id=2",[json.dumps(final_data)])
conn.commit()
conn.close()

def get_live_focus_mode_data():
"""
Gets the live focus mode data
"""
conn = connect_to_db()
c = conn.cursor()
# just get id 1 in users table
c.execute("SELECT * FROM user WHERE id=2")
data = c.fetchone()
conn.close()
if data is None:
return None
final_data = {}
if type(data[2]) == str:
final_data = json.loads(data[2])
else:
final_data = data[2]
if get_time_from_format(final_data['time']) < datetime.datetime.now() - datetime.timedelta(seconds=10):
return None
return final_data['data']
3 changes: 3 additions & 0 deletions power_time_tracking_electron/src/py/get_time_spent.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def proper_time_parse(data,distractions=[]):
final_data.append(data[i])
i += 1
# print(len(final_data))
if len(final_data) == 0:
return {},{'total_time_spent':0,"distractions_number":0,"distractions_time_min":0/60}

previous_time = datetime.datetime.strptime(final_data[0][0],full_time_format)
time = 0
all_times = {}
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion power_time_tracking_electron/src/py/macos_data_grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@



logger.add(constants.LOGGER_LOCATION,backtrace=True,diagnose=True, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",rotation="5MB")
logger.add(constants.LOGGER_LOCATION,backtrace=True,diagnose=True, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",rotation="5MB", retention=5)

#logger.add(f"{os.getenv('HOME')}/.PowerTimeTracking/logs/log.log",backtrace=True,diagnose=True, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",rotation="5MB")

Expand Down
Loading