Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit 8d5cb19

Browse files
committed
패키지 전체 업데이트 및 네이밍 변경
1 parent da2cb3d commit 8d5cb19

File tree

24 files changed

+554
-776
lines changed

24 files changed

+554
-776
lines changed

electron/app.ts renamed to app/app.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { app, BrowserWindow, Menu, nativeImage, Tray } from 'electron';
33
import { join } from 'path';
44

55
import { productName, protocols } from '../electron-builder.json';
6+
import { globImport } from './utils/import';
67

7-
export type MyAppType = InstanceType<typeof MyApp>;
8-
export type ModuleFunction = (app: MyAppType) => void | Promise<void>;
8+
export type AppContextType = InstanceType<typeof AppContext>;
9+
export type ModuleFunction = (context: AppContextType) => void | Promise<void>;
910

10-
class MyApp {
11+
class AppContext {
1112
// deep link protocol
1213
readonly PROTOCOL = protocols.name;
1314

@@ -37,6 +38,7 @@ class MyApp {
3738
async bootstrap() {
3839
await this.initliazeElectron();
3940
await this.autoload();
41+
await this.createWindow();
4042
}
4143

4244
async initliazeElectron() {
@@ -58,7 +60,6 @@ class MyApp {
5860
});
5961

6062
await app.whenReady();
61-
await this.createWindow();
6263
await this.createTray();
6364
}
6465

@@ -88,11 +89,9 @@ class MyApp {
8889
this.window.loadFile(this.PROD_LOAD_FILE_PATH, {
8990
hash: this.PROD_LOAD_FILE_HASH,
9091
});
91-
92-
this.window.webContents.openDevTools(); // FIXME: Remove this line
9392
} else {
94-
this.window.loadURL(this.DEV_URL);
95-
this.window.webContents.openDevTools(); // FIXME: Remove this line
93+
await this.window.loadURL(this.DEV_URL);
94+
this.window.webContents.openDevTools();
9695
}
9796

9897
this.window.on('ready-to-show', () => {
@@ -119,14 +118,10 @@ class MyApp {
119118
}
120119

121120
async autoload() {
122-
const modules = import.meta.glob<{ default: ModuleFunction }>('./modules/**/index.ts', {
123-
eager: true,
124-
});
121+
const modules = await globImport('./modules/**/index.js', { cwd: __dirname });
125122

126-
for (const module of Object.values(modules)) {
127-
await this.register(module.default);
128-
}
123+
await Promise.all(modules.map(({ default: module }) => this.register(module)));
129124
}
130125
}
131126

132-
export default MyApp;
127+
export default AppContext;

app/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import AppContext from './app';
2+
3+
(async () => {
4+
const context = new AppContext();
5+
await context.bootstrap();
6+
})();

app/modules/deepLink/index.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { app } from 'electron';
2+
3+
import { match, MatchResult } from 'path-to-regexp';
4+
5+
import { ModuleFunction, AppContextType } from '@app/app';
6+
import { globImport } from '@app/utils/import';
7+
8+
export type DeepLinkResolvers = Record<
9+
string,
10+
(matchResult: MatchResult<any>, app: AppContextType) => void
11+
>;
12+
13+
const DeepLinkModule: ModuleFunction = async context => {
14+
const modules = await globImport('./resolvers/**/*.resolver.js', { cwd: __dirname });
15+
16+
const resolvers: DeepLinkResolvers = modules.reduce((resolvers, module) => {
17+
return { ...resolvers, ...module.default };
18+
}, {});
19+
20+
const runDeepLinkResolver = (url: string) => {
21+
const pathname = url.replace(`${context.PROTOCOL}://`, '/');
22+
23+
for (const path in resolvers) {
24+
const data = match(path)(pathname);
25+
26+
if (data) {
27+
resolvers[path](data, context);
28+
break;
29+
}
30+
}
31+
};
32+
33+
app.on('second-instance', (_, argv) => {
34+
if (!context.IS_MAC) {
35+
const url = argv.find(arg => arg.startsWith(`${context.PROTOCOL}://`));
36+
37+
if (url) {
38+
runDeepLinkResolver(url);
39+
}
40+
}
41+
42+
context.createWindow();
43+
});
44+
45+
app.on('open-url', (_, url) => {
46+
runDeepLinkResolver(url);
47+
});
48+
};
49+
50+
export default DeepLinkModule;
File renamed without changes.
Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
1-
import { contextBridge, ipcRenderer } from 'electron';
1+
import { ElectronRendererContext } from '@app/types/preload';
22

3-
import { Log } from '../modules/developers';
4-
import { AppControlAction } from '../modules/general';
5-
import { UpdateEvent, UpdateStatus } from '../modules/update';
6-
import { ConfigStoreValues } from '../stores/config';
7-
8-
export interface ElectronRendererContext {
9-
onUpdate: (callback: (event: UpdateEvent, data: any) => void) => void;
10-
11-
initlizeUpdater: () => void;
12-
appControl: (action: AppControlAction) => void;
13-
openExternal: (link: string) => void;
14-
checkForUpdate: () => void;
15-
quitAndInstall: () => void;
16-
17-
getConfig: () => Promise<ConfigStoreValues>;
18-
setConfig: (config: ConfigStoreValues) => Promise<ConfigStoreValues>;
19-
20-
getVersion: () => Promise<string>;
21-
getUpdaterStatus: () => Promise<UpdateStatus>;
22-
23-
getStorePath: () => Promise<string>;
24-
getLogs: () => Promise<Log[]>;
25-
clearLogs: () => Promise<boolean>;
26-
}
3+
const { contextBridge, ipcRenderer } = require('electron');
274

285
const electronContext: ElectronRendererContext = {
296
onUpdate: callback => ipcRenderer.on('update', (_, event, data) => callback(event, data)),

0 commit comments

Comments
 (0)