Skip to content

Commit 424cca9

Browse files
committed
Switch to web server feed data to book.module.......A great progress.
1 parent 0ed8575 commit 424cca9

File tree

14 files changed

+269
-111
lines changed

14 files changed

+269
-111
lines changed

electron/db.sqlite

60 KB
Binary file not shown.

electron/package-lock.json

Lines changed: 62 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

electron/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
},
1313
"dependencies": {
1414
"@capacitor-community/electron": "^1.3.2",
15+
"node-static": "^0.7.11",
1516
"nodegit": "^0.27.0",
1617
"sqlite3": "^5.0.0",
17-
"typeorm": "^0.2.29"
18+
"typeorm": "^0.2.29",
19+
"yargs": "^16.2.0"
1820
},
1921
"devDependencies": {
2022
"@types/filesystem": "^0.0.29",
2123
"@types/fs-extra": "^9.0.5",
2224
"@types/node": "^14.14.12",
2325
"@types/nodegit": "^0.26.12",
26+
"@types/yargs": "^15.0.11",
2427
"electron": "^10.1.7",
2528
"electron-builder": "^22.9.1",
2629
"electron-packager": "^15.2.0",

electron/src/fsOps.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ const sortFn = (a: string, b: string) => {
8181
}
8282

8383
export const getList = (dir: string): Array<string> => {
84-
const resolvedPath = resolve(__dirname, dir);
85-
8684
const list = lookupMdFiles(dir).reduce((acc: Array<string>, i: string): Array<string> => {
87-
return i ? [...acc, i.replace(resolvedPath, '')] : acc;
85+
return i ? [...acc, i.replace(dir, '')] : acc;
8886
}, []);
8987

9088
return list.sort(sortFn);

electron/src/index.ts

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,66 @@
1-
import { app, Menu, BrowserWindow, ipcMain } from "electron";
1+
import { app, Menu, BrowserWindow, ipcMain, session } from "electron";
22
import { createCapacitorElectronApp } from "@capacitor-community/electron";
3+
import { fork, ChildProcess } from 'child_process';
34

45
import { join } from 'path';
56

7+
import { TableName,
8+
IpcChannel,
9+
ItemType,
10+
IWhereItem,
11+
IItem,
12+
IFindStatement,
13+
IFindCondition, } from './vendor';
14+
15+
import { conn, addItem, updateItem, getItems } from './crud';
16+
617
import { loadingWindow, bookWindow } from './window.children';
718
import { bookClone } from './bookOps';
819
//import { createMenuTemplate } from './menu_template';
9-
import { conn } from './crud';
10-
import { onGetItems, onAddItem, } from './ipc';
20+
1121
// The MainWindow object can be accessed via myCapacitorApp.getMainWindow()
1222

1323
const myCapacitorApp = createCapacitorElectronApp();
24+
1425
const winChildren: Array<Electron.BrowserWindow> = [];
26+
const processChildren: Array<ChildProcess> = [];
27+
1528
// This method will be called when Electron has finished
1629
// initialization and is ready to create browser windows.
1730
// Some Electron APIs can only be used after this event occurs.
1831
app.on("ready", () => {
1932

33+
const filter = {
34+
urls: [
35+
'http://localhost:10080/*',
36+
]
37+
};
38+
39+
session.defaultSession.webRequest.onBeforeSendHeaders(
40+
filter,
41+
(details, callback) => {
42+
console.log(details);
43+
details.requestHeaders['Origin'] = 'http://localhost:10080';
44+
callback({ requestHeaders: details.requestHeaders });
45+
}
46+
);
47+
48+
session.defaultSession.webRequest.onHeadersReceived(
49+
filter,
50+
(details, callback) => {
51+
console.log(details);
52+
details.responseHeaders['Access-Control-Allow-Origin'] = [
53+
'capacitor-electron://-'
54+
];
55+
callback({ responseHeaders: details.responseHeaders });
56+
}
57+
);
58+
2059
myCapacitorApp.init();
2160

2261
const booksDir = join(app.getPath('appData'), 'gbr_books');
62+
const serverProcess: ChildProcess = fork(join(__dirname, 'server.js'), ['-d', booksDir]);
63+
processChildren.push(serverProcess);
2364

2465
const mainWindow = myCapacitorApp.getMainWindow();
2566
const webContents = mainWindow.webContents;
@@ -40,7 +81,7 @@ app.on("ready", () => {
4081
});
4182

4283
ipcMain.on('open-book', (event, book) => {
43-
bookWindow(mainWindow, loadingWin, book, (win) => {
84+
bookWindow(mainWindow, loadingWin, book, booksDir, (win) => {
4485
winChildren.push(win);
4586
})
4687
});
@@ -65,6 +106,11 @@ app.on("window-all-closed", async () => {
65106
if(winChildren.length > 0){
66107
winChildren.map(w => w =null);
67108
}
109+
if(processChildren.length > 0){
110+
processChildren.map(p => {
111+
p.kill('SIGINT');
112+
});
113+
}
68114
app.quit();
69115
}
70116
return 0
@@ -78,5 +124,27 @@ app.on("activate", function () {
78124
});
79125

80126
// Define any IPC or other custom functionality below here
81-
onGetItems;
82-
onAddItem;
127+
ipcMain.on('add-item', async (event, item) =>{
128+
const table = item.table;
129+
let _item: ItemType;
130+
await addItem(item).then(_ => _item = _);
131+
132+
event.returnValue = _item;
133+
});
134+
135+
ipcMain.on('update-item', async (event, _item) =>{
136+
const table = _item.table;
137+
138+
let item: ItemType;
139+
await updateItem(_item).then(_ => item = _);
140+
141+
event.returnValue = item;
142+
});
143+
144+
ipcMain.on('get-items', async (event, getParam) => {
145+
const table = getParam.table;
146+
147+
let items: Array<ItemType>;
148+
await getItems(getParam).then(_ => items = _);
149+
event.returnValue = items;
150+
});

electron/src/ipc.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)