Skip to content

kosync.koplugin: Add custom hostname option for kosync plugin#14172

Merged
Frenzie merged 7 commits into
koreader:masterfrom
rspilk:master
Feb 4, 2026
Merged

kosync.koplugin: Add custom hostname option for kosync plugin#14172
Frenzie merged 7 commits into
koreader:masterfrom
rspilk:master

Conversation

@rspilk

@rspilk rspilk commented Aug 15, 2025

Copy link
Copy Markdown
Contributor

Adds a custom hostname option for the kosync plugin. This feature allows a user-defined device name to be set in settings.reader.lua, which is then used instead of the default Device.model value for progress updates sent to the kosync server. This provides a more explicit way to identify a device, which is useful when syncing across multiple readers.

The feature is backward compatible; if no custom hostname is set, it defaults to the existing Device.model behavior. This has been tested and confirmed to be working with koreader/kosync:latest (VERSION=1.0.1.3)


This change is Reviewable

Comment thread plugins/kosync.koplugin/main.lua Outdated

function KOSync:setHostname(hostname)
logger.dbg("KOSync: Setting custom hostname to:", hostname)
self.settings.kosync_hostname = hostname ~= "" and hostname or nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To delete the custom hostname you need to allow blank input:

callback = function()
if input.allow_blank_input or self.input_dialog:getInputText() ~= "" then
input.callback(self.input_dialog:getInputText())
self:closeInputDialog()
end
end,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rspilk Could you please resolve this? If I understand correctly it only needs to be made simpler like this?

Suggested change
self.settings.kosync_hostname = hostname ~= "" and hostname or nil
self.settings.kosync_hostname = hostname

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This this cause hostname to be reevaluated as Device.model though? I thought it had to be nil in order for that to work and leaving it empty would be ""?

I looked at adding allow_blank_input = true into the tap input function but I couldn't seem to make that work in my testing. I will try a bit on it this weekend when I have a bit of time to put into getting my environment set up again

@rspilk

rspilk commented Dec 17, 2025

Copy link
Copy Markdown
Contributor Author

I made an additional change to the main.lua. The menu function relies on input not being blank for the other elements. I thought making this change to the one section of the menu was a better option than globally affecting the menu allowing blank entries but I am open to hearing what you think. Now making it empty reverts back to Device.model or syncs with whatever you enter in the field.

I am also not sure how a pull request works now that the master branch has moved on but i dont believe the file has been modified otherwise

@rspilk

rspilk commented Dec 17, 2025

Copy link
Copy Markdown
Contributor Author
Screenshot_20251217-132057

Comment thread plugins/kosync.koplugin/main.lua Outdated
return {
callback = function()
local dialog
dialog = MultiInputDialog:new{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

MultiInputDialog with one field is InputDialog.

Comment thread plugins/kosync.koplugin/main.lua Outdated
title = _("Hostname for sync"),
fields = {
{
text = self.settings.kosync_hostname or "",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need for or, the input accepts nil.

Comment thread plugins/kosync.koplugin/main.lua Outdated
self.settings.custom_server = server ~= "" and server or nil
end

function KOSync:setHostname(hostname)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just 2 lines, the method isn't called anywhere else, can de done right in the callback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see, you follow the style of the module, okay.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see, you follow the style of the module, okay.

Is that the case? There's still a difference between having a function with only a couple of lines and having a function that's only called from a single spot. But yeah, getters and setters for everything even when nothing's happening yet is this Java/OOP pattern I'm not really into either.

@rspilk

rspilk commented Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

I made a change to the plugin to use the InputDialog function instead of MultiInput. I also followed the advice to remove the function and perform directly in the callback, its cleaner but it is slightly different than some of the other stylings. I don't care either way so I could revert it.

Also noticed that InputDialog uses the name "input_hint" for its hinting and MultiInputDialog uses "hint" so i modified to accommodate that. Thats probably a bigger UI change that would have to be made to fix that globally.

@hius07

hius07 commented Dec 18, 2025

Copy link
Copy Markdown
Member

I'm not sure that I'm happy with the latest massive style editing.

@Frenzie

Frenzie commented Dec 18, 2025

Copy link
Copy Markdown
Member

Me neither. ;-)

@rspilk rspilk force-pushed the master branch 2 times, most recently from 9360e2b to edefb07 Compare February 3, 2026 23:31
@rspilk

rspilk commented Feb 3, 2026

Copy link
Copy Markdown
Contributor Author

Fixed that

Sorry about the accidental reformatting. The diff should now only contain the intended logic changes.

Comment thread plugins/kosync.koplugin/main.lua Outdated
end,
},
{
text = _("Device Hostname"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lowercase hostname

…Dialog. Additionally use inline callback rather than a whole placeholder function.
@Frenzie Frenzie added this to the 2026.02 milestone Feb 4, 2026
@rspilk

rspilk commented Feb 4, 2026

Copy link
Copy Markdown
Contributor Author

The build failed after modifying that string?

@Frenzie

Frenzie commented Feb 4, 2026

Copy link
Copy Markdown
Member

I'm not immediately sure what you're referring to. I only see green checkmarks on pretty much every commit?

@Frenzie Frenzie merged commit 9eedae3 into koreader:master Feb 4, 2026
2 checks passed
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants