Skip to content

Commit

Permalink
0.0.3.1
Browse files Browse the repository at this point in the history
Fixed an issue with Linux where the file system is case sensitive. Module Credits now uses `FilePicker` to get the correct path.
  • Loading branch information
mouse0270 committed Aug 1, 2021
1 parent f765fc8 commit d960fde
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 41 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 0.0.3.1 - Linux Case Sensitive File System
- Fixed an issue with Linux where the file system is case sensitive. Module Credits now uses `FilePicker` to get the correct path. Thank you LorduFreeman for helping me fix this issue

# Version 0.0.3 - All the Customization
Added Option to add font awesome icon to default tags such as Javascript, CSS and Compendium.
Added Option to condense tags. Condensing a tag will remove the text from the tag and only show the icon for that tag.
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Lists the authors of projects on the Manage Modules Window. If a url is provided in the module.json file, it will make the version tag link to the module url.",
"version": "This is auto replaced",
"library": "false",
"manifestPlusVersion": "0.0.1",
"manifestPlusVersion": "0.0.0.1",
"minimumCoreVersion": "0.8.8",
"compatibleCoreVersion": "0.8.8",
"authors": [
Expand Down
108 changes: 68 additions & 40 deletions scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ class ModuleCredits extends MousesLib {
super(module)
}

async getModuleMD(module, file) {
return await FilePicker.browse('user', `./modules/${module}/${file}.md`, { extensions: ['.md'] });
}

init = () => {
// Add Changelog Button to Help and Documentation
$('#sidebar #settings #settings-documentation').append(`<button data-action="changelog">
Expand Down Expand Up @@ -44,14 +40,6 @@ class ModuleCredits extends MousesLib {
return 0;
};

const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (array, callback) => {
this.LOG(array, array.length);
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}

let tracker = this.setting('trackedChangelogs');

// Remove Modules that Don't Exists
Expand All @@ -68,23 +56,35 @@ class ModuleCredits extends MousesLib {
if (typeof tracker[module?.data?.name] != 'undefined') {
// Check if Module has Updated
if (compareVersion(module?.data?.version, tracker[module?.data?.name].version)) {
await this.getModuleMD(module?.data?.name, 'CHANGELOG').then(response => {
await FilePicker.browse('user', `./modules/${module?.data?.name}/`, { extensions: ['.md'] }).then(response => {
let files = response.files.filter(file => file.toLowerCase().includes(`changelog.md`))
if (files.length > 0) {
return files[0];
}
throw TypeError(`${module?.data?.title} did not provide a changelog.md file`);
}).then(file => {
tracker[module?.data?.name] = {
version: module?.data?.version,
hasSeen: false
}
}).catch((error) => {
this.LOG(`${module?.data?.title} did not provide a changelog.md file`);
//this.LOG(error);
});
}
}else{
await this.getModuleMD(module?.data?.name, 'CHANGELOG').then(response => {
await FilePicker.browse('user', `./modules/${module?.data?.name}/`, { extensions: ['.md'] }).then(response => {
let files = response.files.filter(file => file.toLowerCase().includes(`changelog.md`))
if (files.length > 0) {
return files[0];
}
throw TypeError(`${module?.data?.title} did not provide a changelog.md file`);
}).then(file => {
tracker[module?.data?.name] = {
version: module?.data?.version,
hasSeen: false
}
}).catch((error) => {
this.LOG(`${module?.data?.title} did not provide a changelog.md file`);
//this.LOG(error);
});
}
};
Expand Down Expand Up @@ -181,7 +181,13 @@ class ModuleCredits extends MousesLib {
onclick: () => window.open(moduleData?.data?.readme, '_blank')
});
if (moduleCredits.setting('fetchLocalReadme')) {
this.getModuleMD(moduleData.data.name, 'README').then(response => {
FilePicker.browse('user', `./modules/${moduleData?.data?.name}/`, { extensions: ['.md'] }).then(response => {
let files = response.files.filter(file => file.toLowerCase().includes(`readme.md`))
if (files.length > 0) {
return files[0];
}
throw TypeError(`${moduleData?.data?.title} did not provide a readme.md file`);
}).then(file => {
$tag = tag({
text: 'text.readme.name',
isLocal: true,
Expand Down Expand Up @@ -223,7 +229,13 @@ class ModuleCredits extends MousesLib {
onclick: () => window.open(moduleData?.data?.changelog, '_blank')
});
if (moduleCredits.setting('fetchLocalChangelogs')) {
this.getModuleMD(moduleData?.data?.name, 'CHANGELOG').then(response => {
FilePicker.browse('user', `./modules/${moduleData?.data?.name}/`, { extensions: ['.md'] }).then(response => {
let files = response.files.filter(file => file.toLowerCase().includes(`changelog.md`))
if (files.length > 0) {
return files[0];
}
throw TypeError(`${moduleData?.data?.title} did not provide a changelog.md file`);
}).then(file => {
$tag = tag({
text: 'text.changelog.name',
isLocal: true,
Expand Down Expand Up @@ -383,10 +395,15 @@ class ModuleCreditsDialog extends FormApplication {

getData() {
return {
modules: this.modules.map(module => ({
...module,
hasSeen: module.type == 'changelog' ? moduleCredits.setting('trackedChangelogs')[module?.name].hasSeen : false
}))
modules: this.modules.map(module => {
let hasSeen = false;
if (typeof moduleCredits.setting('trackedChangelogs')[module?.name]?.hasSeen) hasSeen = moduleCredits.setting('trackedChangelogs')[module?.name]?.hasSeen

return {
...module,
hasSeen: hasSeen || false
}
})
};
}
activateListeners(html) {
Expand All @@ -412,26 +429,37 @@ class ModuleCreditsDialog extends FormApplication {
// Deactivate current Item
$element.closest('ul').find('li.active').removeClass('active');

fetch(`./modules/${module.name}/${module.type}.md`).then(response => {
if (response.status >= 200 && response.status <= 299) {
return response.text();
}
}).then(data => {
let changelog = DOMPurify.sanitize(marked(data), {USE_PROFILES: {html: true}});
let toggle = `<div class="module-credits-dialog-toggle"><i class="fas fa-chevron-circle-down"></i></div>`
$(html).find('main > .module-credits-dialog-title').html(`${toggle} ${module.title}`);
$(html).find('main .module-credits-dialog-content').html(changelog);
$listElement.addClass('active module-credits-dialog-has-seen-true').removeClass('module-credits-dialog-has-seen-false');

// Updated Tracked Modules!!
if (module.type == 'changelog') {
let trackedModules = moduleCredits.setting('trackedChangelogs');
trackedModules[module.name].hasSeen = true;
moduleCredits.setting('trackedChangelogs', trackedModules);
FilePicker.browse('user', `./modules/${module.name}/`, { extensions: ['.md'] }).then(response => {
let files = response.files.filter(file => file.toLowerCase().includes(`${module.type}.md`));
if (files.length > 0) {
return files[0];
}
throw TypeError(`no file matching ${module.type}.md`);
}).then(file => {
fetch(`./${file}`).then(response => {
if (response.status >= 200 && response.status <= 299) {
return response.text();
}
throw TypeError("did not provide a changelog.md file");
}).then(data => {
let changelog = DOMPurify.sanitize(marked(data), {USE_PROFILES: {html: true}});
let toggle = `<div class="module-credits-dialog-toggle"><i class="fas fa-chevron-circle-down"></i></div>`
$(html).find('main > .module-credits-dialog-title').html(`${toggle} ${module.title}`);
$(html).find('main .module-credits-dialog-content').html(changelog);
$listElement.addClass('active module-credits-dialog-has-seen-true').removeClass('module-credits-dialog-has-seen-false');

// Updated Tracked Modules!!
if (module.type == 'changelog') {
let trackedModules = moduleCredits.setting('trackedChangelogs');
trackedModules[module.name].hasSeen = true;
moduleCredits.setting('trackedChangelogs', trackedModules);
}
}).catch(error => {
//moduleCredits.LOG('ERROR', error);
})
}).catch(error => {
moduleCredits.LOG('ERROR', error);
})
//moduleCredits.LOG('ERROR', error);
});
}
});
// Activate first item in list
Expand Down

0 comments on commit d960fde

Please sign in to comment.