Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
烟灰好
edex-ui
提交
3810f5c3
E
edex-ui
项目概览
烟灰好
/
edex-ui
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
edex-ui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3810f5c3
编写于
1月 29, 2019
作者:
G
GitSquared
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🎨
Reduce callback hell in fsDisp & fix #408
Sweet async/await
上级
3262679e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
152 addition
and
132 deletion
+152
-132
src/classes/filesystem.class.js
src/classes/filesystem.class.js
+152
-132
未找到文件。
src/classes/filesystem.class.js
浏览文件 @
3810f5c3
...
...
@@ -52,6 +52,25 @@ class FilesystemDisplay {
}
},
1000
);
this
.
_asyncFSwrapper
=
new
Proxy
(
fs
,
{
get
:
function
(
fs
,
prop
)
{
if
(
prop
in
fs
)
{
return
function
(...
args
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fs
[
prop
](...
args
,
(
err
,
d
)
=>
{
if
(
typeof
err
!==
"
undefined
"
&&
err
!==
null
)
reject
(
err
);
if
(
typeof
d
!==
"
undefined
"
)
resolve
(
d
);
if
(
typeof
d
===
"
undefined
"
&&
typeof
err
===
"
undefined
"
)
resolve
();
});
});
}
}
},
set
:
function
()
{
return
false
;
}
});
this
.
setFailedState
=
()
=>
{
this
.
failed
=
true
;
container
.
innerHTML
=
`
...
...
@@ -88,151 +107,152 @@ class FilesystemDisplay {
});
};
this
.
readFS
=
(
dir
)
=>
{
this
.
readFS
=
async
dir
=>
{
if
(
this
.
failed
===
true
)
return
false
;
let
tcwd
=
dir
;
fs
.
readdir
(
tcwd
,
(
err
,
content
)
=>
{
if
(
err
!==
null
)
{
console
.
warn
(
err
);
if
(
this
.
_noTracking
===
true
&&
this
.
dirpath
)
{
// #262
this
.
setFailedState
();
setTimeout
(()
=>
{
this
.
readFS
(
this
.
dirpath
);
},
1000
);
}
else
{
this
.
setFailedState
();
}
let
content
=
await
this
.
_asyncFSwrapper
.
readdir
(
tcwd
).
catch
(
err
=>
{
console
.
warn
(
err
);
if
(
this
.
_noTracking
===
true
&&
this
.
dirpath
)
{
// #262
this
.
setFailedState
();
setTimeout
(()
=>
{
this
.
readFS
(
this
.
dirpath
);
},
1000
);
}
else
{
this
.
cwd
=
[];
this
.
_tmp
=
{
dirs
:
[],
symlinks
:
[],
files
:
[],
others
:
[]
};
let
i
=
0
;
content
.
forEach
(
file
=>
{
fs
.
lstat
(
path
.
join
(
tcwd
,
file
),
(
err
,
fstat
)
=>
{
if
(
err
!==
null
)
{
this
.
setFailedState
();
}
else
{
if
(
fstat
.
isDirectory
())
{
this
.
_tmp
.
dirs
.
push
(
file
);
}
else
if
(
fstat
.
isSymbolicLink
())
{
this
.
_tmp
.
symlinks
.
push
(
file
);
}
else
if
(
fstat
.
isFile
())
{
this
.
_tmp
.
files
.
push
(
file
);
}
else
{
this
.
_tmp
.
others
.
push
(
file
);
}
i
++
;
if
(
i
===
content
.
length
)
{
this
.
cwd
.
push
({
name
:
"
Show disks
"
,
type
:
"
showDisks
"
});
if
(
tcwd
!==
"
/
"
&&
tcwd
!==
"
\\
"
)
{
this
.
cwd
.
push
({
name
:
"
Go up
"
,
type
:
"
up
"
});
}
this
.
_tmp
.
dirs
.
forEach
(
e
=>
{
if
(
tcwd
===
settingsDir
&&
e
===
"
themes
"
)
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
e
),
type
:
"
edex-themesDir
"
});
}
else
if
(
tcwd
===
settingsDir
&&
e
===
"
keyboards
"
)
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
e
),
type
:
"
edex-kblayoutsDir
"
});
}
else
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
e
),
type
:
"
dir
"
});
}
});
this
.
_tmp
.
symlinks
.
forEach
(
e
=>
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
e
),
type
:
"
symlink
"
});
});
this
.
_tmp
.
files
.
forEach
(
e
=>
{
if
(
tcwd
===
themesDir
&&
e
.
endsWith
(
"
.json
"
))
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
e
),
type
:
"
edex-theme
"
});
}
else
if
(
tcwd
===
keyboardsDir
&&
e
.
endsWith
(
"
.json
"
))
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
e
),
type
:
"
edex-kblayout
"
});
}
else
if
(
tcwd
===
settingsDir
&&
e
===
"
settings.json
"
)
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
e
),
type
:
"
edex-settings
"
});
}
else
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
e
),
type
:
"
file
"
});
}
});
this
.
_tmp
.
others
.
forEach
(
e
=>
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
e
),
type
:
"
other
"
});
});
window
.
si
.
fsSize
().
then
(
d
=>
{
d
.
forEach
(
fsBlock
=>
{
if
(
tcwd
.
startsWith
(
fsBlock
.
mount
))
{
this
.
fsBlock
=
fsBlock
;
}
});
this
.
dirpath
=
tcwd
;
this
.
render
(
this
.
cwd
);
});
}
}
this
.
setFailedState
();
}
});
this
.
cwd
=
[];
await
new
Promise
((
resolve
,
reject
)
=>
{
if
(
content
.
length
===
0
)
resolve
();
content
.
forEach
(
async
(
file
,
i
)
=>
{
let
fstat
=
await
this
.
_asyncFSwrapper
.
lstat
(
path
.
join
(
tcwd
,
file
)).
catch
(
reject
);
if
(
fstat
.
isDirectory
())
{
if
(
tcwd
===
settingsDir
&&
file
===
"
themes
"
)
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
file
),
type
:
"
edex-themesDir
"
,
category
:
"
dir
"
});
}
else
if
(
tcwd
===
settingsDir
&&
file
===
"
keyboards
"
)
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
file
),
type
:
"
edex-kblayoutsDir
"
,
category
:
"
dir
"
});
}
else
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
file
),
type
:
"
dir
"
,
category
:
"
dir
"
});
}
}
else
if
(
fstat
.
isSymbolicLink
())
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
file
),
type
:
"
symlink
"
,
category
:
"
symlink
"
});
});
}
else
if
(
fstat
.
isFile
())
{
if
(
tcwd
===
themesDir
&&
file
.
endsWith
(
"
.json
"
))
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
file
),
type
:
"
edex-theme
"
,
category
:
"
file
"
});
}
else
if
(
tcwd
===
keyboardsDir
&&
file
.
endsWith
(
"
.json
"
))
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
file
),
type
:
"
edex-kblayout
"
,
category
:
"
file
"
});
}
else
if
(
tcwd
===
settingsDir
&&
file
===
"
settings.json
"
)
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
file
),
type
:
"
edex-settings
"
,
category
:
"
file
"
});
}
else
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
file
),
type
:
"
file
"
,
category
:
"
file
"
});
}
}
else
{
this
.
cwd
.
push
({
name
:
window
.
_escapeHtml
(
file
),
type
:
"
other
"
,
category
:
"
other
"
});
}
if
(
i
===
content
.
length
-
1
)
resolve
();
});
}).
catch
(()
=>
{
this
.
setFailedState
()
});
if
(
this
.
failed
)
return
false
;
let
ordering
=
{
dir
:
0
,
symlink
:
1
,
file
:
2
,
other
:
3
};
this
.
cwd
.
sort
((
a
,
b
)
=>
{
return
(
ordering
[
a
.
category
]
-
ordering
[
b
.
category
]
||
a
.
name
.
localeCompare
(
b
.
name
));
});
this
.
cwd
.
splice
(
0
,
0
,
{
name
:
"
Show disks
"
,
type
:
"
showDisks
"
});
if
(
tcwd
!==
"
/
"
&&
tcwd
!==
"
\\
"
)
{
this
.
cwd
.
splice
(
1
,
0
,
{
name
:
"
Go up
"
,
type
:
"
up
"
});
}
let
d
=
await
window
.
si
.
fsSize
().
catch
(()
=>
{
this
.
setFailedState
();
});
d
.
forEach
(
fsBlock
=>
{
if
(
tcwd
.
startsWith
(
fsBlock
.
mount
))
{
this
.
fsBlock
=
fsBlock
;
}
});
this
.
dirpath
=
tcwd
;
this
.
render
(
this
.
cwd
);
};
this
.
readDevices
=
()
=>
{
this
.
readDevices
=
async
()
=>
{
if
(
this
.
failed
===
true
)
return
false
;
window
.
si
.
blockDevices
().
then
(
blocks
=>
{
let
devices
=
[];
blocks
.
forEach
(
block
=>
{
if
(
fs
.
existsSync
(
block
.
mount
))
{
let
type
=
(
block
.
type
===
"
rom
"
)
?
"
rom
"
:
"
disk
"
;
if
(
block
.
removable
&&
block
.
type
!==
"
rom
"
)
{
type
=
"
usb
"
;
}
devices
.
push
({
name
:
(
block
.
label
!==
""
)
?
`
${
block
.
label
}
(
${
block
.
name
}
)`
:
`
${
block
.
mount
}
(
${
block
.
name
}
)`
,
type
,
path
:
block
.
mount
});
let
blocks
=
await
window
.
si
.
blockDevices
();
let
devices
=
[];
blocks
.
forEach
(
block
=>
{
if
(
fs
.
existsSync
(
block
.
mount
))
{
let
type
=
(
block
.
type
===
"
rom
"
)
?
"
rom
"
:
"
disk
"
;
if
(
block
.
removable
&&
block
.
type
!==
"
rom
"
)
{
type
=
"
usb
"
;
}
});
this
.
render
(
devices
);
devices
.
push
({
name
:
(
block
.
label
!==
""
)
?
`
${
block
.
label
}
(
${
block
.
name
}
)`
:
`
${
block
.
mount
}
(
${
block
.
name
}
)`
,
type
,
path
:
block
.
mount
});
}
});
this
.
render
(
devices
);
};
this
.
render
=
async
blockList
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录