-
Notifications
You must be signed in to change notification settings - Fork 55
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
Allow registering aliases without components #49
Conversation
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
@skjnldsv I get
|
Don't register a mime, only the alias :) |
@skjnldsv
|
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
I pushed a fix, you should be able to register without a group (not needed for you since you want the media group I assume) and without a mimes array :) |
@skjnldsv Thanks. It works fine now with only id and mimeAliases. I still get |
With that? I don't have the issue. Did you build the viewer app ? OCA.Viewer.registerHandler({
id: 'camerarawpreviews',
mimesAliases: {
'image/x-dcraw': 'image/jpeg'
}
}) |
@skjnldsv Only doing it in the app. My code is only ran once. This branch is built. If I try directly in the console there is no issue, but when doing it with DOMContentLoaded there is. document.addEventListener("DOMContentLoaded", function() {
if (OCA.Viewer) {
console.log("TEST")
OCA.Viewer.registerHandler({
id: 'camerarawpreviews',
mimesAliases: {
'image/x-dcraw': 'image/jpeg'
}
})
}
}); I only see "TEST" once in the console. |
Works here 🤷♀️ |
@skjnldsv It's a race condition between watch.handlers and beforeMount. |
@skjnldsv document.addEventListener("DOMContentLoaded", function() {
if (OCA.Viewer) {
setTimeout(function () {
OCA.Viewer.registerHandler({
id: 'camerarawpreviews',
mimesAliases: {
'image/x-dcraw': 'image/jpeg'
}
})
}, 0);
}
}); |
@skjnldsv if(this.registeredHandlers.indexOf(handler.id) === -1) {
this.registerHandler(handler)
} |
@@ -219,9 +225,10 @@ export default { | |||
modal: this.components[mime], | |||
loaded: false | |||
} | |||
this.updatePreviousNext() | |||
} else { | |||
console.error(`The following file could not be displayed because to view matches its mime type`, fileName, fileInfo) |
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.
I feel this could be easier written?
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.
This is meant to be a dev debug. Since no regular user would open the console I guess 🤔
But I've always been terrible at writing error messages, so feel free to suggest a simpler one 😁
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.
@skjnldsv Hey no worries. I thought it was just unclear what it said. I am actually struggling understanding: "because to view matches". What about this: "The following file could not be displayed due to it's mime type"?
@skjnldsv diff --git a/src/views/Viewer.vue b/src/views/Viewer.vue
index 722d284..863c2d6 100644
--- a/src/views/Viewer.vue
+++ b/src/views/Viewer.vue
@@ -158,8 +158,11 @@ export default {
watch: {
// make sure any late external app can register handlers
- handlers: function() {
- this.registerHandler(this.handlers[this.handlers.length - 1])
+ handlers: {
+ handler: function() {
+ this.registerHandler(this.handlers[this.handlers.length - 1])
+ },
+ immediate: false
}
}, |
What is the error on your side then? |
@skjnldsv Sorry my fix in the watch.handlers did not do anything I am afraid. |
@skjnldsv Confirmed good fix: diff --git a/src/views/Viewer.vue b/src/views/Viewer.vue
index 722d284..474336e 100644
--- a/src/views/Viewer.vue
+++ b/src/views/Viewer.vue
@@ -106,6 +106,7 @@ export default {
},
data: () => ({
+ loaded: false,
handlers: OCA.Viewer.availableHandlers,
components: {},
@@ -159,7 +160,9 @@ export default {
watch: {
// make sure any late external app can register handlers
handlers: function() {
- this.registerHandler(this.handlers[this.handlers.length - 1])
+ if (this.loaded) {
+ this.registerHandler(this.handlers[this.handlers.length - 1])
+ }
}
},
@@ -169,6 +172,7 @@ export default {
this.handlers.forEach(handler => {
this.registerHandler(handler)
})
+ this.loaded = true
})
window.addEventListener('resize', this.onResize) |
No this is not the fix we're looking for I think. 🙈 The question is why does the watch gets trigered after the handler is already registered (though this is not really an issue, since it's just a warning that state that the viewer won't register the camerapreview again since it already exists) I'd say, we should merge this and open an issue to properly investigate why the watcher gets fired despite being handled after the domReadyContent. What do you say? The current state of this pr is working for you, right? Aside from the console message? |
Yes we can merge it. I am not sure what you mean with the fix. With the fix it works both asynchronously and with DOMContentLoaded. Just not asynchronously before DOMContentLoaded. |
DOMContentLoaded is mandatory anyway :) |
@cowai I ended up using your fix in #73 :) And sorry if I sounded harsh on my previous comments. I came back to this issue and while reading them, I was not happy with the way I wrote them. I'm very happy of all the help and suggestions you gave me! |
@skjnldsv No worries. I did not think that at all ;) |
@cowai glad to hear!! Thanks 😉 |
Signed-off-by: John Molakvoæ (skjnldsv) [email protected]