Skip to content

Commit 6bbe22a

Browse files
author
Benoit Schweblin
committed
Fixed multiple window issue
1 parent f8f3a87 commit 6bbe22a

File tree

6 files changed

+49
-43
lines changed

6 files changed

+49
-43
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ npm-debug.log*
66
yarn-debug.log*
77
yarn-error.log*
88
.vscode
9+
stackedit_v4

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var path = require('path');
77
var express = require('express');
88
var app = express();
99

10-
require('./server')(app);
10+
require('./server')(app, process.env.SERVE_V4);
1111

1212
var port = parseInt(process.env.PORT || 8080, 10);
1313
if(port === 443) {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"raw-loader": "^0.5.1",
4040
"request": "^2.82.0",
4141
"serve-static": "^1.12.6",
42-
"stackedit": "^4.3.17",
4342
"vue": "^2.3.3",
4443
"vuex": "^2.3.1"
4544
},

server/index.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,31 @@ var compression = require('compression');
22
var serveStatic = require('serve-static');
33
var path = require('path');
44

5-
module.exports = function (app) {
5+
module.exports = function (app, serveV4) {
66
// Use gzip compression
77
if (process.env.NODE_ENV === 'production') {
8-
// Force HTTPS on stackedit.io
98
app.all('*', function(req, res, next) {
9+
// Force HTTPS on stackedit.io
1010
if (req.headers.host === 'stackedit.io' && !req.secure && req.headers['x-forwarded-proto'] !== 'https') {
1111
return res.redirect('https://stackedit.io' + req.url);
1212
}
13-
/\.(eot|ttf|woff|svg)$/.test(req.url) && res.header('Access-Control-Allow-Origin', '*');
13+
// Enable CORS for fonts
14+
if (/\.(eot|ttf|woff|svg)$/.test(req.url)) {
15+
res.header('Access-Control-Allow-Origin', '*');
16+
}
1417
next();
1518
});
1619

1720
app.use(compression());
1821
}
1922

2023
app.get('/oauth2/githubToken', require('./github').githubToken);
21-
app.post('/pdfExport', require('stackedit/app/pdf').export);
22-
app.post('/sshPublish', require('stackedit/app/ssh').publish);
23-
app.post('/picasaImportImg', require('stackedit/app/picasa').importImg);
24-
app.get('/downloadImport', require('stackedit/app/download').importPublic);
24+
if (serveV4) {
25+
app.post('/pdfExport', require('../stackedit_v4/app/pdf').export);
26+
app.post('/sshPublish', require('../stackedit_v4/app/ssh').publish);
27+
app.post('/picasaImportImg', require('../stackedit_v4/app/picasa').importImg);
28+
app.get('/downloadImport', require('../stackedit_v4/app/download').importPublic);
29+
}
2530

2631
// Serve callback.html in /app
2732
app.get('/oauth2/callback', function(req, res) {
@@ -30,29 +35,35 @@ module.exports = function (app) {
3035

3136
// Serve static resources
3237
if (process.env.NODE_ENV === 'production') {
33-
// Serve landing.html in /
34-
app.get('/', function(req, res) {
35-
res.sendFile(require.resolve('stackedit/views/landing.html'));
36-
});
37-
// Serve editor.html in /viewer
38-
app.get('/editor', function(req, res) {
39-
res.sendFile(require.resolve('stackedit/views/editor.html'));
40-
});
41-
// Serve viewer.html in /viewer
42-
app.get('/viewer', function(req, res) {
43-
res.sendFile(require.resolve('stackedit/views/viewer.html'));
44-
});
38+
if (serveV4) {
39+
// Serve landing.html in /
40+
app.get('/', function(req, res) {
41+
res.sendFile(require.resolve('../stackedit_v4/views/landing.html'));
42+
});
43+
// Serve editor.html in /viewer
44+
app.get('/editor', function(req, res) {
45+
res.sendFile(require.resolve('../stackedit_v4/views/editor.html'));
46+
});
47+
// Serve viewer.html in /viewer
48+
app.get('/viewer', function(req, res) {
49+
res.sendFile(require.resolve('../stackedit_v4/views/viewer.html'));
50+
});
51+
}
52+
4553
// Serve index.html in /app
4654
app.get('/app', function(req, res) {
4755
res.sendFile(path.join(__dirname, '../dist/index.html'));
4856
});
4957

50-
app.use(serveStatic(path.join(__dirname, '../dist'))); // v5
51-
app.use(serveStatic(path.dirname(require.resolve('stackedit/public/cache.manifest')))); // v4
58+
app.use(serveStatic(path.join(__dirname, '../dist')));
5259

53-
// Error 404
54-
app.use(function(req, res) {
55-
res.status(404).sendFile(require.resolve('stackedit/views/error_404.html'));
56-
});
60+
if (serveV4) {
61+
app.use(serveStatic(path.dirname(require.resolve('../stackedit_v4/public/cache.manifest'))));
62+
63+
// Error 404
64+
app.use(function(req, res) {
65+
res.status(404).sendFile(require.resolve('../stackedit_v4/views/error_404.html'));
66+
});
67+
}
5768
}
5869
};

src/services/localDbSvc.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,14 @@ const localDbSvc = {
9898
connection: new Connection(),
9999

100100
/**
101-
* Return a promise that is resolved once the synchronization between the store and the localDb
102-
* is finished. Effectively, open a transaction, then read and apply all changes from the DB
103-
* since the previous transaction, then write all the changes from the store.
101+
* Return a promise that will be resolved once the synchronization between the store and the
102+
* localDb will be finished. Effectively, open a transaction, then read and apply all changes
103+
* from the DB since the previous transaction, then write all the changes from the store.
104104
*/
105105
sync() {
106106
return new Promise((resolve, reject) => {
107-
const storeItemMap = { ...store.getters.allItemMap };
108107
this.connection.createTx((tx) => {
109-
this.readAll(storeItemMap, tx, () => {
108+
this.readAll(tx, (storeItemMap) => {
110109
this.writeAll(storeItemMap, tx);
111110
if (!store.state.ready) {
112111
store.commit('setReady');
@@ -120,7 +119,7 @@ const localDbSvc = {
120119
/**
121120
* Read and apply all changes from the DB since previous transaction.
122121
*/
123-
readAll(storeItemMap, tx, cb) {
122+
readAll(tx, cb) {
124123
let lastTx = this.lastTx;
125124
const dbStore = tx.objectStore(dbStoreName);
126125
const index = dbStore.index('tx');
@@ -142,6 +141,7 @@ const localDbSvc = {
142141
changes.push(item);
143142
cursor.continue();
144143
} else {
144+
const storeItemMap = { ...store.getters.allItemMap };
145145
changes.forEach((item) => {
146146
this.readDbItem(item, storeItemMap);
147147
// If item is an old delete marker, remove it from the DB
@@ -150,7 +150,7 @@ const localDbSvc = {
150150
}
151151
});
152152
this.lastTx = lastTx;
153-
cb();
153+
cb(storeItemMap);
154154
}
155155
};
156156
},

src/store/modules/data.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,12 @@ module.mutations.setItem = (state, value) => {
2929
: value.data;
3030
const item = {
3131
...emptyItem,
32-
...value,
3332
data,
34-
hash: Date.now(),
3533
};
36-
if (item.id === 'settings' || item.id === 'templates') {
37-
// Use a real hash for synced types
38-
item.hash = utils.hash(utils.serializeObject({
39-
...item,
40-
hash: undefined,
41-
}));
42-
}
34+
item.hash = utils.hash(utils.serializeObject({
35+
...item,
36+
hash: undefined,
37+
}));
4338
Vue.set(state.itemMap, item.id, item);
4439
};
4540

0 commit comments

Comments
 (0)