Skip to content

Commit fc73f57

Browse files
committed
fix: many problems related to the recent updates of dependencies
1 parent 9d2efba commit fc73f57

32 files changed

+682
-776
lines changed

.electron-vue/webpack.renderer.config.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,21 @@ const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
1616
const VueLoaderPlugin = require('vue-loader/lib/plugin')
1717
const CopyWebpackPlugin = require('copy-webpack-plugin')
1818

19+
function inlineOptions(loaders) {
20+
return loaders.map(({ loader, options={} }) => {
21+
if (!isString(loader)) throw new Error('inlineOptions: loader should be a string!')
22+
if (!isObjectLike(options)) throw new Error('inlineOptions: options should be an object!')
23+
return loader + '?' + JSON.stringify(options)
24+
})
25+
}
26+
1927
function returnLess() {
2028
return [
2129
process.env.NODE_ENV !== 'production'
2230
? 'vue-style-loader'
2331
: MiniCssExtractPlugin.loader,
24-
'css-loader',
32+
// https://blog.csdn.net/vv_bug/article/details/108148263
33+
'css-loader?{"esModule":false}',
2534
'less-loader'
2635
]
2736
}
@@ -30,7 +39,8 @@ function returnCss() {
3039
process.env.NODE_ENV !== 'production'
3140
? 'vue-style-loader'
3241
: MiniCssExtractPlugin.loader,
33-
'css-loader'
42+
// https://blog.csdn.net/vv_bug/article/details/108148263
43+
'css-loader?{"esModule":false}'
3444
]
3545
}
3646

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@
8989
],
9090
"import/newline-after-import": "off",
9191
"no-control-regex": "off",
92-
"@typescript-eslint/explicit-module-boundary-types": "off"
92+
"@typescript-eslint/explicit-module-boundary-types": "off",
93+
"@typescript-eslint/member-delimiter-style": "error"
9394
},
9495
"settings": {
9596
"import/resolver": {

package.json

+25-25
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
"css-element-queries": "^1.2.3",
4242
"electron-localshortcut": "^3.2.1",
4343
"electron-process-manager": "^1.0.0",
44-
"fuse.js": "^6.4.3",
45-
"idb-keyval": "^3.2.0",
44+
"fuse.js": "^6.4.6",
45+
"idb-keyval": "3.2.0",
4646
"lulumi": "^0.0.23",
4747
"nanoid": "^3.1.20",
4848
"vue": "^2.6.12",
4949
"vue-electron": "^1.0.6",
50-
"vue-i18n": "^8.22.2",
50+
"vue-i18n": "^8.22.3",
5151
"vue-router": "^3.4.9",
5252
"vuex": "^3.6.0"
5353
},
@@ -59,23 +59,23 @@
5959
"@babel/preset-env": "^7.12.11",
6060
"@babel/preset-typescript": "^7.12.7",
6161
"@babel/register": "^7.12.10",
62-
"@typescript-eslint/eslint-plugin": "^4.11.0",
63-
"@typescript-eslint/parser": "^4.11.0",
64-
"@types/chrome": "^0.0.127",
62+
"@typescript-eslint/eslint-plugin": "^4.13.0",
63+
"@typescript-eslint/parser": "^4.13.0",
64+
"@types/chrome": "^0.0.128",
6565
"@types/mocha": "^8.2.0",
66-
"@types/webpack": "^4.41.25",
66+
"@types/webpack": "^4.41.26",
6767
"@types/webpack-env": "^1.16.0",
6868
"@types/webpack-hot-middleware": "^2.25.3",
69-
"ava": "^3.14.0",
69+
"ava": "^3.15.0",
7070
"babel-eslint": "^10.1.0",
7171
"babel-loader": "^8.2.2",
72-
"cfonts": "^2.9.0",
72+
"cfonts": "^2.9.1",
7373
"chai": "^4.2.0",
7474
"chalk": "^4.1.0",
7575
"comlink": "^4.3.0",
76-
"copy-webpack-plugin": "^6.4.0",
76+
"copy-webpack-plugin": "6.4.0",
7777
"cross-env": "^7.0.3",
78-
"csp-html-webpack-plugin": "^5.0.1",
78+
"csp-html-webpack-plugin": "^5.1.0",
7979
"css-loader": "^5.0.1",
8080
"del": "^6.0.0",
8181
"devtron": "^1.4.0",
@@ -84,8 +84,8 @@
8484
"electron-packager": "^15.2.0",
8585
"electron-rebuild": "^2.3.4",
8686
"electron-util": "^0.14.2",
87-
"element-ui": "^2.14.1",
88-
"eslint": "^7.16.0",
87+
"element-ui": "^2.15.0",
88+
"eslint": "^7.17.0",
8989
"eslint-config-airbnb-base": "^14.2.1",
9090
"eslint-friendly-formatter": "^4.0.1",
9191
"eslint-import-resolver-webpack": "^0.13.0",
@@ -95,12 +95,12 @@
9595
"express": "^4.17.1",
9696
"file-loader": "^6.2.0",
9797
"fork-ts-checker-notifier-webpack-plugin": "^3.0.0",
98-
"fork-ts-checker-webpack-plugin": "^6.0.8",
98+
"fork-ts-checker-webpack-plugin": "^6.1.0",
9999
"git-rev-sync": "^3.0.1",
100-
"html-webpack-plugin": "^4.5.0",
100+
"html-webpack-plugin": "^4.5.1",
101101
"inject-loader": "^4.0.1",
102102
"iview": "^3.5.4",
103-
"karma": "^5.2.3",
103+
"karma": "^6.0.0",
104104
"karma-chai": "^0.1.0",
105105
"karma-coverage": "^2.0.3",
106106
"karma-electron": "^6.3.1",
@@ -109,10 +109,10 @@
109109
"karma-spec-reporter": "^0.0.32",
110110
"karma-webpack": "^4.0.2",
111111
"launch-editor-middleware": "^2.2.1",
112-
"less": "^4.0.0",
113-
"less-loader": "^7.2.0",
114-
"mime-types": "^2.1.27",
115-
"mini-css-extract-plugin": "^1.3.3",
112+
"less": "^4.1.0",
113+
"less-loader": "^7.2.1",
114+
"mime-types": "^2.1.28",
115+
"mini-css-extract-plugin": "^1.3.4",
116116
"mocha": "^8.2.1",
117117
"mockery": "^2.1.0",
118118
"modern-normalize": "^1.0.0",
@@ -122,12 +122,12 @@
122122
"pug": "^3.0.0",
123123
"pug-plain-loader": "^1.1.0",
124124
"require-dir": "^1.2.0",
125-
"sinon": "^9.2.2",
126-
"sortablejs": "^1.10.2",
125+
"sinon": "^9.2.3",
126+
"sortablejs": "^1.13.0",
127127
"spectron": "5.0.0",
128128
"style-loader": "^2.0.0",
129129
"tree-kill": "^1.2.2",
130-
"ts-loader": "^8.0.12",
130+
"ts-loader": "^8.0.14",
131131
"tslint": "^6.1.3",
132132
"tslint-config-airbnb": "^5.11.2",
133133
"typescript": "^4.1.3",
@@ -144,8 +144,8 @@
144144
"vue-style-loader": "^4.1.2",
145145
"vue-template-compiler": "^2.6.12",
146146
"webpack": "^4.45.0",
147-
"webpack-cli": "^4.2.0",
148-
"webpack-dev-middleware": "^4.0.2",
147+
"webpack-cli": "^4.3.1",
148+
"webpack-dev-middleware": "^4.1.0",
149149
"webpack-hot-middleware": "^2.25.0",
150150
"webpack-merge": "^5.7.3",
151151
"write-file-webpack-plugin": "^4.5.1"

src/main/constants.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ const lulumiRootPath = process.env.NODE_ENV === 'development'
66
const lulumiHelperPath = process.env.NODE_ENV === 'development'
77
? path.resolve(lulumiRootPath, 'src', 'helper')
88
: path.resolve(lulumiRootPath, 'dist');
9+
const lulumiPreloadPath = process.env.NODE_ENV === 'development'
10+
? `http://localhost:${require('../../.electron-vue/config').port}`
11+
: path.resolve(lulumiRootPath, 'dist');
912

1013
export default {
1114
lulumiRootPath,
1215
lulumiHelperPath,
16+
lulumiPreloadPath,
1317
devUserData: `${path.resolve(lulumiRootPath, 'userData')}`,
1418
testUserData: `${path.resolve(lulumiRootPath, 'test', 'userData')}`,
1519
lulumiPagesCustomProtocol: 'lulumi',
16-
lulumiPreloadPath: `${path.resolve(lulumiRootPath, 'dist')}`,
1720
lulumiPDFJSPath: `${path.resolve(lulumiHelperPath, 'pdfjs')}`,
18-
lulumiRev: 'dab6f25887f6e66a96e07990b6ce576d0316c750',
21+
lulumiRev: '9d2efbaa0bb8d90e30c1b73a7fcc620e9f453781',
1922
};

src/main/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function createWindow(options?: Electron.BrowserWindowConstructorOptions, callba
135135
minHeight: 500,
136136
titleBarStyle: 'hiddenInset',
137137
webPreferences: {
138+
worldSafeExecuteJavaScript: true,
138139
contextIsolation: false,
139140
nodeIntegration: true,
140141
webSecurity: false,
@@ -792,8 +793,8 @@ ipcMain.on('register-local-commands', (event: Electron.IpcMainEvent) => {
792793
});
793794

794795
ipcMain.on('fetch-search-suggestions',
795-
(event: Electron.IpcMainEvent, provider: string, url: string, timestamp: number) => {
796-
fetch(provider, url, (result) => {
796+
(event: Electron.IpcMainEvent, url: string, timestamp: number) => {
797+
fetch(url, (result) => {
797798
event.sender.send(`fetch-search-suggestions-${timestamp}`, result);
798799
});
799800
});

src/main/lib/fetch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { net } from 'electron';
44

5-
export default function fetch(provider: string, url: string, callback: ({ body: string, error: any, ok: boolean }) => any): void {
5+
export default function fetch(url: string, callback: ({ body: string, error: any, ok: boolean }) => any): void {
66
let bodyData = '';
77
const urlRequest = net.request(url);
88
urlRequest.on('response', (response) => {

src/main/lib/view.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22

3-
import { BrowserView } from 'electron';
3+
import { app, BrowserView } from 'electron';
44
import { Store } from 'vuex';
5+
import * as fs from 'fs';
56
import * as path from 'path';
67
import urlUtil from '../../renderer/lib/url-util';
78
import constants from '../constants';
9+
import fetch from './fetch';
810

911
const { default: mainStore } = require('../../shared/store/mainStore');
1012
const store: Store<any> = mainStore.getStore();
@@ -15,13 +17,22 @@ export default class View {
1517
public tabIndex: number;
1618

1719
private window: Electron.BrowserWindow;
20+
private preloadCachePath: string;
1821

1922
public constructor(window: Electron.BrowserWindow, tabIndex: number, tabId: number, url: string) {
23+
this.preloadCachePath = '';
24+
if (process.env.NODE_ENV === 'development') {
25+
this.fetchPreload(`${constants.lulumiPreloadPath}/webview-preload.js`);
26+
}
2027
this.browserView = new BrowserView({
2128
webPreferences: {
22-
preload: path.join(constants.lulumiPreloadPath, 'webview-preload.js'),
29+
preload: (this.preloadCachePath.length === 0)
30+
? path.join(constants.lulumiPreloadPath, 'webview-preload.js')
31+
: this.preloadCachePath,
32+
enableRemoteModule: true,
2333
nodeIntegration: false,
2434
nodeIntegrationInSubFrames: true,
35+
worldSafeExecuteJavaScript: true,
2536
contextIsolation: true,
2637
sandbox: false,
2738
partition: 'persist:lulumi',
@@ -221,4 +232,16 @@ export default class View {
221232
this.browserView.destroy();
222233
return this.browserView.isDestroyed();
223234
}
235+
236+
private fetchPreload(preloadPath: string): void {
237+
this.preloadCachePath = path.join(app.getPath('userData'), 'webview-preload.js');
238+
fetch(preloadPath, (result) => {
239+
if (result.ok) {
240+
if (!fs.existsSync(path.dirname(this.preloadCachePath))) {
241+
fs.mkdirSync(path.dirname(this.preloadCachePath));
242+
}
243+
fs.writeFileSync(this.preloadCachePath, result.body);
244+
}
245+
});
246+
}
224247
}

src/preloads/webview-preload.ts

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-len */
22

3-
import { ipcRenderer, remote, webFrame } from 'electron';
3+
import { contextBridge, ipcRenderer, remote, webFrame } from 'electron';
44
import * as urllib from 'url';
55

66
import requirePreload from './require-preload';
@@ -125,26 +125,23 @@ process.once('loaded', () => {
125125
if (document.location) {
126126
if (document.location.href.startsWith('lulumi://') ||
127127
(process.env.NODE_ENV === 'development' && document.location.href.startsWith('http://localhost:'))) {
128-
webFrame.executeJavaScript('window').then((window) => {
129-
window.about = ipcRenderer.sendSync('lulumi-scheme-loaded', document.location.href);
130-
window.backgroundPages = ipcRenderer.sendSync('get-background-pages');
131-
window.manifestMap = ipcRenderer.sendSync('get-manifest-map');
132-
window.renderProcessPreferences = ipcRenderer.sendSync('get-render-process-preferences');
133-
window.createFromPath = remote.nativeImage.createFromPath;
134-
window.join = require('path').join;
135-
136-
window.ipcRenderer = ipcRenderer;
137-
window.require = requirePreload.require;
138-
window.module = moduleTmp;
139-
// eslint-disable-next-line no-console
140-
}).catch(err => console.error(err));
128+
contextBridge.exposeInMainWorld('data', {
129+
about: ipcRenderer.sendSync('lulumi-scheme-loaded', document.location.href),
130+
backgroundPages: ipcRenderer.sendSync('get-background-pages'),
131+
manifestMap: ipcRenderer.sendSync('get-manifest-map'),
132+
renderProcessPreferences: ipcRenderer.sendSync('get-render-process-preferences'),
133+
});
134+
contextBridge.exposeInMainWorld('func', {
135+
createFromPath: remote.nativeImage.createFromPath,
136+
join: require('path').join,
137+
require: requirePreload.require,
138+
module: moduleTmp,
139+
ipcRenderer,
140+
});
141141
}
142142
if (process.env.NODE_ENV === 'test' &&
143143
process.env.TEST_ENV === 'e2e') {
144-
webFrame.executeJavaScript('window').then((window) => {
145-
window.require = requirePreload.electronRequire;
146-
// eslint-disable-next-line no-console
147-
}).catch(err => console.error(err));
144+
contextBridge.exposeInMainWorld('func', { require: requirePreload.electronRequire });
148145
}
149146
}
150147
ipcRenderer.on('lulumi-tabs-send-message', (event, message) => {

src/renderer/commandPalette/components/CPMainView/SearchBar.vue

-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ export default class SearchBar extends Vue {
254254
});
255255
ipc.send(
256256
'fetch-search-suggestions',
257-
currentSearchEngine,
258257
this.currentSearchEngine.autocomplete
259258
.replace('{queryString}', this.value)
260259
.replace('{language}', this.$store.getters.lang),

src/renderer/lib/url-util.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,8 @@ const urlUtil = {
9797
},
9898

9999
canParseURL(input: string): boolean {
100-
if (window === undefined) {
101-
return true;
102-
}
103100
try {
104-
const url = new window.URL(input);
101+
const url = new URL(input);
105102
return !!url;
106103
} catch (e) {
107104
return false;
@@ -186,7 +183,7 @@ const urlUtil = {
186183
}
187184

188185
try {
189-
return new window.URL(newInput).href;
186+
return new URL(newInput).href;
190187
} catch (e) {
191188
return newInput;
192189
}
@@ -265,9 +262,9 @@ const urlUtil = {
265262
getHostname(input: string, excludePort = false): string | null {
266263
try {
267264
if (excludePort) {
268-
return new window.URL(input).hostname;
265+
return new URL(input).hostname;
269266
}
270-
return new window.URL(input).host;
267+
return new URL(input).host;
271268
} catch (e) {
272269
return null;
273270
}
@@ -385,7 +382,7 @@ const urlUtil = {
385382
*/
386383
getDefaultFaviconUrl(url: string): string {
387384
if (urlUtil.isURL(url)) {
388-
const loc = new window.URL(url);
385+
const loc = new URL(url);
389386
return `${loc.protocol}//${loc.host}/favicon.ico`;
390387
}
391388
return '';

src/renderer/mainBrowserWindow/components/BrowserMainView/Navbar.vue

-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,6 @@ export default class Navbar extends Vue {
823823
});
824824
ipc.send(
825825
'fetch-search-suggestions',
826-
currentSearchEngine,
827826
this.currentSearchEngine.autocomplete
828827
.replace('{queryString}', this.value)
829828
.replace('{language}', this.$store.getters.lang),

src/renderer/mainBrowserWindow/constants.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ const tabConfig: Lulumi.Store.TabConfig = {
8181
extensionsMetadata: {},
8282
},
8383
lulumiDefault: {
84-
systemFavicon: nativeImage
85-
.createFromPath(fixPathForAsarUnpack(path.join(__static, 'icons', 'icon.png')))
86-
.toDataURL(),
84+
systemFavicon: (typeof __static === 'undefined')
85+
? ''
86+
: nativeImage.createFromPath(fixPathForAsarUnpack(path.join(__static, 'icons', 'icon.png'))).toDataURL(),
8787
tabFavicon: 'document',
8888
commandPalette: {
8989
browsingHistory: 'reading',

0 commit comments

Comments
 (0)