-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
741ebd7
commit 98e5d82
Showing
13 changed files
with
575 additions
and
541 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
assets/ | ||
assets/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |
Oops, something went wrong.