Skip to content

Commit

Permalink
Merge pull request #150 from nigeljacob/Nigel
Browse files Browse the repository at this point in the history
Fixed small issues and bugs
  • Loading branch information
nigeljacob authored Mar 23, 2024
2 parents f9aa15c + c5e36dd commit 385adf3
Show file tree
Hide file tree
Showing 26 changed files with 3,244 additions and 404 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 6 additions & 2 deletions Backend/src/ProgressTrackerFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const axios = require('axios');
const FormData = require('form-data');
const { WritableStreamBuffer } = require('stream-buffers');
// import { activeWindow, type } from '@miniben90/x-win';
const { activeWindow } = require('@miniben90/x-win');
const { activeWindow, openWindows } = require('@miniben90/x-win');
const { uIOhook, UiohookKey } = require('uiohook-napi')


Expand All @@ -25,6 +25,10 @@ function getActiveWindowMac() {
});
}

function getRunningWindowsMac() {
return openWindows()
}

// to get currently active app on mac
function checkActiveApplication() {
getActiveWindowMac()
Expand Down Expand Up @@ -301,4 +305,4 @@ function getDateTime() {



module.exports = { checkActiveApplication, getCurrentlyActiveApplication, openFileDialog, createZipAndUpload, getFocusedWindow, idleDetection, getDateTime};
module.exports = { checkActiveApplication, getCurrentlyActiveApplication, openFileDialog, createZipAndUpload, getFocusedWindow, idleDetection, getDateTime, getRunningWindowsMac};
11 changes: 10 additions & 1 deletion Backend/src/viewTaskFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var fs = require('fs');
const os = require('node:os')
const { exec } = require('child_process');
// const helloModule = require('./testing.js');
const {getCurrentlyActiveApplication} = require('./ProgressTrackerFunctions')
const {getCurrentlyActiveApplication, getRunningWindowsMac} = require('./ProgressTrackerFunctions')

const {getInstalledApps} = require('get-installed-apps')

Expand Down Expand Up @@ -60,6 +60,15 @@ const {getInstalledApps} = require('get-installed-apps')
for(let i = 0; i < activeAppList.length; i++) {
let dict = {name: activeAppList[i], iconData: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAA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qmNY0tHfLAqNg4dSr9x+dtSGhY+JmPZ836nlifSDo6M11cPnRxcfmC8hXl6+nMzJkz5xDpc8r7Aud03qN8SPlomsMGtrw7785bcGbM+AtbwdMNvKhRMAAAAABJRU5ErkJggg=="}

if(!appsList.some((item) => item.name === dict.name)) {
appsList.push(dict)
}
}
} else {
const applicationsList = getRunningWindowsMac();

for(let i = 0; i < applicationsList.length; i++) {
let dict = {name: applicationsList[i].info.name, iconData: "../../assets/images/defaultIconMac.png"}
if(!appsList.some((item) => item.name === dict.name)) {
appsList.push(dict)
}
Expand Down
85 changes: 80 additions & 5 deletions Electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ const {
BrowserWindow,
Menu,
ipcMain,
Notification,
dialog,
screen,
nativeImage
Notification,
nativeImage,
shell,
session
} = require("electron");
const isDev = false
const isDev = true;
const windowStateKeeper = require("electron-window-state");
const path = require("path");
const {
Expand All @@ -25,6 +27,8 @@ const {
} = require("../Backend/src/ProgressTrackerFunctions");
const chokidar = require('chokidar');
const trayWindow = require("electron-tray-window");
const { systemPreferences } = require('electron')
const { exec } = require('child_process');

function createWindow() {
let mainWindowState = windowStateKeeper({
Expand Down Expand Up @@ -153,6 +157,40 @@ function createWindow() {
});
});


if(os.platform() == "darwin") {
setTimeout(() => {
const permission = ""

session.defaultSession.setPermissionRequestHandler((webContents, permission, callback) => {
return callback(false);
})

systemPreferences.isTrustedAccessibilityClient(true)

win.webContents
.executeJavaScript('localStorage.getItem("notificationPermission");', true)
.then(result => {
if(result == null) {
dialog.showMessageBox(win, {
type: 'warning',
icon: path.join(__dirname, 'icon.png'),
message: 'Notification permissions denied',
detail: 'To enable notifications, please go to your system settings. Click "Notifications" and enable notifications for SYNK.',
buttons: ['Open Settings', 'Deny'],
defaultId: 0
}).then(({ response }) => {
if (response === 0) {
shell.openExternal('x-apple.systempreferences:com.apple.preference.notifications')
win.webContents
.executeJavaScript('localStorage.setItem("notificationPermission", true);', true)
}
});
}
});
}, 10000)
}

ipcMain.on("notification", (event, notification) => {
const NOTIFICATION_TITLE = notification[0];
const NOTIFICATION_BODY = notification[1];
Expand Down Expand Up @@ -539,16 +577,51 @@ win.on("close", (e) => {
}, 900000)

appTrackingInterval = setInterval(() => {
let currentWindow = getFocusedWindow();

let currentWindow;

try{
currentWindow = getFocusedWindow();
} catch(e) {
dialog.showMessageBox(win, {
type: 'error',
icon: path.join(__dirname, 'icon.png'),
message: 'Tracking Permission denied',
detail: 'Accept the permission to allow SYNK to track your task activity. Start the task again after successfull permission.',
buttons: ['Ok'],
defaultId: 0
})
clearInterval(idleTrackingInterval)
clearInterval(appTrackingInterval)
clearInterval(lastModifiedInterval)

win.webContents.send("sendIntervalsPaused", {...TaskDetails, trackedApplications: trackedApplications})
}
if(!idleDetected) {
idleDetection("start", (data) => {
try{
idleDetection("start", (data) => {
console.log("detected");
idleDetected = true
if(idlePopupShown) {
idlePopup.destroy()
idlePopupShown = false
}
})
} catch(e) {
dialog.showMessageBox(win, {
type: 'error',
icon: path.join(__dirname, 'icon.png'),
message: 'Tracking Permission denied',
detail: 'Accept the permission to allow SYNK to track your task activity. Start the task again after successfull permission.',
buttons: ['Ok'],
defaultId: 0
})
clearInterval(idleTrackingInterval)
clearInterval(appTrackingInterval)
clearInterval(lastModifiedInterval)

win.webContents.send("sendIntervalsPaused", {...TaskDetails, trackedApplications: trackedApplications})
}
} else {
idleDetection("stop", (data) => {
// console.log("stopped")
Expand Down Expand Up @@ -733,6 +806,8 @@ ipcMain.on("idleCloseClicked", (event, data) => {
}
});

app.setAccessibilitySupportEnabled(true)

}

app.on("ready", createWindow);
Expand Down
1 change: 1 addition & 0 deletions Frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ body {
rgba(30, 30, 30, 1) 100%
);
background-repeat: none;
scroll-behavior: smooth;
}

*::-webkit-scrollbar {
Expand Down
Loading

0 comments on commit 385adf3

Please sign in to comment.