-
-
Notifications
You must be signed in to change notification settings - Fork 241
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
Foreground detection mixin service for widgets #1404
Conversation
Job #444: Bundle Size — 10.75MB (~-0.01%).Changed metrics (2/10)
|
Good idea to provide this in a mixin 👍. If it works as expected from what I read in #1390, I'm going to use it for my sip widget as well. |
Thanks @hubsif , to implement you do something like this in your widget import foregroundService from '../widget-foreground-service'
export default {
mixins: [foregroundService],
name: 'OhVideoWebRTC',
methods: {
startForegroundActivity () {
this.startPlay()
},
stopForegroundActivity () {
this.stopPlay()
}
}
} there is also a variable |
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
75ee227
to
2d264c8
Compare
Yes, thank you! I had an idea of adding this to the widget mixin at first but subscribing to events unnecessarily was not the right way to go; making it separate is a good option. A minor remark is that |
mounted () { | ||
// determine the current page - support: https://caniuse.com/?search=closest | ||
this.pageEl = this.$el.closest('.page') | ||
const isPopup = this.$el.closest('.popup') !== null |
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.
Could you elaborate on this? I tested the original code with popups and found out that it seemed to work as expected?
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.
Yeah, it was working for me as well when i had the logic directly in my widget , but when using as a mixin, it was not finding the page-current
class.
I actually can't test this right now to show some examples, the build seems to be broken? I rebased to main
and now I am getting the error when running npm start
:
Module not found: Error: Can't resolve 'source-map-loader' in '/Users/daniel/openhab-main/git/openhab-webui/bundles/org.openhab.ui/web'
Along with a whole lot of other source-map-loader errors. I tried blowing away my node modules and reinstalling, and when that did not work, i cloned a clean copy of the repo, did a npm install
then npm start
and am seeing the same error.
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.
So it looks like this line
use: (env === 'development' || buildSourceMaps) ? ["source-map-loader"] : [], |
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.
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.
Along with a whole lot of other source-map-loader errors. I tried blowing away my node modules and reinstalling, and when that did not work, i cloned a clean copy of the repo, did a npm install then npm start and am seeing the same error.
Merged #1401 too fast I suppose - it only affects development and npm i source-map-loader
should also solve the problem for the time being (but the package.json should obviously include it so it's installed).
so back to the topic at hand, if i dump out the this.$el.closest('.page') to the console during a popup, you can see it does not contain the page-current class.
That would be another overlook - I'm assuming you want the widget to work when it's in a page presented as a popup. The original code works correctly when it's on a regular page and you open a popup over it; the activity (like playing a video) would be expected to continue because it might still be visible behind the popup, especially on desktops. And it does, because the pageBeforeOut
event is not called on the top-level page since it doesn't go away, another page is simply displayed on top (in the popup). Also the page-current
class is apparently only for top-level pages, and is not applied to popups.
So this "page-current
class means the page is already is the foreground" logic is wrong because it doesn't work with modals. Note that popups are not the only type of modals (sheets and popovers, albeit far less used) can be encountered as well.
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.
and npm i source-map-loader should also solve the problem for the time being
Yeah, that was the first thing i tried, but it led to some package conflict which i thought could happen when your npm cache is out of sync (it was not the issue in this case), so when trying from a fresh clone failed, I kinda gave up debugging the issue :-)
That would be another overlook - I'm assuming you want the widget to work when it's in a page presented as a popup.
i have only tried this PR running the widget in popups and in full pages, but not a page in a popup (or other modals)
So this "page-current class means the page is already is the foreground" logic is wrong
So does that mean this technique is not viable, or needs to be tweaked in your opinion?
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.
Continuing the conversation above with a suggestion:
mounted () { | ||
// determine the current page - support: https://caniuse.com/?search=closest | ||
this.pageEl = this.$el.closest('.page') | ||
const isPopup = this.$el.closest('.popup') !== null | ||
// start the foreground activity immediately if the page | ||
// is already in the foreground when the widget is mounted | ||
// or is being shown within a popup | ||
if (this.pageEl.classList.contains('page-current') || isPopup) { | ||
this.inForeground = true | ||
this.startForegroundActivity() | ||
} | ||
this.$f7.on('pageAfterIn', this.onPageAfterIn) | ||
this.$f7.on('pageBeforeOut', this.onPageBeforeOut) |
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.
mounted () { | |
// determine the current page - support: https://caniuse.com/?search=closest | |
this.pageEl = this.$el.closest('.page') | |
const isPopup = this.$el.closest('.popup') !== null | |
// start the foreground activity immediately if the page | |
// is already in the foreground when the widget is mounted | |
// or is being shown within a popup | |
if (this.pageEl.classList.contains('page-current') || isPopup) { | |
this.inForeground = true | |
this.startForegroundActivity() | |
} | |
this.$f7.on('pageAfterIn', this.onPageAfterIn) | |
this.$f7.on('pageBeforeOut', this.onPageBeforeOut) | |
mounted () { | |
const isInModal = this.$el.closest('.framework7-modals') | |
if (isInModal) { | |
this.startForegroundActivity() | |
return | |
} | |
this.pageEl = this.$el.closest('.page') | |
if (this.pageEl && this.pageEl.classList.contains('page-current')) { | |
this.startForegroundActivity() | |
} | |
this.$f7.on('pageAfterIn', this.onPageAfterIn) | |
this.$f7.on('pageBeforeOut', this.onPageBeforeOut) |
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.
Yeah, that was the first thing i tried, but it led to some package conflict which i thought could happen when your npm cache is out of sync (it was not the issue in this case), so when trying from a fresh clone failed, I kinda gave up debugging the issue :-)
This should probably be addressed asap as it's only useful to @stefan-hoehn at the moment and breaks the build for others.
So does that mean this technique is not viable, or needs to be tweaked in your opinion?
It's just a matter of making it work in as many combinations of pages & modals as possible. It would appear at mounting time modals are in the DOM under a background div with the framework7-modals
class (then they're moved elsewhere). There's no need to subscribe to events when in a modal, since they are temporary in nature and destroyed when closed. A caveat is that a modal may be covered by another modal (or navigate to a page while still in the background) but in this case the foreground activity won't stop.
The suggestion above seems to work in most cases:
@digitaldan as the feature freeze is imminent would be able to address the minor change above and use the mixin in #1386 in time? |
Signed-off-by: Yannick Schaus <github@schaus.net>
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.
@digitaldan as you're busy with the iOS app as discussed I finished this PR to include my earlier remark about modals. This PR can be safely merged because it is not currently used and won't even be compiled in before #1386 uses it.
Signed-off-by: Dan Cunningham dan@digitaldan.com