Skip to content

Commit

Permalink
change the way showing locations of About Pages & PDF Viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
qazbnm456 committed May 15, 2017
1 parent 9d3803b commit 468ec4d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/guest/renderer/store/modules/guest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as types from '../mutation-types';
import * as types from 'renderer/store/mutation-types';

const state = {
about: {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/js/constants/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default {
currentSearchEngine: searchEngine[0],
homepage,
pdfViewer,
lulumiPagesPath: `${lulumiHelperPath}/pages/`,
lulumiPDFJSPath: `${lulumiHelperPath}/pdfjs/`,
lulumiPagesPath: `${lulumiHelperPath}/pages`,
lulumiPDFJSPath: `${lulumiHelperPath}/pdfjs`,
lulumiHelperPath,
lulumiRootPath,
devUserData: `${lulumiRootPath}/userData/`,
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/js/lib/url-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ function getLulumiExtUrl(relativeUrl) {
const urlResource = {
aboutUrls(url) {
switch (url) {
case 'about:about':
return getLulumiExtUrl('about/#/');
case 'about:lulumi':
return getLulumiExtUrl('about/#/lulumi');
case 'about:preferences':
return getLulumiExtUrl('about/#/preferences');
case 'about:about':
return getLulumiExtUrl('about/#/');
case 'about:downloads':
return getLulumiExtUrl('about/#/downloads');
case 'about:history':
return getLulumiExtUrl('about/#/history');
case 'about:extensions':
return getLulumiExtUrl('about/#/extensions');
case 'about:blank':
return url;
default:
Expand Down
37 changes: 33 additions & 4 deletions src/renderer/js/lib/url-util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import config from 'renderer/js/constants/config';

// characters, then : with optional //
const rscheme = /^(?:[a-z\u00a1-\uffff0-9-+]+)(?::(\/\/)?)(?!\d)/i;
const defaultScheme = 'http://';
Expand Down Expand Up @@ -242,11 +244,38 @@ const urlUtil = {
* @return {string}
*/
getLocationIfPDF(url) {
const PDFViewerURL = '/pdfjs/web/viewer.html';
if (url && url.includes(PDFViewerURL)) {
return url.replace(/^file:.+\/pdfjs\/web\/viewer.html\?file=(\w+:\/\/.+)/, '$1');
const PDFViewerWithPDFJS = '/pdfjs/web/viewer.html';
const PDFViewerForChrome = 'chrome://pdf-viewer/index.html?src=';
if (url) {
if (url.includes(PDFViewerWithPDFJS)) {
return url.replace(/^file:.+\/pdfjs\/web\/viewer.html\?file=(\w+:\/\/.+)/, '$1');
} else if (url.includes(PDFViewerForChrome)) {
return url.replace(/^chrome:\/\/pdf-viewer\/index\.html\?src=/, '');
}
return url;
}
return '';
},

/**
* Gets about location from a lulumi scheme
* @param {string} url
* @return {string}
*/
getLocationIfAbout(url) {
if (url.startsWith(config.lulumiPagesCustomProtocol)) {
const guestUrl = require('url').parse(url);
const guestHash = guestUrl.hash.substr(2);
const item = `${guestUrl.host}:${guestHash === '' ? 'about' : guestHash}`;
return {
title: item,
url: item,
};
}
return url;
return {
title: undefined,
url,
};
},

/**
Expand Down
26 changes: 12 additions & 14 deletions src/renderer/store/modules/browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as types from '../mutation-types';
import config from '../../js/constants/config';
import urlUtil from '../../js/lib/url-util';
import timeUtil from '../../js/lib/time-util';
import * as types from 'renderer/store/mutation-types';
import config from 'renderer/js/constants/config';
import urlUtil from 'renderer/js/lib/url-util';
import timeUtil from 'renderer/js/lib/time-util';

const state = {
pid: 0,
Expand Down Expand Up @@ -105,15 +105,12 @@ const mutations = {
state.pages[payload.pageIndex].canRefresh = true;
},
[types.DID_STOP_LOADING](state, payload) {
const url = payload.webview.getURL();
state.pages[payload.pageIndex].statusText = false;
state.pages[payload.pageIndex].canGoBack = payload.webview.canGoBack();
state.pages[payload.pageIndex].canGoForward = payload.webview.canGoForward();
let url = decodeURIComponent(payload.webview.getURL());
url = urlUtil.getLocationIfPDF(url);
const data = urlUtil.getLocationIfAbout(url);
state.pages[payload.pageIndex].location = data.url;
if (url.startsWith(config.lulumiPagesCustomProtocol)) {
const guestUrl = require('url').parse(url);
const guestHash = guestUrl.hash.substr(2);
state.pages[payload.pageIndex].title = `${guestUrl.host} : ${guestHash === '' ? 'about' : guestHash}`;
state.pages[payload.pageIndex].location = url;
state.pages[payload.pageIndex].title = data.title;
} else {
if (!state.pages[payload.pageIndex].title) {
state.pages[payload.pageIndex].title = state.pages[payload.pageIndex].location;
Expand Down Expand Up @@ -154,6 +151,9 @@ const mutations = {
}
}
}
state.pages[payload.pageIndex].statusText = false;
state.pages[payload.pageIndex].canGoBack = payload.webview.canGoBack();
state.pages[payload.pageIndex].canGoForward = payload.webview.canGoForward();
state.pages[payload.pageIndex].isLoading = false;
},
[types.DID_FAIL_LOAD](state, pageIndex) {
Expand All @@ -165,8 +165,6 @@ const mutations = {
},
[types.PAGE_TITLE_SET](state, payload) {
state.pages[payload.pageIndex].title = payload.webview.getTitle();
state.pages[payload.pageIndex].location
= decodeURIComponent(urlUtil.getLocationIfPDF(payload.webview.getURL()));
},
[types.UPDATE_TARGET_URL](state, payload) {
state.pages[payload.pageIndex].statusText
Expand Down

0 comments on commit 468ec4d

Please sign in to comment.