🐛 try again after some time in case tree-view takes a bit longer to load

This commit is contained in:
DrMaxNix 2023-05-15 13:30:48 +02:00
parent 5e7f29af9f
commit 53f78f40e9
3 changed files with 112 additions and 24 deletions

View File

@ -15,6 +15,8 @@ When the file is called `init.js`, add this snippet to the file:
```js
// RESET FLAG //
var codeRanOnce = false;
var tryTreeViewCloseInterval = null;
var tryTreeViewCloseIntervalCount = 0;
// EXECUTE CODE WHEN WORKSPACE IS OPENED //
@ -27,23 +29,46 @@ atom.workspace.onDidOpen(function({item}){
// check whether the `Hidden On Startup` setting is activated
if(atom.packages.config.settings["tree-view"].hiddenOnStartup || false){
// get tree-view element
var treeView = atom.workspace.paneContainerForURI("atom://tree-view");
// close the tree-view dock
treeView.hide();
// schedule multiple tries to close the tree-view
tryTreeViewClose();
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100);
}
});
// TRY TO CLOSE THE TREE-VIEW //
tryTreeViewClose = function(){
// get tree-view element
var treeView = atom.workspace.paneContainerForURI("atom://tree-view");
// time out after too many tries
tryTreeViewCloseIntervalCount++;
if(tryTreeViewCloseIntervalCount >= 20){
clearInterval(tryTreeViewCloseInterval);
return;
}
// check if tree-view element exists
if(!treeView) return;
// close the tree-view dock
treeView.hide();
// stop trying
clearInterval(tryTreeViewCloseInterval);
}
```
When the file is called `init.coffee`, add this snippet to the file:
```coffee
## RESET FLAG ##
## RESET ##
codeRanOnce = false
tryTreeViewCloseInterval = null
tryTreeViewCloseIntervalCount = 0
## EXECUTE CODE WHEN WORKSPACE IS OPENED ##
atom.workspace.onDidOpen ({item}) ->
atom.workspace.onDidOpen({item}) ->
# make sure the code doesn't run twice
if codeRanOnce then return
@ -52,11 +77,30 @@ atom.workspace.onDidOpen ({item}) ->
# check whether the `Hidden On Startup` setting is activated
if atom.packages.config.settings["tree-view"].hiddenOnStartup || false
# get tree-view element
treeView = atom.workspace.paneContainerForURI("atom://tree-view")
# close the tree-view dock
treeView.hide()
# schedule multiple tries to close the tree-view
tryTreeViewClose()
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100)
## TRY TO CLOSE THE TREE-VIEW ##
tryTreeViewClose = () ->
# get tree-view element
treeView = atom.workspace.paneContainerForURI("atom://tree-view")
# time out after too many tries
tryTreeViewCloseIntervalCount++
if tryTreeViewCloseIntervalCount >= 20
clearInterval(tryTreeViewCloseInterval)
return;
# check if tree-view element exists
if !treeView then return;
# close the tree-view dock
treeView.hide()
# stop trying
clearInterval(tryTreeViewCloseInterval)
```
Now you can configure whether you want the tree-view to be hidden on startup in the settings of the `tree-view` package:

View File

@ -1,9 +1,11 @@
## RESET FLAG ##
## RESET ##
codeRanOnce = false
tryTreeViewCloseInterval = null
tryTreeViewCloseIntervalCount = 0
## EXECUTE CODE WHEN WORKSPACE IS OPENED ##
atom.workspace.onDidOpen ({item}) ->
atom.workspace.onDidOpen({item}) ->
# make sure the code doesn't run twice
if codeRanOnce then return
@ -12,8 +14,27 @@ atom.workspace.onDidOpen ({item}) ->
# check whether the `Hidden On Startup` setting is activated
if atom.packages.config.settings["tree-view"].hiddenOnStartup || false
# get tree-view element
treeView = atom.workspace.paneContainerForURI("atom://tree-view")
# close the tree-view dock
treeView.hide()
# schedule multiple tries to close the tree-view
tryTreeViewClose()
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100)
## TRY TO CLOSE THE TREE-VIEW ##
tryTreeViewClose = () ->
# get tree-view element
treeView = atom.workspace.paneContainerForURI("atom://tree-view")
# time out after too many tries
tryTreeViewCloseIntervalCount++
if tryTreeViewCloseIntervalCount >= 20
clearInterval(tryTreeViewCloseInterval)
return;
# check if tree-view element exists
if !treeView then return;
# close the tree-view dock
treeView.hide()
# stop trying
clearInterval(tryTreeViewCloseInterval)

View File

@ -1,5 +1,7 @@
// RESET FLAG //
var codeRanOnce = false;
var tryTreeViewCloseInterval = null;
var tryTreeViewCloseIntervalCount = 0;
// EXECUTE CODE WHEN WORKSPACE IS OPENED //
@ -12,10 +14,31 @@ atom.workspace.onDidOpen(function({item}){
// check whether the `Hidden On Startup` setting is activated
if(atom.packages.config.settings["tree-view"].hiddenOnStartup || false){
// get tree-view element
var treeView = atom.workspace.paneContainerForURI("atom://tree-view");
// close the tree-view dock
treeView.hide();
// schedule multiple tries to close the tree-view
tryTreeViewClose();
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100);
}
});
// TRY TO CLOSE THE TREE-VIEW //
tryTreeViewClose = function(){
// get tree-view element
var treeView = atom.workspace.paneContainerForURI("atom://tree-view");
// time out after too many tries
tryTreeViewCloseIntervalCount++;
if(tryTreeViewCloseIntervalCount >= 20){
clearInterval(tryTreeViewCloseInterval);
return;
}
// check if tree-view element exists
if(!treeView) return;
// close the tree-view dock
treeView.hide();
// stop trying
clearInterval(tryTreeViewCloseInterval);
}