Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { useState } from 'react';
function useCount() {
const [count, setState] = useState(0);
function increment() {
setState(count + 1);
}
return {
count,
increment,
};
}
export default createModel(useCount);
export { useCount as useLocalCount };
}, [])
const signout = useCallback((account, password) => {
clearAll()
setCurrentUser(null)
setTokenState(null)
}, [])
return {
currentUser,
sign,
signout
}
}
export default createModel(useAuthModel)
useEffect(() => {
getSysHosts(aliases).then(sysHosts => {
setSysHosts(sysHosts)
})
}, [aliases])
return {
hosts,
createHost,
toggleHostState,
removeHost,
modifyHost
}
}
export default createModel(useHostsModel)
function getSysHosts(aliases) {
return new Promise(function(resolve, reject) {
hostile.get(false, function(error, lines) {
if (error) {
return reject(error.message)
}
const sysHosts = lines.map(line => {
const ip = line[0]
const domain = line[1]
return {
ip: ip,
domain: domain,
disabled: false,
alias: aliases[ip + domain] || ''
}
},
() => {
setAcquired(false)
return false
}
)
})
}
return {
acquired,
permissionAcquired
}
}
export default createModel(usePermissionModel)
function requestPermission() {
const options = {
name: 'Hosts Master'
}
return new Promise(function(resolve, reject) {
sudo.exec(PERMISSION_CMD, options, function(err) {
if (err) {
return reject(err)
}
return resolve()
})
})
}