-
Notifications
You must be signed in to change notification settings - Fork 472
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
Changes from all commits
753a1c0
0a3a657
e199668
cf345bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,6 +212,34 @@ | |
</template> | ||
</div> | ||
</div> | ||
<div class="connectors"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as for the dark theme |
||
<div class="separator"> | ||
<i class="fas fa-times button clear" title="Reset all filters" on-click="clearFilters"></i> | ||
<label>Favorites</label> | ||
</div> | ||
<div class="scroll"> | ||
<template is="dom-repeat" items="[[ favoriteList ]]" filter="[[ filterConnectors(connectorPattern, selectedTags) ]]"> | ||
<div class$="card [[ getConnectorClass(selectedConnector, item) ]]" title$="Click to show mangas from this website Label: [[ item.label ]] ID: [[ item.id ]] URL: [[ item.url ]]" on-click="selectConnector"> | ||
<img class="icon" src$="[[ item.icon ]]" onerror="this.src='/img/connectors/default';" /> | ||
<div class="description"> | ||
<div class="heading"> | ||
<div class="title">[[ item.label ]]</div> | ||
<div class="control"> | ||
<i class$="fas fa-sign-in-alt link [[ getLoginClass(item.links) ]]" title="Click to open the login page" on-click="openLogin"></i> | ||
<i class$="fas fa-coffee link [[ getDonationClass(item.links) ]]" title="Click to open the donation page" on-click="openDonation"></i> | ||
<i class="fas fa-external-link-square-alt link active" title="Click to open the website in a new window This can be useful for various taks e.g. • Check / Investigate the website status • Bypass CloudFlare protection • Unlock a Captcha" on-click="openWebsite"></i> | ||
</div> | ||
</div> | ||
<div> | ||
<template is="dom-repeat" items="[[ item.tags ]]"> | ||
<span class="tag">[[ item ]]</span> | ||
</template> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
@@ -248,14 +276,16 @@ | |
this.popupVisibility = false; | ||
// list of all available connectors | ||
this.connectorList = []; | ||
this.favoriteList = []; | ||
// load connectors | ||
this.set( 'connectorList', Engine.Connectors ); | ||
this.set( 'favoriteList', Engine.Favorites ); | ||
this.tags = this.getAvailableTags(); | ||
this.selectedTags = []; | ||
} | ||
|
||
/** | ||
* | ||
* | ||
*/ | ||
getAvailableTags() { | ||
let tags = this.connectorList.reduce( ( accumulator, connector ) => { | ||
|
@@ -322,23 +352,23 @@ | |
evt.cancelBubble = true; | ||
evt.stopPropagation(); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
openWebsite(evt) { | ||
let item = evt.model.item; | ||
this._openLink(evt, item.url); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
openLogin(evt) { | ||
let links = evt.model.item.links; | ||
this._openLink(evt, links ? links.login : undefined); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
|
@@ -348,7 +378,7 @@ | |
} | ||
|
||
/** | ||
* | ||
* | ||
*/ | ||
toggleTag( event ) { | ||
event.model.item.selected = !event.model.item.selected; | ||
|
@@ -402,7 +432,7 @@ | |
} | ||
|
||
/** | ||
* | ||
* | ||
*/ | ||
clearFilters() { | ||
this.tags.forEach( tag => tag.selected = false); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ export default class Connectors { | |
constructor(ipc) { | ||
ipc.listen('on-connector-protocol-handler', this._onConnectorProtocolHandler.bind(this)); | ||
this._list = []; | ||
this._favlist = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed anymore if you accept the suggested change based on |
||
} | ||
|
||
async _loadPlugins(uri) { | ||
|
@@ -24,16 +25,22 @@ export default class Connectors { | |
]; | ||
let userPlugins = await this._loadPlugins('hakuneko://plugins/'); | ||
let internalPlugins = await this._loadPlugins('hakuneko://cache/mjs/connectors/'); | ||
let favoritePlugins = Engine.Storage.downloadedConnectors; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed anymore if you accept the suggested change based on |
||
|
||
await this.register(systemPlugins); | ||
await this.register(userPlugins); | ||
await this.register(internalPlugins); | ||
await this.registerfav(favoritePlugins); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed anymore if you accept the suggested change based on |
||
} | ||
|
||
get list() { | ||
return this._list; | ||
} | ||
|
||
get favlist() { | ||
return this._favlist; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just get the connector IDs of downloaded lists as suggested in let downloaded = Storage.getDownloadedConnectorIDs();
return this._list.filter(connector => downloaded.includes(connector.id)); |
||
} | ||
|
||
async register(files) { | ||
try { | ||
for(let file of files) { | ||
|
@@ -56,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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only part I'm not happy with, since original There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
async _onConnectorProtocolHandler(request) { | ||
try { | ||
let uri = new URL(request.url); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ export default class Storage { | |
this.fs = require( 'fs' ); | ||
this.path = require( 'path' ); | ||
this.config = this.path.join( electron.remote.app.getPath( 'userData' ), 'hakuneko.' ); | ||
this.root = electron.remote.app.getPath( 'userData'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. couldn't use |
||
this.temp = this.path.join( require( 'os' ).tmpdir(), 'hakuneko' ); | ||
this._createDirectoryChain( this.temp ); | ||
|
||
|
@@ -911,4 +912,18 @@ export default class Storage { | |
} ); | ||
} ); | ||
} | ||
|
||
get downloadedConnectors() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just return a list of connector IDs (string), makes further processing much simpler. |
||
//since this is a async function, isn't hakuneko startup waiting for this to be ran first? | ||
//seems like performance drain | ||
let rootDirectoryEntries = this._readDirectoryEntries(this.root); | ||
let arrayFiltered = []; | ||
rootDirectoryEntries.then(function(arrayRaw) { | ||
arrayRaw = arrayRaw.filter(plugin => plugin.startsWith('hakuneko.mangas.')); | ||
arrayRaw.forEach(file => { | ||
arrayFiltered.push('hakuneko://cache/mjs/connectors/' + file.substr(file.indexOf('.', 15)+1) + '.mjs'); | ||
}); | ||
}); | ||
return arrayFiltered; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this duplicated code should not be added.
Just introduce a new checkbox or something to toggle between the full list of websites and the websites that have been downloaded. In the code behind, assign the corresponding list to the property which is bound to the dom-repeat template in the UI.