Skip to content

Commit 62faeb6

Browse files
committed
Changed style of welcome page, persist windows on close
1 parent 4a09fde commit 62faeb6

File tree

6 files changed

+98
-38
lines changed

6 files changed

+98
-38
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ PRs for more protocols are welcome.
4747
- Basic navigation bar (`ctrl+l` to bring into focus)
4848
- Dev tools (`ctrl+shift+i`)
4949
- Autocomplete URLs from history (type in the URL bar)
50+
- Persist open windows when quitting
5051
- Basic Chrome Extension support (hardcoded into the source for now)
5152

5253
![Agregore demo](agregore-demo-1.gif)
@@ -75,12 +76,15 @@ This project uses the [StandardJS](https://standardjs.com/) code style. Please f
7576
- [x] `ctrl+[` and `ctrl+]` for navigating history
7677
- [x] `ctrl+l` for selecting the navigation bar
7778
- [ ] saveAs context menu (using fetch and fs.createWriteStream())
78-
- [ ] Persist windows on application quit
79+
- [x] Persist windows on application quit
7980
- [ ] fetch API for hyperdrives [GH issue](https://github.com/cliqz-oss/dat-webext/issues/159)
8081
- [ ] Creating an archive (scoped to page origin)
8182
- [ ] PUT/DELETE methods for files / folders
8283
- [ ] Track created archives for origin in a DB
8384
- [ ] Access control prompt for writing to origin
85+
- [ ] Sync folder with hyperdrive
86+
- [ ] Sync from folder to hyperdrive
87+
- [ ] Sync to folder from hyperdrive
8488
- [ ] Better browser history
8589
- [x] As an extension?
8690
- [x] Save history to a DB
@@ -106,6 +110,8 @@ This project uses the [StandardJS](https://standardjs.com/) code style. Please f
106110
- [ ] Developer options page
107111
- [ ] Track extensions in a DB
108112
- [ ] Drag and drop extension folder
113+
- [ ] Password / Account management for web pages [using native OS APIs](https://github.com/atom/node-keytar)
114+
- [ ] Private browsing mode
109115
- [ ] PWA support
110116
- [x] Service Workers (Free with Electron)
111117
- [ ] Install web page to desktop

app/main.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { app, BrowserWindow, session } = require('electron')
22

33
const protocols = require('./protocols')
44
const { registerMenu } = require('./menu')
5-
const { createWindow } = require('./windows')
5+
const { createWindow, saveOpen, loadFromHistory } = require('./windows')
66
const { registerExtensions } = require('./extensions')
77
const history = require('./history')
88

@@ -43,6 +43,10 @@ app.on('activate', () => {
4343
}
4444
})
4545

46+
app.on('before-quit', () => {
47+
saveOpen()
48+
})
49+
4650
async function onready () {
4751
const webSession = session.fromPartition(WEB_PARTITION)
4852

@@ -56,5 +60,8 @@ async function onready () {
5660

5761
const urls = process.argv.filter((arg) => arg.includes('://'))
5862
if (urls.length) urls.map(createWindow)
59-
else createWindow()
63+
else {
64+
const opened = await loadFromHistory()
65+
if (!opened.length) createWindow()
66+
}
6067
}

app/pages/welcome.html

+25-28
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,42 @@
88
<meta name="mobile-web-app-capable" content="yes">
99

1010
<style>
11-
body {
12-
margin: 0 auto;
13-
max-width: 666px;
14-
padding: 1em;
15-
}
16-
header {
17-
text-align: center;
11+
body, html {
12+
display: flex;
13+
flex: 1;
14+
margin: 0px;
15+
padding: 0px;
16+
width: 100%;
17+
height: 100%;
18+
flex-direction: column;
19+
justify-content: center;
20+
align-items: center;
1821
}
1922
img {
20-
width: 8em;
23+
width: 40vmin;
24+
}
25+
a::before, a::after {
26+
content: " ⟐ "
27+
}
28+
a {
29+
margin: 0.1em;
2130
}
2231
</style>
2332

24-
<header>
2533
<img src="agregore-browser://icon.svg" />
2634

2735
<h1>
2836
Agregore
2937
</h1>
3038

31-
</header>
32-
3339
<p>
34-
Check out some of these dweb links.
35-
</p>
36-
37-
<ul>
38-
<li>
39-
<a href="hyper://94f0cab7f60fcc2a711df11c85db5e0594d11e8a3efd04a06f46a3c34d03c418/">
40+
<a href="hyper://94f0cab7f60fcc2a711df11c85db5e0594d11e8a3efd04a06f46a3c34d03c418/">
4041
Mauve's Blog
41-
</a>
42-
</li>
43-
<li>
44-
<a href="dat://dat.foundation/">
45-
Dat Foundation Blog
46-
</a>
47-
</li>
48-
</ul>
49-
50-
<p>
51-
Otherwise, try entering a <code>hyper://</code> or <code>dat://</code> URL in the address bar.
42+
</a>
43+
<a href="dat://dat.foundation/">
44+
Dat Foundation
45+
</a>
46+
<a href="hyper://a8109b835d27c30ad4d55b321dd7c4032c037eaf1f6f2b00de7b03b5a6cc504a/">
47+
Hypercore Protocol
48+
</a>
5249
</p>

app/protocols/browser-protocol.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ module.exports = async function createHandler () {
1818
const parsed = new URL(url)
1919
console.debug('Rendering browser page', url)
2020

21-
const {pathname, hostname} = parsed
22-
const toResolve = path.join(hostname, pathname)
21+
const { pathname, hostname } = parsed
22+
const toResolve = path.join(hostname, pathname)
2323
try {
2424
const resolvedPath = await resolveFile(toResolve)
2525
const statusCode = 200

app/ui/script.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ frontbutton.addEventListener('click', () => {
4646
webview.addEventListener('did-start-navigation', ({ detail }) => {
4747
const url = detail[1]
4848
const isMainFrame = detail[3]
49-
if(!isMainFrame) return
49+
if (!isMainFrame) return
5050
urlbar.value = url
5151
if (firstLoad && (toNavigate === DEFAULT_PAGE)) {
5252
urlbar.focus()

app/windows.js

+54-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1+
const { app } = require('electron')
12
const { BrowserWindow } = require('electron')
23
const { resolve } = require('path')
34
const { headerContextMenu } = require('./ui/context-menus')
5+
const fs = require('fs-extra')
6+
const path = require('path')
47

58
const MAIN_PAGE = resolve(__dirname, './ui/index.html')
9+
const PERSIST_FILE = path.join(app.getPath('userData'), 'lastOpened.json')
610

711
module.exports = {
8-
createWindow
12+
createWindow,
13+
loadFromHistory,
14+
saveOpen
915
}
1016

17+
const openWindows = new Set()
18+
1119
function createWindow (url, options = {}) {
1220
// Create the browser window.
1321
const win = new BrowserWindow({
14-
width: 800,
15-
height: 600,
1622
autoHideMenuBar: true,
1723
webPreferences: {
1824
nodeIntegration: true,
19-
webviewTag: true
25+
webviewTag: false
2026
},
2127
show: false,
2228
...options
@@ -37,4 +43,48 @@ function createWindow (url, options = {}) {
3743
if (process.env.MODE === 'debug') {
3844
win.webContents.openDevTools()
3945
}
46+
47+
openWindows.add(win)
48+
49+
win.once('closed', () => {
50+
openWindows.delete(win)
51+
})
52+
}
53+
54+
function saveOpen (file = PERSIST_FILE) {
55+
const urls = getToSave()
56+
57+
fs.outputJsonSync(file, urls)
58+
}
59+
60+
function getToSave () {
61+
const currentlyOpen = [...openWindows]
62+
63+
const urls = currentlyOpen.map((win) => {
64+
const view = win.getBrowserView() || win
65+
return view.webContents.getURL()
66+
})
67+
68+
if (urls.length === 1) return []
69+
return urls
70+
}
71+
72+
async function loadFromHistory (file = PERSIST_FILE) {
73+
const urls = await getHistory(file)
74+
75+
for (const url of urls) {
76+
createWindow(url)
77+
}
78+
79+
return urls
80+
}
81+
82+
async function getHistory (file = PERSIST_FILE) {
83+
try {
84+
const urls = await fs.readJson(file)
85+
return urls
86+
} catch (e) {
87+
console.error(e.stack)
88+
return []
89+
}
4090
}

0 commit comments

Comments
 (0)