Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to see connectors that have been downloaded #1456

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/app/ElectronBootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ module.exports = class ElectronBootstrap {
];
this._directoryMap = {
'cache': this._configuration.applicationCacheDirectory,
'plugins': this._configuration.applicationUserPluginsDirectory,
'root': this._configuration.applicationUserDataDirectory
'plugins': this._configuration.applicationUserPluginsDirectory
};
this._appIcon;
this._minimizeToTray = false; // only supported when tray is shown
Expand Down
4 changes: 3 additions & 1 deletion src/web/lib/hakuneko/frontend@classic-dark/connectors.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,11 @@
this.favoriteList = [];
// load connectors
this.set( 'connectorList', Engine.Connectors );
this.set( 'favoriteList', Engine.Storage.downloadedConnectors );
this.set( 'favoriteList', Engine.Favorites );
this.tags = this.getAvailableTags();
this.selectedTags = [];
console.log(this.connectorList);
console.log(this.favoriteList);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/web/mjs/HakuNeko.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import BookmarkImporter from './engine/BookmarkImporter.mjs';
import BookmarkManager from './engine/BookmarkManager.mjs';
import ChaptermarkManager from './engine/ChaptermarkManager.mjs';
import Connectors from './engine/Connectors.mjs';
import Favorites from './engine/Favorites.mjs';
import DownloadManager from './engine/DownloadManager.mjs';
//import HistoryWorker from './engine/HistoryWorker.mjs'
import Request from './engine/Request.mjs';
Expand All @@ -23,14 +22,12 @@ export default class HakuNeko {

this._version = Version;
this._enums = Enums;

let ipc = new InterProcessCommunication();
this._blacklist = new Blacklist();
this._downloadManager = new DownloadManager();
this._settings = new Settings();
this._request = new Request(ipc, this._settings);
this._connectors = new Connectors(ipc);
this._favorites = new Favorites(ipc);
this._storage = new Storage();
this._bookmarkManager = new BookmarkManager(this._settings, new BookmarkImporter());
this._chaptermarkManager = new ChaptermarkManager(this._settings);
Expand All @@ -53,7 +50,6 @@ export default class HakuNeko {

async initialize() {
await this._connectors.initialize();
await this._favorites.initialize();
}

get Blacklist() {
Expand All @@ -73,7 +69,7 @@ export default class HakuNeko {
}

get Favorites() {
return this._connectors.favoriteList;
return this._connectors.favlist;
}

get DownloadManager() {
Expand Down
35 changes: 29 additions & 6 deletions src/web/mjs/engine/Connectors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default class Connectors {
constructor(ipc) {
ipc.listen('on-connector-protocol-handler', this._onConnectorProtocolHandler.bind(this));
this._list = [];
this._favList = [];
this._favlist = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore if you accept the suggested change based on Storage.mjs

}

async _loadPlugins(uri) {
Expand All @@ -25,20 +25,20 @@ export default class Connectors {
];
let userPlugins = await this._loadPlugins('hakuneko://plugins/');
let internalPlugins = await this._loadPlugins('hakuneko://cache/mjs/connectors/');
let favoritePlugins = Storage.downloadedConnectors;
let favoritePlugins = Engine.Storage.downloadedConnectors;
Copy link
Contributor

@ronny1982 ronny1982 Apr 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore if you accept the suggested change based on Storage.mjs


await this.register(systemPlugins);
await this.register(userPlugins);
await this.register(internalPlugins);
await this.register(favoritePlugins);
await this.registerfav(favoritePlugins);
Copy link
Contributor

@ronny1982 ronny1982 Apr 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore if you accept the suggested change based on Storage.mjs

}

get list() {
return this._list;
}

get favoriteList() {
return this._favList;
get favlist() {
return this._favlist;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just get the connector IDs of downloaded lists as suggested in Storage.mjs and then filter the full list based of the downloaded...
e.g.

let downloaded = Storage.getDownloadedConnectorIDs();
return this._list.filter(connector => downloaded.includes(connector.id));

}

async register(files) {
Expand All @@ -63,7 +63,30 @@ export default class Connectors {
console.warn(`Failed to load connector`, error);
}
}


async registerfav(files) {
try {
for(let file of files) {
try {
let module = await import(file);
let connector = new module.default();
if(this._favlist.find(c => c.id === connector.id)) {
console.warn(`The connector "${connector.label}" with ID "${connector.id}" is already registered`);
} else {
this._favlist.push(connector);
}
} catch(error) {
console.warn(`Failed to load connector "${file}"`, error);
}
}
this._favlist.sort( ( a, b ) => {
return ( a.label.toLowerCase() < b.label.toLowerCase() ? -1 : 1 );
} );
} catch(error) {
console.warn(`Failed to load connector`, error);
}
}

Comment on lines +67 to +89
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only part I'm not happy with, since original register(files) uses this._list (which can't be rewritten) I've had to create a new register function.

Copy link
Contributor

@ronny1982 ronny1982 Apr 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method is not needed anymore if you accept the suggested change based on Storage.mjs

async _onConnectorProtocolHandler(request) {
try {
let uri = new URL(request.url);
Expand Down
66 changes: 0 additions & 66 deletions src/web/mjs/engine/Favorites.mjs

This file was deleted.

10 changes: 4 additions & 6 deletions src/web/mjs/engine/Storage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -918,14 +918,12 @@ export default class Storage {
//seems like performance drain
let rootDirectoryEntries = this._readDirectoryEntries(this.root);
let arrayFiltered = [];
rootDirectoryEntries.then(function(arrayRaw){
rootDirectoryEntries.then(function(arrayRaw) {
arrayRaw = arrayRaw.filter(plugin => plugin.startsWith('hakuneko.mangas.'));
arrayRaw.forEach(file => {
arrayFiltered.push(file.substr(file.indexOf('.', 15)+1));
arrayFiltered.push('hakuneko://cache/mjs/connectors/' + file.substr(file.indexOf('.', 15)+1) + '.mjs');
});
return arrayFiltered;
})


});
return arrayFiltered;
}
}