(reveal = false)
| 100 | * @returns {Promise<void>} |
| 101 | */ |
| 102 | const Tab = async (reveal = false): Promise<void> => { |
| 103 | const _preference = await Storage.get('preference'); |
| 104 | const defaultTabsInfo = { |
| 105 | focus: '1', |
| 106 | tabs: { |
| 107 | 1: { |
| 108 | position: 'xplorer://Home', |
| 109 | history: ['xplorer://Home'], |
| 110 | currentIndex: 0, |
| 111 | }, |
| 112 | }, |
| 113 | focusHistory: [1], |
| 114 | latestIndex: 1, |
| 115 | }; // default tabs information |
| 116 | if ((_preference?.on_startup ?? 'new') === 'new') { |
| 117 | // Store default tabs information into local storage |
| 118 | Storage.set(`tabs-${windowName}`, defaultTabsInfo); |
| 119 | tabsManager.setAttribute('data-tauri-drag-region', ''); |
| 120 | } else { |
| 121 | const tabsInfo = await Storage.get(`tabs-${windowName}`); |
| 122 | if (!tabsInfo.tabs || reveal) { |
| 123 | Storage.set(`tabs-${windowName}`, defaultTabsInfo); |
| 124 | tabsManager.setAttribute('data-tauri-drag-region', ''); |
| 125 | Home(); |
| 126 | } else { |
| 127 | let _first = true; |
| 128 | const createNewTabElement = document.querySelector('.create-new-tab'); |
| 129 | for (const index in Object.keys(tabsInfo.tabs)) { |
| 130 | if (_first) { |
| 131 | if (Object.keys(tabsInfo.tabs).length > 1) { |
| 132 | const tabIndex = Object.keys(tabsInfo.tabs)[index]; |
| 133 | const tabPosition = tabsInfo.tabs[Object.keys(tabsInfo.tabs)[index]].position; |
| 134 | document.querySelector('#tab1').id = `tab${tabIndex}`; |
| 135 | document.getElementById(`tab${tabIndex}`).querySelector<HTMLInputElement>('#tab-position').innerText = await Translate( |
| 136 | basename(tabPosition) === '' ? tabPosition : basename(tabPosition) |
| 137 | ); |
| 138 | } else { |
| 139 | document.querySelector('#tab1').id = `tab${Object.keys(tabsInfo.tabs)[index]}`; |
| 140 | await OpenDir(tabsInfo.tabs[Object.keys(tabsInfo.tabs)[index]].position, false, true); |
| 141 | } |
| 142 | _first = false; |
| 143 | } else { |
| 144 | const tabIndex = Object.keys(tabsInfo.tabs)[index]; |
| 145 | const tabPosition = tabsInfo.tabs[Object.keys(tabsInfo.tabs)[index]].position; |
| 146 | const newTab = document.createElement('div'); |
| 147 | newTab.classList.add('tab'); |
| 148 | newTab.classList.add('tab-hover-effect'); |
| 149 | newTab.innerHTML = `<span id='tab-position'>${await Translate('Home')}</span><span class='close-tab-btn'>×</span>`; |
| 150 | newTab.dataset.tabIndex = tabIndex; |
| 151 | newTab.id = `tab${tabIndex}`; |
| 152 | |
| 153 | createNewTabElement.parentElement.insertBefore(newTab, createNewTabElement); // Insert the new tab |
| 154 | OpenDir(tabPosition ?? 'xplorer://Home'); |
| 155 | document.getElementById(`tab${tabIndex}`).querySelector<HTMLInputElement>('#tab-position').innerText = await Translate( |
| 156 | basename(tabPosition) === '' ? tabPosition : basename(tabPosition) |
| 157 | ); |
| 158 | } |
| 159 | } |
no test coverage detected