This repository has been archived by the owner on Jun 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from wexond/tabs-preview
feat: add tabs preview
- Loading branch information
Showing
12 changed files
with
256 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { AppWindow } from '../windows'; | ||
import { MENU_WIDTH } from '~/constants/design'; | ||
import { Dialog } from '.'; | ||
import { TAB_MAX_WIDTH } from '~/renderer/views/app/constants/tabs'; | ||
|
||
const WIDTH = MENU_WIDTH; | ||
const HEIGHT = 128; | ||
|
||
export class PreviewDialog extends Dialog { | ||
public visible = false; | ||
public tab: { id?: number; x?: number } = {}; | ||
|
||
constructor(appWindow: AppWindow) { | ||
super(appWindow, { | ||
name: 'preview', | ||
bounds: { | ||
width: TAB_MAX_WIDTH + 16, | ||
height: HEIGHT, | ||
y: 40, | ||
}, | ||
hideTimeout: 300, | ||
}); | ||
} | ||
|
||
public show() { | ||
this.bounds.x = Math.round(this.tab.x - 8); | ||
|
||
super.show(); | ||
|
||
const tab = this.appWindow.viewManager.views.find( | ||
x => x.webContents.id === this.tab.id, | ||
); | ||
|
||
const url = tab.webContents.getURL(); | ||
const title = tab.webContents.getTitle(); | ||
|
||
this.webContents.send('visible', true, { | ||
id: tab.id, | ||
url: url.startsWith('wexond-error') ? tab.errorURL : url, | ||
title, | ||
}); | ||
} | ||
|
||
public hide() { | ||
super.hide(); | ||
this.webContents.send('visible', false); | ||
} | ||
} |
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,24 @@ | ||
import * as React from 'react'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { createGlobalStyle, ThemeProvider } from 'styled-components'; | ||
import { hot } from 'react-hot-loader/root'; | ||
|
||
import { Style } from '../../style'; | ||
import { StyledApp, Title, Domain } from './style'; | ||
import store from '../../store'; | ||
|
||
const GlobalStyle = createGlobalStyle`${Style}`; | ||
|
||
export const App = hot( | ||
observer(() => { | ||
return ( | ||
<ThemeProvider theme={{ ...store.theme }}> | ||
<StyledApp visible={store.visible}> | ||
<Title>{store.title}</Title> | ||
<Domain>{store.domain}</Domain> | ||
<GlobalStyle /> | ||
</StyledApp> | ||
</ThemeProvider> | ||
); | ||
}), | ||
); |
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,45 @@ | ||
import styled, { css } from 'styled-components'; | ||
import { ITheme } from '~/interfaces'; | ||
import { maxLines } from '~/renderer/mixins'; | ||
|
||
export const StyledApp = styled.div` | ||
margin: 8px; | ||
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23); | ||
border-radius: 6px; | ||
overflow: hidden; | ||
position: relative; | ||
transition: 0.2s opacity, 0.2s margin-top; | ||
padding: 16px; | ||
font-size: 14px; | ||
${({ visible, theme }: { visible: boolean; theme?: ITheme }) => css` | ||
opacity: ${visible ? 1 : 0}; | ||
margin-top: ${visible ? 0 : 7}px; | ||
background-color: ${theme['dialog.backgroundColor']}; | ||
color: ${theme['dialog.textColor']}; | ||
`} | ||
`; | ||
|
||
export const Title = styled.div` | ||
font-weight: 500; | ||
line-height: 1.3rem; | ||
${maxLines(2)}; | ||
`; | ||
|
||
export const Domain = styled.div` | ||
opacity: 0.54; | ||
font-weight: 300; | ||
line-height: 1.3rem; | ||
`; | ||
|
||
export const Subtitle = styled.div` | ||
font-size: 13px; | ||
opacity: 0.54; | ||
margin-top: 8px; | ||
`; | ||
|
||
export const Buttons = styled.div` | ||
display: flex; | ||
margin-top: 16px; | ||
float: right; | ||
`; |
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,35 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
|
||
import { App } from './components/App'; | ||
import { fonts } from '../../constants'; | ||
import { ipcRenderer } from 'electron'; | ||
|
||
ipcRenderer.setMaxListeners(0); | ||
|
||
const styleElement = document.createElement('style'); | ||
|
||
styleElement.textContent = ` | ||
@font-face { | ||
font-family: 'Roboto'; | ||
font-style: normal; | ||
font-weight: 400; | ||
src: url(${fonts.robotoRegular}) format('woff2'); | ||
} | ||
@font-face { | ||
font-family: 'Roboto'; | ||
font-style: normal; | ||
font-weight: 500; | ||
src: url(${fonts.robotoMedium}) format('woff2'); | ||
} | ||
@font-face { | ||
font-family: 'Roboto'; | ||
font-style: normal; | ||
font-weight: 300; | ||
src: url(${fonts.robotoLight}) format('woff2'); | ||
} | ||
`; | ||
|
||
document.head.appendChild(styleElement); | ||
|
||
ReactDOM.render(<App />, document.getElementById('app')); |
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,58 @@ | ||
import { ipcRenderer, remote } from 'electron'; | ||
import { observable, computed } from 'mobx'; | ||
import { getTheme } from '~/utils/themes'; | ||
import { ISettings } from '~/interfaces'; | ||
import { DEFAULT_SETTINGS } from '~/constants'; | ||
import { parse } from 'url'; | ||
|
||
export class Store { | ||
@observable | ||
public settings: ISettings = DEFAULT_SETTINGS; | ||
|
||
@computed | ||
public get theme() { | ||
return getTheme(this.settings.theme); | ||
} | ||
|
||
@observable | ||
public visible = false; | ||
|
||
@observable | ||
public id = remote.getCurrentWebContents().id; | ||
|
||
@observable | ||
public windowId = remote.getCurrentWindow().id; | ||
|
||
@observable | ||
public title = ''; | ||
|
||
@observable | ||
public url = ''; | ||
|
||
@computed | ||
public get domain() { | ||
return parse(this.url).hostname; | ||
} | ||
|
||
public constructor() { | ||
ipcRenderer.on('visible', (e, flag, tab) => { | ||
this.visible = flag; | ||
if (tab) { | ||
this.title = tab.title; | ||
this.url = tab.url; | ||
} | ||
}); | ||
|
||
ipcRenderer.send('get-settings'); | ||
|
||
ipcRenderer.on('update-settings', (e, settings: ISettings) => { | ||
this.settings = { ...this.settings, ...settings }; | ||
}); | ||
} | ||
|
||
public hide() { | ||
ipcRenderer.send(`hide-${this.id}`); | ||
} | ||
} | ||
|
||
export default new Store(); |
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,20 @@ | ||
import { css } from 'styled-components'; | ||
|
||
import { body2 } from '~/renderer/mixins'; | ||
|
||
export const Style = css` | ||
body { | ||
user-select: none; | ||
cursor: default; | ||
margin: 0; | ||
padding: 0; | ||
width: 100vw; | ||
height: 100vh; | ||
overflow: hidden; | ||
${body2()} | ||
} | ||
* { | ||
box-sizing: border-box; | ||
} | ||
`; |
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ applyEntries('app', appConfig, [ | |
'find', | ||
'menu', | ||
'search', | ||
'preview', | ||
]); | ||
|
||
module.exports = appConfig; |