Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://www.github.com/qusly/qusly
- Loading branch information
Showing
12 changed files
with
193 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as React from 'react'; | ||
|
||
import { File } from '~/renderer/models'; | ||
import store from '~/renderer/store'; | ||
import { StyledItem, Icon, Name, Path, Details } from './styles'; | ||
|
||
export default ({ file }: { file: File }) => { | ||
const { icon, opacity } = store.favicons.get(file); | ||
|
||
return ( | ||
<StyledItem> | ||
<Icon icon={icon} opacity={opacity} /> | ||
<Details> | ||
<Name>name.txt</Name> | ||
<Path>/var/www/</Path> | ||
</Details> | ||
</StyledItem> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import styled, { css } from 'styled-components'; | ||
import { centerIcon, transparency } from 'wexond-ui'; | ||
|
||
export const StyledItem = styled.div` | ||
width: 100%; | ||
height: 36px; | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
export const Icon = styled.div` | ||
width: 24px; | ||
height: 24px; | ||
margin-left: 20px; | ||
${centerIcon(24)}; | ||
${({ icon, opacity }: { icon: string, opacity: number }) => css` | ||
background-image: url(${icon}); | ||
opacity: ${opacity}; | ||
`} | ||
`; | ||
|
||
export const Details = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
flex-direction: column; | ||
padding-left: 12px; | ||
padding-right: 24px; | ||
`; | ||
|
||
export const Name = styled.div` | ||
font-size: 13px; | ||
white-space: nowrap; | ||
`; | ||
|
||
export const Path = styled(Name)` | ||
margin-top: 2px; | ||
color: rgba(0, 0, 0, ${transparency.text.medium}); | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as React from 'react'; | ||
import { observer } from 'mobx-react'; | ||
|
||
import store from '~/renderer/store'; | ||
import { Pagebar, PageTitle } from '../MenuPage/styles'; | ||
import TransferItem from '../TransferItem'; | ||
import { File } from '~/renderer/models'; | ||
|
||
export default observer(() => { | ||
const file: File = { | ||
date: new Date('2001-06-01T20:05:00.000Z'), | ||
permissions: { user: 6, group: 4 }, | ||
name: 'documentation.pdf', | ||
size: 1724303, | ||
user: 'root', | ||
group: 'root', | ||
type: 'file', | ||
ext: '.pdf', | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<Pagebar> | ||
<PageTitle>File transfer</PageTitle> | ||
</Pagebar> | ||
<TransferItem file={file} /> | ||
</React.Fragment> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface QueueItem { | ||
remotePath: string; | ||
localPath: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { createWriteStream, existsSync, mkdirSync } from 'fs'; | ||
import { join } from 'path'; | ||
import { Client } from 'qusly-core'; | ||
|
||
import { Session } from './session'; | ||
import { QueueItem } from './queue-item'; | ||
import { getPath } from '../utils'; | ||
|
||
export class TransferManager { | ||
public client: Client; | ||
|
||
public queue: QueueItem[] = []; | ||
|
||
public transfering = false; | ||
|
||
constructor(public session: Session, public type: 'download' | 'upload') { } | ||
|
||
public async connect() { | ||
if (!this.client) { | ||
this.client = new Client(); | ||
|
||
const config = this.session.site; | ||
const { error } = await this.client.connect(config); | ||
|
||
if (error) throw error; | ||
} | ||
} | ||
|
||
public async add(remotePath: string, fileName: string) { | ||
await this.connect(); | ||
const localPath = getPath('downloads'); | ||
|
||
if (!existsSync(localPath)) { | ||
mkdirSync(localPath); | ||
} | ||
|
||
this.queue.push({ | ||
remotePath, | ||
localPath: join(localPath, fileName), | ||
}); | ||
|
||
this.process(); | ||
} | ||
|
||
private async process() { | ||
if (this.transfering || !this.queue.length) return; | ||
|
||
this.transfering = true; | ||
|
||
const { remotePath, localPath } = this.queue[0]; | ||
const { error } = await this.client.download(remotePath, createWriteStream(localPath)); | ||
|
||
if (error) { | ||
console.error('Error while transfering a file', remotePath, localPath, error); | ||
} | ||
|
||
this.queue.shift(); | ||
this.transfering = false; | ||
await this.process(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { observable } from 'mobx'; | ||
|
||
export type MenuContent = 'file-tree' | 'transfer' | 'search' | 'sites'; | ||
export type MenuContent = 'file-tree' | 'transfers' | 'search' | 'sites'; | ||
|
||
export class MenuStore { | ||
@observable | ||
public content: MenuContent = 'sites'; | ||
public content: MenuContent = 'transfers'; | ||
} |