From 352a6d9238a9a0fadbdcea512919d2d5fae25a47 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 23 Feb 2017 00:40:32 +0530 Subject: [PATCH] A randomly generated device id that persists in local storage --- src/pyj/session.pyj | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pyj/session.pyj b/src/pyj/session.pyj index 215a15e795..8bb954a57a 100644 --- a/src/pyj/session.pyj +++ b/src/pyj/session.pyj @@ -1,9 +1,12 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2015, Kovid Goyal -from __python__ import hash_literals, bound_methods +from __python__ import bound_methods, hash_literals + +from uuid import short_uuid from ajax import ajax_send + defaults = { # Book list settings 'view_mode': 'cover_grid', @@ -45,6 +48,7 @@ is_local_setting = { 'base_font_size': True, } + def storage_available(which): which = which or 'localStorage' try: @@ -134,6 +138,18 @@ def local_storage(): local_storage.storage = SessionData('calibre-local-') return local_storage.storage + +def get_device_uuid(): + if not get_device_uuid.ans: + s = local_storage() + ans = s.get('device_uuid') + if not ans: + ans = short_uuid() + s.set('device_uuid', ans) + get_device_uuid.ans = ans + return get_device_uuid.ans + + default_interface_data = { 'username': None, 'output_format': 'EPUB',