Skip to content

Commit

Permalink
Updated in version 0.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ciriousjoker committed Feb 24, 2022
1 parent 44727b7 commit 2e83cbb
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 36 deletions.
6 changes: 3 additions & 3 deletions MainActivity.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="col-12">
<div class="mdl-shadow--2dp">
<div class="mdl-card__title">
<h2 class="mdl-card__title-text">ShufflePaper 0.9.0</h2>
<h2 class="mdl-card__title-text">ShufflePaper 0.9.2</h2>
</div>
<div class="mdl-card__supporting-text">
Choose a folder with your backgroud images. These will then be set as your wallpaper according to your preferences below.
Expand All @@ -34,7 +34,7 @@ <h2 class="mdl-card__title-text">ShufflePaper 0.9.0</h2>
<div class="mdl-grid" style="padding: 0px !important">
<div class="mdl-cell mdl-cell--6-col" style="width: calc(75%); margin: 0px; display: flex; align-items: center">
<span></span>
<div id="tv_chosen_folder" class="center-vertically"></div>
<div id="tv_chosen_folder" class="center-vertically" style="display: none;"></div>
</div>
<div class="mdl-cell mdl-cell--2-col" style="width: calc(25%); margin: 0px">
<button id="btn_choose_folder" class="mdl-button nofocus mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect" style="width: 100%; padding: 0">
Expand All @@ -44,7 +44,7 @@ <h2 class="mdl-card__title-text">ShufflePaper 0.9.0</h2>
</div>
</div>
<div class="mdl-card__menu">
<button id="btn_refresh" class="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect">
<button id="btn_refresh" class="mdl-button nofocus mdl-button--icon mdl-js-button mdl-js-ripple-effect">
<i class="material-icons">autorenew</i>
</button>
</div>
Expand Down
11 changes: 7 additions & 4 deletions js/AlarmManager.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
function ALARM() {}
function AlarmManager() {}
AlarmManager.ID = function() {};
AlarmManager.INTERVAL = function() {};



// Used as an identifier for the alarm used
// to change the wallpaper every x minutes
ALARM.WALLPAPER_INTERVAL = "wallpaper_change_interval";
AlarmManager.ID.Wallpaper = "wallpaper_change_interval";
AlarmManager.INTERVAL.Wallpaper = 15;


function AlarmManager() {}

