Skip to content

Commit

Permalink
Merge pull request #150 from OrangeJedi/v.1.2.1
Browse files Browse the repository at this point in the history
V.1.2.1
  • Loading branch information
OrangeJedi committed Jun 7, 2023
2 parents 0dd4ebe + 2f7473f commit ba9259b
Show file tree
Hide file tree
Showing 7 changed files with 1,091 additions and 868 deletions.
72 changes: 57 additions & 15 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ let astronomy = {
"moonset": undefined,
"calculated": false
};
let admin = false;
exec('NET SESSION', function (err, so, se) {
if (se.length === 0) {
admin = true;
}
//console.log(se.length === 0 ? "admin" : "not admin");
});

//window creation code
function createConfigWindow(argv) {
Expand Down Expand Up @@ -323,6 +330,8 @@ app.allowRendererProcessReuse = true
app.whenReady().then(startUp);

function startUp() {
//Uncomment the line below when compiling the .scr file
//store.set('useTray', false);
let firstTime = false;
if (!store.get("configured") || store.get("version") !== app.getVersion()) {
firstTime = true;
Expand Down Expand Up @@ -447,6 +456,7 @@ function setUpConfigFile() {
store.set('transitionDirection', store.get("transitionDirection") ?? "");
store.set('videoTransitionLength', store.get('videoTransitionLength') ?? 2000);
store.set('fillMode', store.get('fillMode') ?? "stretch");
store.set('videoFileType', store.get('videoFileType') ?? "H2641080p");
//1.2.0 changes the default transition length because of internal changes
if (store.get('videoTransitionLength') === 1000) {
store.set('videoTransitionLength', 2000);
Expand Down Expand Up @@ -832,9 +842,9 @@ function downloadVideos() {
return true;
}
});
console.log(allowedVideos[i]);
//console.log(allowedVideos[i]);
//console.log(`Downloading ${videos[index].name}`);
downloadFile(videos[index].src.H2641080p, `${cachePath}/temp/${allowedVideos[i]}.mov`, () => {
downloadFile(videos[index].src[store.get('videoFileType')], `${cachePath}/temp/${allowedVideos[i]}.mov`, () => {
fs.copyFileSync(`${cachePath}/temp/${allowedVideos[i]}.mov`, `${cachePath}/${allowedVideos[i]}.mov`);
fs.unlink(`${cachePath}/temp/${allowedVideos[i]}.mov`, (err) => {
});
Expand Down Expand Up @@ -946,6 +956,9 @@ function clearCacheTemp() {
if (!fs.existsSync(`${app.getPath('userData')}/videos/temp`)) {
fs.mkdirSync(`${app.getPath('userData')}/videos/temp`);
}
if(!fs.existsSync(cachePath + "\\temp")){
fs.mkdirSync(cachePath + "\\temp");
}
let dir = fs.readdirSync(cachePath + "\\temp").forEach(file => {
if (fs.existsSync(`${cachePath}/temp/${file}`)) {
fs.unlink(`${cachePath}/temp/${file}`, (err) => {
Expand Down Expand Up @@ -993,10 +1006,11 @@ function lockComputer() {

//idle startup timer
function launchScreensaver() {
let startAfter = store.get('startAfter');
//console.log(screens.length,powerMonitor.getSystemIdleTime(),store.get('startAfter') * 60)
if (screens.length === 0 && !suspend && !isComputerSleeping && !isComputerSuspendedOrLocked) {
let idleTime = powerMonitor.getSystemIdleTime();
if (powerMonitor.getSystemIdleState(store.get('startAfter') * 60) === "idle") {
if (screens.length === 0 && !suspend && !isComputerSleeping && !isComputerSuspendedOrLocked && startAfter > 0) {
//let idleTime = powerMonitor.getSystemIdleTime();
if (powerMonitor.getSystemIdleState(startAfter * 60) === "idle" && getWakeLock()) {
if (!store.get("runOnBattery")) {
if (powerMonitor.isOnBatteryPower()) {
return;
Expand All @@ -1010,19 +1024,30 @@ function launchScreensaver() {
setInterval(launchScreensaver, 5000);

function onFirstVideoPlayed() {
let startTime = new Date();
setTimeOfDayList();
if (store.get('blankScreen')) {
setTimeout(() => {
for (let i = 0; i < screens.length; i++) {
screens[i].webContents.send('blankTheScreen');
if (store.get('sleepAfterBlank')) {
//sleep the computer after a few seconds of blank screen
setTimeout(() => {
sleepComputer()
}, store.get('videoTransitionLength') * 3)
}
let interval = setInterval(() => {
if (screens.length === 0) {
clearTimeout(interval);
return;
}
if (new Date() - startTime >= store.get('blankAfter') * 60 * 1000) {
blankScreensaver();
}
}, store.get('blankAfter') * 60000);
}, 30000);
}
}

function blankScreensaver() {
for (let i = 0; i < screens.length; i++) {
screens[i].webContents.send('blankTheScreen');
if (store.get('sleepAfterBlank')) {
//sleep the computer after a few seconds of blank screen
setTimeout(() => {
sleepComputer()
}, store.get('videoTransitionLength') * 3)
}
}
}

Expand Down Expand Up @@ -1088,6 +1113,23 @@ function calculateAstronomy() {
}
}

//check the system to see if any app is requesting the system to not sleep
//Requires admin privileges to run
function getWakeLock() {
if (admin) {
exec('powercfg /requests', function (error, stdout, stderr) {
if (error) {
console.log(error);
return true;
}
return stdout.match(/None./g).length !== 6;
}
);
} else {
return true;
}
}

//helper functions
function randomInt(min, max) {
return Math.floor(Math.random() * max) - min;
Expand Down
29 changes: 28 additions & 1 deletion json-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ function createJSON() {
'id' : newData[i].id,
'accessibilityLabel' : newData[i].accessibilityLabel,
'src' : {
'H2641080p' : newData[i]["url-1080-H264"]
'H2641080p' : newData[i]["url-1080-H264"],
'H2651080p' : newData[i]["url-1080-SDR"],
'H2654k' : newData[i]["url-4K-SDR"]
}
}
)
Expand Down Expand Up @@ -55,6 +57,31 @@ function updateJSON() {
document.getElementById('output').value = beautify(videos.sort(sortVideos),null,2,128);
}

function updateSource(){
let newData = JSON.parse(document.getElementById('input').value);
let newVideos = [];
for (const vid in newData) {
let index = videos.findIndex((e) => {
if(newData[vid].id === e.id){
return true;
}
});
if(index > -1) {
newVideos.push({
'id' : videos[index].id,
"accessibilityLabel": videos[index].accessibilityLabel,
"name": videos[index].name,
"pointsOfInterest": videos[index].pointsOfInterest,
"type": videos[index].type,
"timeOfDay": videos[index].timeOfDay,
'src': newData[vid].src
});
}
}
console.log(newVideos.length,videos.length);
document.getElementById('output').value = beautify(newVideos,null,2,128);
}

function addToJSON() {
let newData = JSON.parse(document.getElementById('input').value);
if(!Array.isArray(newData)){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aerial",
"version": "1.2.0",
"version": "1.2.1",
"videoJSONVersion": "1.15.0",
"description": "Apple TV screen saver for Windows",
"main": "app.js",
Expand Down
Loading

0 comments on commit ba9259b

Please sign in to comment.