Browse Source

fix: Make showing/hiding the clock configurable #159

meetqy 1 year ago
parent
commit
514abf030c
4 changed files with 28 additions and 11 deletions
  1. 6 10
      src/UI/Settings/UIWindowSettings.js
  2. 0 1
      src/UI/UIDesktop.js
  3. 3 0
      src/UI/UITaskbar.js
  4. 19 0
      src/helpers.js

+ 6 - 10
src/UI/Settings/UIWindowSettings.js

@@ -133,9 +133,9 @@ async function UIWindowSettings(options){
                      h += `<div style="display: flex;align-items: center">`
                         h += `<span>${i18n('click_visable')}:</span>`
                         h += `<Select class="change-clock-visable" style="margin-left: 10px;flex: 1">`
-                            h += `<option value="auto" selected="${window.user_preferences.clock_visable === 'auto'}">${i18n('click_visable_auto')}</option>`
-                            h += `<option value="hide" selected="${window.user_preferences.clock_visable === 'hide'}">${i18n('click_visable_hide')}</option>`
-                            h += `<option value="show" selected="${window.user_preferences.clock_visable === 'show'}">${i18n('click_visable_show')}</option>`
+                            h += `<option value="auto">${i18n('click_visable_auto')}</option>`
+                            h += `<option value="hide">${i18n('click_visable_hide')}</option>`
+                            h += `<option value="show">${i18n('click_visable_show')}</option>`
                         h += `</Select>`
                      h += `</div>`
                 h += `</div>`;      
@@ -361,15 +361,11 @@ async function UIWindowSettings(options){
             const $this = $(this);  
             const value = $this.val();
 
-            value === 'show' && $('#clock').show();
-            value === 'hide' && $('#clock').hide();
-
-            // save clock_visable to user preferences
-            window.mutate_user_preferences({
-                clock_visable: value
-            });
+            changeClockVisable(value);
         })
 
+        change_clock_visable();
+
         resolve(el_window);
     });
 }

+ 0 - 1
src/UI/UIDesktop.js

@@ -1029,7 +1029,6 @@ async function UIDesktop(options){
             }
         })
     }
-
 }
 
 $(document).on('contextmenu taphold', '.taskbar', function(event){

+ 3 - 0
src/UI/UITaskbar.js

@@ -45,6 +45,9 @@ async function UITaskbar(options){
 
     $('.desktop').append(h);
 
+    // init clock visibility
+    window.change_clock_visable();
+
     //---------------------------------------------
     // add `Start` to taskbar
     //---------------------------------------------

+ 19 - 0
src/helpers.js

@@ -3676,4 +3676,23 @@ window.save_desktop_item_positions = ()=>{
 window.delete_desktop_item_positions = ()=>{
     desktop_item_positions = {}
     puter.kv.del('desktop_item_positions');
+}
+
+window.change_clock_visable = (clock_visable) => {
+    let newValue = clock_visable || window.user_preferences.clock_visable;
+    
+    newValue === 'show' && $('#clock').show();
+    newValue === 'hide' && $('#clock').hide();
+
+
+    if(clock_visable) {
+        // save clock_visable to user preferences
+        window.mutate_user_preferences({
+            clock_visable: newValue
+        });
+
+        return;
+    }
+
+    $('select.change-clock-visable').val(window.user_preferences.clock_visable);
 }