AlarmManager.set = function(id, interval) {
chrome.alarms.create(id, {
delayInMinutes: interval,
Expand Down
31 changes: 31 additions & 0 deletions js/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,35 @@ function getRoot(callback, return_anyway) {
},
// Flag to return even if the result would be 'undefined'
true);
}

function getFormattedPath(dir, callback) {
chrome.fileSystem.getDisplayPath(dir, function(path) {
// eg. /special/drive-[SOME ID]/root/
var regIsMyDrive = new RegExp('\/special\/drive-\\w*\/root\/');

// eg. /special/drive-[SOME ID]/other/
var regIsShared = new RegExp('\/special\/drive-\\w*\/other\/');

// eg. /media/removable/My Usb/subfolder
var regIsExternal = new RegExp('\/media\/removable');

// eg /provided/[SOME ID]:chrome-extension_[SOME ID]_[SOME STORAGE NUMBER]:Persistent::::::::::::::chrome_extension:::::::::::::::[MOUNTED FOLDER NAME]:[SOME ID]/subfolders
var regIsProvided = new RegExp('\/provided\/.*::::::::::::::chrome_extension:::::::::::::::');

if (regIsMyDrive.test(path)) {
callback(path.replace(regIsMyDrive, "~/My Drive/"));
} else if (regIsShared.test(path)) {
callback(path.replace(regIsShared, "~/Shared/"));
} else if (regIsExternal.test(path)) {
callback(path.replace(regIsExternal, "~"));
} else if (regIsProvided.test(path)) {
var FormattedStart = path.replace(regIsProvided, "~/"); // Returns [MOUNTED FOLDER NAME]:[SOME ID]/subfolders
var StorageName = FormattedStart.substring(0, FormattedStart.lastIndexOf(":")); // Returns [MOUNTED FOLDER NAME]
var SubPath = FormattedStart.replace(new RegExp('~\/[^\/]*'), ""); // Returns /subfolders
callback(StorageName + SubPath);
} else {
callback(path);
}
});
}
10 changes: 6 additions & 4 deletions js/MainActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ $(document).ready(function() {
prefs.apply();

if(!this.checked) {
AlarmManager.clear(ALARM.WALLPAPER_INTERVAL);
AlarmManager.clear(AlarmManager.ID.Wallpaper);
} else {
AlarmManager.set(ALARM.WALLPAPER_INTERVAL, 0.1);
AlarmManager.set(AlarmManager.ID.Wallpaper, AlarmManager.INTERVAL.Wallpaper);
}
});
});
Expand Down Expand Up @@ -85,10 +85,12 @@ function loadDirPath() {
getRoot(function(rootDir) {
if(!isdef(rootDir)) {
$('#tv_chosen_folder').html("Please speficy a folder <i class=\"material-icons\">keyboard_arrow_right</i>");
$('#tv_chosen_folder').fadeIn();
} else {
chrome.fileSystem.getDisplayPath(rootDir, function(path) {
getFormattedPath(rootDir, function(path) {
$('#tv_chosen_folder').html(path);
});
$('#tv_chosen_folder').fadeIn();
});
}
},
// flag to return even if the result would be 'undefined'
Expand Down
51 changes: 31 additions & 20 deletions js/WallpaperManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@ function loadNextWallpaper() {
getNextId(_currentId, numbertotal, function(nextId) {
readFolder(rootDir, function(fileEntry, number) {
if(number == nextId) {
console.log("New wallpaper id: " + nextId);
// Read the file as an arraybuffer
readFileAsArrayBuffer(fileEntry, function(buf) {
// Set the arraybuffer as a wallpaper
chrome.wallpaper.setWallpaper(
{
'data': buf.target.result,
'filename': fileEntry.name,
'layout': 'CENTER_CROPPED'
}, function() {
var regCheckFileExtension = new RegExp('(.jpg|.jpeg|.jfif|.png)', 'i');
if(regCheckFileExtension.test(fileEntry.name) && isdef(buf)) {
// Set the arraybuffer as a wallpaper
console.log("New wallpaper: " + fileEntry.name);

// Store the new current_id as a SharedPreference
chrome.wallpaper.setWallpaper(
{
'data': buf.target.result,
'filename': fileEntry.name,
'layout': 'CENTER_CROPPED'
}, function() {
// Store the new current_id as a SharedPreference
prefs.set(Key.current_file_id, nextId);
prefs.apply();
});
} else {
// Store the new current_id as a SharedPreference so that it doesn't try the same file over and over
prefs.set(Key.current_file_id, nextId);
prefs.apply();
});
}
});
}
});
Expand All @@ -37,7 +42,7 @@ function loadNextWallpaper() {
// Pick the next file id based on the user's preferences
function getNextId(currentId, filecount, callback) {
prefs.get(Key.choose_random, function(is_random) {
if(is_random) {
if(isdef(is_random) && is_random === true) {
callback(randomMinMax(0, filecount - 1));
} else {
if(!isdef(currentId)) {
Expand All @@ -50,18 +55,24 @@ function getNextId(currentId, filecount, callback) {
callback(newId);
}
}
});
},
// optional flag to return even if the result would be "undefined"
true);
}

// Returns an ArrayBuffer with the file's content
function readFileAsArrayBuffer(fileEntry, callback) {
fileEntry.file(function(file) {
var fileReader = new FileReader();
fileReader.onloadend = function(arybf) {
callback(arybf);
};
fileReader.readAsArrayBuffer(file);
});
if(fileEntry.isFile) {
fileEntry.file(function(file) {
var fileReader = new FileReader();
fileReader.onloadend = function(arybf) {
callback(arybf);
};
fileReader.readAsArrayBuffer(file);
});
} else {
callback();
}
}

// Returns the file count of the folder
Expand Down
8 changes: 3 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
{
"manifest_version": 2,
"name": "ShufflePaper",
"version": "0.9.0",
"short_name": "ShufflePaper",
"version": "0.9.2",
"description": "Choose a folder and have your Chromebook automatically shuffle through the wallpapers in it!",
"minimum_chrome_version": "38",

"icons": {
"16": "assets/ic_launcher_16.png",
"48": "assets/ic_launcher_48.png",
"128": "assets/ic_launcher_128.png",
"512": "assets/ic_launcher_512.png"
},
"permissions": [
"notifications",
"wallpaper",
"alarms",
"storage",
{
"fileSystem": [
"write",
"retainEntries",
"directory"
]
Expand All @@ -36,4 +34,4 @@
}
},
"offline_enabled": true
}
}

0 comments on commit 2e83cbb

Please sign in to comment.