Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ export const DEFAULT_SERVICE_SETTINGS = {
darkReaderBrightness: 100,
darkReaderContrast: 90,
darkReaderSepia: 10,
pollDelay: 2000 /* 2000ms */,
};

export const DEFAULT_SHORTCUTS = {
Expand Down
5 changes: 5 additions & 0 deletions src/models/Recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface RecipeData {
local?: boolean;
message?: string;
allowFavoritesDelineationInUnreadCount?: boolean;
pollDelay?: number;
};
defaultIcon: string;
}
Expand All @@ -51,6 +52,7 @@ export interface IRecipe {
partition: string;
local: boolean;
defaultIcon: string;
pollDelay: number;

readonly overrideUserAgent?: () => string;

Expand Down Expand Up @@ -113,6 +115,8 @@ export default class Recipe implements IRecipe {

partition = '';

pollDelay = DEFAULT_SERVICE_SETTINGS.pollDelay;

// TODO: Is this being used?
local = false;

Expand Down Expand Up @@ -188,6 +192,7 @@ export default class Recipe implements IRecipe {
data.config.allowFavoritesDelineationInUnreadCount,
this.allowFavoritesDelineationInUnreadCount,
);
this.pollDelay = ifUndefined<number>(data.config.pollDelay, this.pollDelay);

// computed
this.path = data.path;
Expand Down
8 changes: 7 additions & 1 deletion src/models/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export default class Service {

@observable lastHibernated: number | null = null; // timestamp

@observable pollDelay: number = DEFAULT_SERVICE_SETTINGS.pollDelay; // interval for Recipe Polling

@observable lastPoll: number = Date.now();

@observable lastPollAnswer: number = Date.now();
Expand Down Expand Up @@ -237,7 +239,11 @@ export default class Service {
data.isWakeUpEnabled,
this.isWakeUpEnabled,
);

this.pollDelay = ifUndefined<number>(
recipe.pollDelay <= data.pollDelay ? data.pollDelay : recipe.pollDelay,
Copy link
Member

Choose a reason for hiding this comment

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

At the current state of things, this has no impact because you don't allow the user to modify the value. In order for it to do something you need to modify the files EditServiceForm.tsx and EditServiceScreen.tsx in order to add a field where the user can input the value (which will appear on the window that allows for adding/modifying a service). Make sure to validate the value entered appropriately.

As for this line explicitly: why would you prevent a user from entering a value smaller than what the recipe suggests? At the current stage, since no recipe has a given value, the polling time is the default 2sec, and users would like to poll more often. This would prevent the user to input a lower value when initially creating the service.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @Alphrag
I already made some changes (I would like to improve my knowledge of Ferdium) and this is a first result
Poll Delay (ms)
In this case, can be an useful integration add a switch (Enable/Disable Poll Delay) and show this customization only if the user would like to personalize the delay of the poll

Also, than you have more experiences on this project, did you know some validation (already coded) for numeric input? I'm asking this, because I can't found nothing about. I would like to avoid duplicated code.

Thanks

Copy link
Member

Choose a reason for hiding this comment

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

Great!
I leave the decision to you to either add a switch to enable/disable custom poll delay (where toggling off resets to the recipe's poll delay value), or to simply allow an empty value, which is the default and corresponds to the recipe's delay. We do the latter in other places of the code, for example, to handle the accentColor field on the general settings, and the important part is how we validate that field —which in that case required dynamic handling whereas here we won't need that (cf EditSettingsForm.tsx)—.

I honestly don't remember of having a specific function that validates numeric input (they would normally be located in the helpers folder) and since you simply need to check the value that is passed is an integer, a Number.isInteger check would probably suffice, don't you think?

this.pollDelay,
);
// console.log('ctor-recipe', recipe);
Copy link
Member

Choose a reason for hiding this comment

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

Please remove comments used to test out things.

// Check if "Hibernate on Startup" is enabled and hibernate all services except active one
const { hibernateOnStartup } = window['ferdium'].stores.settings.app;
// The service store is probably not loaded yet so we need to use localStorage data to get active service
Expand Down
5 changes: 2 additions & 3 deletions src/stores/ServicesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ export default class ServicesStore extends TypedStore {
spellcheckerLanguage:
SPELLCHECKER_LOCALES[this.stores.settings.app.spellcheckerLanguage],
userAgentPref: '',
pollDelay: DEFAULT_SERVICE_SETTINGS.pollDelay,
...serviceData,
};

Expand Down Expand Up @@ -1440,8 +1441,6 @@ export default class ServicesStore extends TypedStore {
_initRecipePolling(serviceId: string) {
const service = this.one(serviceId);

const delay = ms('2s');

if (service) {
if (service.timer !== null) {
clearTimeout(service.timer);
Expand All @@ -1452,7 +1451,7 @@ export default class ServicesStore extends TypedStore {

service.webview.send('poll');

service.timer = setTimeout(loop, delay);
service.timer = setTimeout(loop, service.pollDelay);
service.lastPoll = Date.now();
};

Expand Down
7 changes: 6 additions & 1 deletion src/webview/lib/RecipeWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ class RecipeWebview {
* Initialize the loop
*
* @param {Function} Function that will be executed
* @param {String} Interval which drive the loop in `ms` library format
*/
loop(fn) {
loop(fn, interval) {
if (interval && typeof interval === 'string') {
ipcRenderer.sendToHost('set-loop-delay', interval);
}
Comment on lines +63 to +66
Copy link
Member

Choose a reason for hiding this comment

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

If you really want to make a change happen from the recipe webview, I would prefer you to create a new function there like setPollDelay instead of modifying the loop one. However, I am not sure even this is worth it: see my general comment for the reason and discussion.

Copy link
Member

Choose a reason for hiding this comment

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

Now that you've removed the listener set-loop-delay and implemented it in the recipe settings, you can revert this file back to what it was, removing your modifications.


this.loopFunc = fn;
}

Expand Down