forked from tickbh/VisualUIEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.js
More file actions
72 lines (60 loc) · 1.84 KB
/
protocol.js
File metadata and controls
72 lines (60 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
let Protocol = {};
module.exports = Protocol;
const Electron = require('electron');
const Console = require('./console');
const app = Electron.app;
var Url = require('url');
var Fs = require('fs');
Protocol.init = function() {
const protocol = Electron.protocol;
// register protocol app://
protocol.registerFileProtocol('app', (request, cb) => {
if (!request.url) {
cb(-3); // ABORTED
return;
}
let url = decodeURIComponent(request.url);
let uri = Url.parse(url);
let relativePath = uri.hostname;
if (uri.pathname) {
relativePath = relativePath + uri.pathname;
}
let file = app.getAppPath() + "/" + relativePath;
cb({ path: file });
}, err => {
if (err) {
Console.log('Failed to register protocol app, %s', err.message);
return;
}
Console.log('protocol app registered');
});
protocol.registerFileProtocol('packages', (request, cb) => {
if (!request.url) {
cb(-3); // ABORTED
return;
}
let url = decodeURIComponent(request.url);
let uri = Url.parse(url);
let relativePath = uri.hostname;
if (uri.pathname) {
relativePath = relativePath + uri.pathname;
}
let file = app.getAppPath() + "/package/" + relativePath;
if (Fs.existsSync(file)) {
cb({ path: file });
return;
}
file = app.getAppPath() + "/third/package/" + relativePath;
if (Fs.existsSync(file)) {
cb({ path: file });
return;
}
}, err => {
if (err) {
Console.log('Failed to register protocol app, %s', err.message);
return;
}
Console.log('protocol packages registered');
});
};