Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ciriousjoker committed Feb 24, 2022
1 parent 741ebd7 commit 98e5d82
Show file tree
Hide file tree
Showing 13 changed files with 575 additions and 541 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
assets/
assets/
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ Choose a folder and have your Chromebook automatically shuffle through the wallp

The files in the assets folder (the icons) are replaced with empty icons in order to comply with the copyright rules of Flaticon. The packaged apps in the Chrome Web Store and the .crx files in the [releases](https://github.com/CiriousJoker/ShufflePaper/releases/latest) still contain the icons, but I'm not allowed to distribute them as files.

## Features (v1.1.0)
## v1.2.0
- Bugfixes
- A little bit better code style

## v1.1.1
### Features
- Select a folder with images you want to use as wallpaper candidates
- Button: Manually change wallpaper
- Optional: Customizable delay between wallpaper changes
Expand Down
10 changes: 5 additions & 5 deletions js/AlarmManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function AlarmManager() {}
AlarmManager.ID = function() {};
AlarmManager.INTERVAL = function() {};
var AlarmManager = {}
AlarmManager.ID = {};
AlarmManager.INTERVAL = {};



Expand All @@ -10,14 +10,14 @@ AlarmManager.ID.WALLPAPER = "wallpaper_change_interval";
AlarmManager.INTERVAL.WALLPAPER_DEFAULT = 15;


AlarmManager.set = function(id, interval) {
AlarmManager.set = (id, interval) => {
chrome.alarms.create(id, {
delayInMinutes: interval,
periodInMinutes: interval
});
console.log("Started the wallpaper service.");
};

AlarmManager.clear = function(id) {
AlarmManager.clear = (id) => {
chrome.alarms.clear(id);
};
51 changes: 23 additions & 28 deletions js/BackgroundService.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
chrome.app.runtime.onLaunched.addListener(function(launchData) {
chrome.app.window.create(
'../MainActivity.html',
{
id: Constants.Defaults.window_id,
bounds: {
width: Constants.Defaults.WindowDimensions.width,
height: Constants.Defaults.WindowDimensions.height
},
innerBounds: {
minWidth: Constants.Defaults.WindowDimensions.min_width,
minHeight: Constants.Defaults.WindowDimensions.min_height
},
frame: {
type: "chrome",
color: Constants.Defaults.frame_color
}
}
);
chrome.app.runtime.onLaunched.addListener(launchData => {
chrome.app.window.create("../MainActivity.html", {
id: Constants.Defaults.window_id,
bounds: {
width: Constants.Defaults.WindowDimensions.width,
height: Constants.Defaults.WindowDimensions.height
},
innerBounds: {
minWidth: Constants.Defaults.WindowDimensions.min_width,
minHeight: Constants.Defaults.WindowDimensions.min_height
},
frame: {
type: "chrome",
color: Constants.Defaults.frame_color
}
});
});

chrome.alarms.onAlarm.addListener(function(alarm) {
console.log("Changing wallpaper!", alarm);
loadNextWallpaper();
chrome.alarms.onAlarm.addListener(alarm => {
console.log("Changing wallpaper!", alarm);
loadNextWallpaper();
});

// This isn't functional yet, but I'll keep it there in case the commands api will work anytime soon
chrome.commands.onCommand.addListener(function(command) {
console.log("Command triggered: " + command);
chrome.commands.onCommand.addListener(command => {
console.log("Command triggered: " + command);

chrome.app.window.create(
'../MainActivity.html'
);
});
chrome.app.window.create("../MainActivity.html");
});
68 changes: 37 additions & 31 deletions js/Constants.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
function Constants() {}
Constants.Key = function() {};
Constants.Defaults = function() {};
Constants.Defaults.WindowDimensions = function() {};
Constants.Defaults.Wallpaper = function() {};
var Constants = {
Key: {
// File system
dir_id: "dir_id",
current_file_id: "current_file_id",

// File system
Constants.Key.dir_id = "dir_id";
Constants.Key.current_file_id = "current_file_id";
// Wallpaper preferences
choose_random: "choose_random",
use_interval: "use_interval",
interval: "interval",
interval_mode: "interval_mode",
layout_mode: "layout_mode"
},
Defaults: {
Wallpaper: {
// Wallpaper defaults
interval_mode: 0,
retry_delay: 100,
layout: 2,
layout_mode: ["STRETCH", "CENTER", "CENTER_CROPPED"],
file_extensions: new RegExp("(.jpg|.jpeg|.jfif|.png)", "i")
},

// Wallpaper preferences
Constants.Key.choose_random = "choose_random";
Constants.Key.use_interval = "use_interval";
Constants.Key.interval = "interval";
Constants.Key.interval_mode = "interval_mode";
Constants.Key.layout_mode = "layout_mode";
WindowDimensions: {
width: 700,
height: 400,
min_width: 680,
min_height: 400
},

// Other
Constants.Defaults.copyright = chrome.i18n.getMessage("copyright", ["Philipp Bauer", new Date().getFullYear()]) + "<br />v" + chrome.runtime.getManifest().version;
Constants.Defaults.share_url = "https://chrome.google.com/webstore/detail/shufflepaper/ghcndibmdbeipgggdddmecagpkllglpj/"; // + chrome.runtime.id + "/"; // chrome.runtime.id seems to return a false value, hence it's hardcoded here
frame_color: "#D32F2F",
window_id: "shufflepaper_mainActivity",

// Wallpaper defaults
Constants.Defaults.Wallpaper.interval_mode = 0;
Constants.Defaults.Wallpaper.retry_delay = 100;
Constants.Defaults.Wallpaper.layout = 2;
Constants.Defaults.Wallpaper.layout_mode = ["STRETCH", "CENTER", "CENTER_CROPPED"];
Constants.Defaults.Wallpaper.file_extensions = new RegExp('(.jpg|.jpeg|.jfif|.png)', 'i');

// Window preferences
Constants.Defaults.frame_color = "#D32F2F";
Constants.Defaults.window_id = "shufflepaper_mainActivity";
Constants.Defaults.WindowDimensions.width = 700;
Constants.Defaults.WindowDimensions.height = 400;
Constants.Defaults.WindowDimensions.min_width = 680;
Constants.Defaults.WindowDimensions.min_height = 400;
// Other
copyright:
chrome.i18n.getMessage("copyright", ["Philipp Bauer", new Date().getFullYear()]) +
"<br />v" +
chrome.runtime.getManifest().version,
share_url: "https://chrome.google.com/webstore/detail/shufflepaper/ghcndibmdbeipgggdddmecagpkllglpj/"
}
};
156 changes: 82 additions & 74 deletions js/Helper.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,91 @@
function randomMinMax(min, max)
{
return Math.floor(Math.random()*(max-min+1)+min);
function randomMinMax(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}

function isdef(o) {
if(typeof o !== 'undefined') {
return true;
}
return false;
if (typeof o !== "undefined") {
return true;
}
return false;
}

function getRoot(callback, return_anyway) {
prefs.get(Constants.Key.dir_id, function(result) {
if(isdef(result)) {
// Try to load the folder using the key
chrome.fileSystem.isRestorable(result, function (is_recoverable) {
if(is_recoverable) {
chrome.fileSystem.restoreEntry(result, function(rootDir) {
callback(rootDir);
});
}
});
} else {
if(return_anyway) {
callback();
}
}
},
// Flag to return even if the result would be 'undefined'
true);
prefs.get(
Constants.Key.dir_id,
result => {
if (isdef(result)) {
// Try to load the folder using the key
chrome.fileSystem.isRestorable(result, is_recoverable => {
if (is_recoverable) {
chrome.fileSystem.restoreEntry(result, rootDir => {
callback(rootDir);
});
}
});
} else {
if (return_anyway) {
callback();
}
}
},
// Flag to return even if the result would be 'undefined'
true
);
}

function getFormattedPath(dir, callback) {
// TODO: Create constants for folder prefixes
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:::::::::::::::');

// eg /provided/[SOME ID]:[ESCAPED ZIP PATH]:[SOME ID]/subfolders
var regIsCompressed = new RegExp('\/provided\/.*:');

// eg ~/Downloads/subfolders
var regIsDownloads = new RegExp('~\/Downloads\/');

var formatted_path, SubPath, isValid = true;
if (regIsMyDrive.test(path)) {
formatted_path = path.replace(regIsMyDrive, "My Drive");
} else if (regIsShared.test(path)) {
formatted_path = path.replace(regIsShared, "Shared/");
} else if (regIsExternal.test(path)) {
formatted_path = 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]
SubPath = FormattedStart.replace(new RegExp('[^\/]*'), ""); // Returns /subfolders
formatted_path = StorageName + SubPath;
} else if (regIsCompressed.test(path)) {
var RemovedBeginning = path.replace(new RegExp('\/provided\/[^:]*:'), ""); // Returns [ESCAPED ZIP PATH]:[SOME ID]/subfolders
var ZipLocation = unescape(RemovedBeginning.replace(new RegExp(':.*'), "")); // Returns [UNESCAPED ZIP PATH]
var ZipName = ZipLocation.replace(new RegExp('.*\/'), ""); // Returns [ZIP NAME]
SubPath = path.replace(new RegExp('.*:[^\/]*'), ""); // Returns /subfolders
formatted_path = ZipName + SubPath;
isValid = false;
} else if (regIsDownloads.test(path)) {
formatted_path = path.replace(new RegExp('~\/'), "");
} else {
formatted_path = getString("error_invalid_path");
}

formatted_path = formatted_path.replace(/\//g, '<i class="material-icons" style="font-size: 18px;">keyboard_arrow_right</i>');
callback(formatted_path, isValid);
});
}
// TODO: Create constants for folder prefixes
chrome.fileSystem.getDisplayPath(dir, 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:::::::::::::::");

// eg /provided/[SOME ID]:[ESCAPED ZIP PATH]:[SOME ID]/subfolders
var regIsCompressed = new RegExp("/provided/.*:");

// eg ~/Downloads/subfolders
var regIsDownloads = new RegExp("~/Downloads/");

var formatted_path;
var SubPath;
var isValid = true;

if (regIsMyDrive.test(path)) {
formatted_path = path.replace(regIsMyDrive, "My Drive");
} else if (regIsShared.test(path)) {
formatted_path = path.replace(regIsShared, "Shared/");
} else if (regIsExternal.test(path)) {
formatted_path = 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]
SubPath = FormattedStart.replace(new RegExp("[^/]*"), ""); // Returns /subfolders
formatted_path = StorageName + SubPath;
} else if (regIsCompressed.test(path)) {
var RemovedBeginning = path.replace(new RegExp("/provided/[^:]*:"), ""); // Returns [ESCAPED ZIP PATH]:[SOME ID]/subfolders
var ZipLocation = unescape(RemovedBeginning.replace(new RegExp(":.*"), "")); // Returns [UNESCAPED ZIP PATH]
var ZipName = ZipLocation.replace(new RegExp(".*/"), ""); // Returns [ZIP NAME]
SubPath = path.replace(new RegExp(".*:[^/]*"), ""); // Returns /subfolders
formatted_path = ZipName + SubPath;
isValid = false;
} else if (regIsDownloads.test(path)) {
formatted_path = path.replace(new RegExp("~/"), "");
} else {
formatted_path = path;
}

formatted_path = formatted_path.replace(
/\//g,
'<i class="material-icons" style="font-size: 18px;">keyboard_arrow_right</i>'
);
callback(formatted_path, isValid);
});
}
Loading

0 comments on commit 98e5d82

Please sign in to comment.