diff --git a/LICENSE.md b/LICENSE.md index 1421f76..4aa511c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -6,4 +6,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index e793b9f..71d77b2 100644 --- a/README.md +++ b/README.md @@ -4,25 +4,29 @@ Content File Management Program. For study about nodejs, typescript and react. ### deployment + ```bash pnpm run app:build ``` ### test + ```bash $ pnpm run app ``` ### server build + ```bash $ pnpm run compile ``` ### client build + ```bash $ pnpm run build ``` ## License -MIT License \ No newline at end of file +MIT License diff --git a/app.ts b/app.ts index 3aad477..27c6636 100644 --- a/app.ts +++ b/app.ts @@ -1,115 +1,113 @@ -import { app, BrowserWindow, session, dialog } from "electron"; -import { get_setting } from "./src/SettingConfig"; -import { create_server } from "./src/server"; -import { getAdminAccessTokenValue,getAdminRefreshTokenValue, accessTokenName, refreshTokenName } from "./src/login"; +import { app, BrowserWindow, dialog, session } from "electron"; +import { ipcMain } from "electron"; import { join } from "path"; -import { ipcMain } from 'electron'; +import { accessTokenName, getAdminAccessTokenValue, getAdminRefreshTokenValue, refreshTokenName } from "./src/login"; import { UserAccessor } from "./src/model/mod"; +import { create_server } from "./src/server"; +import { get_setting } from "./src/SettingConfig"; -function registerChannel(cntr: UserAccessor){ - ipcMain.handle('reset_password', async(event,username:string,password:string)=>{ - const user = await cntr.findUser(username); - if(user === undefined){ - return false; - } - user.reset_password(password); - return true; - }); +function registerChannel(cntr: UserAccessor) { + ipcMain.handle("reset_password", async (event, username: string, password: string) => { + const user = await cntr.findUser(username); + if (user === undefined) { + return false; + } + user.reset_password(password); + return true; + }); } const setting = get_setting(); if (!setting.cli) { - let wnd: BrowserWindow | null = null; + let wnd: BrowserWindow | null = null; - const createWindow = async () => { - wnd = new BrowserWindow({ - width: 800, - height: 600, - center: true, - useContentSize: true, - webPreferences:{ - preload:join(__dirname,'preload.js'), - contextIsolation:true, - } - }); - await wnd.loadURL(`data:text/html;base64,`+Buffer.from(loading_html).toString('base64')); - //await wnd.loadURL('../loading.html'); - //set admin cookies. - await session.defaultSession.cookies.set({ - url:`http://localhost:${setting.port}`, - name:accessTokenName, - value:getAdminAccessTokenValue(), - httpOnly: true, - secure: false, - sameSite:"strict" - }); - await session.defaultSession.cookies.set({ - url:`http://localhost:${setting.port}`, - name:refreshTokenName, - value:getAdminRefreshTokenValue(), - httpOnly: true, - secure: false, - sameSite:"strict" - }); - try{ - const server = await create_server(); - const app = server.start_server(); - registerChannel(server.userController); - await wnd.loadURL(`http://localhost:${setting.port}`); - } - catch(e){ - if(e instanceof Error){ - await dialog.showMessageBox({ - type: "error", - title:"error!", - message:e.message, + const createWindow = async () => { + wnd = new BrowserWindow({ + width: 800, + height: 600, + center: true, + useContentSize: true, + webPreferences: { + preload: join(__dirname, "preload.js"), + contextIsolation: true, + }, }); - } - else{ - await dialog.showMessageBox({ - type: "error", - title:"error!", - message:String(e), + await wnd.loadURL(`data:text/html;base64,` + Buffer.from(loading_html).toString("base64")); + // await wnd.loadURL('../loading.html'); + // set admin cookies. + await session.defaultSession.cookies.set({ + url: `http://localhost:${setting.port}`, + name: accessTokenName, + value: getAdminAccessTokenValue(), + httpOnly: true, + secure: false, + sameSite: "strict", }); - } + await session.defaultSession.cookies.set({ + url: `http://localhost:${setting.port}`, + name: refreshTokenName, + value: getAdminRefreshTokenValue(), + httpOnly: true, + secure: false, + sameSite: "strict", + }); + try { + const server = await create_server(); + const app = server.start_server(); + registerChannel(server.userController); + await wnd.loadURL(`http://localhost:${setting.port}`); + } catch (e) { + if (e instanceof Error) { + await dialog.showMessageBox({ + type: "error", + title: "error!", + message: e.message, + }); + } else { + await dialog.showMessageBox({ + type: "error", + title: "error!", + message: String(e), + }); + } + } + wnd.on("closed", () => { + wnd = null; + }); + }; + + const isPrimary = app.requestSingleInstanceLock(); + if (!isPrimary) { + app.quit(); // exit window + app.exit(); } - wnd.on("closed", () => { - wnd = null; + app.on("second-instance", () => { + if (wnd != null) { + if (wnd.isMinimized()) { + wnd.restore(); + } + wnd.focus(); + } + }); + app.on("ready", (event, info) => { + createWindow(); }); - }; - const isPrimary = app.requestSingleInstanceLock(); - if (!isPrimary) { - app.quit(); //exit window - app.exit(); - } - app.on("second-instance", () => { - if (wnd != null) { - if (wnd.isMinimized()) { - wnd.restore(); - } - wnd.focus(); - } - }); - app.on("ready", (event, info) => { - createWindow(); - }); + app.on("window-all-closed", () => { // quit when all windows are closed + if (process.platform != "darwin") app.quit(); // (except leave MacOS app active until Cmd+Q) + }); - app.on("window-all-closed", () => { // quit when all windows are closed - if (process.platform != "darwin") app.quit(); // (except leave MacOS app active until Cmd+Q) - }); - - app.on("activate", () => { // re-recreate window when dock icon is clicked and no other windows open - if (wnd == null) createWindow(); - }); + app.on("activate", () => { // re-recreate window when dock icon is clicked and no other windows open + if (wnd == null) createWindow(); + }); } else { - (async () => { - try { - const server = await create_server(); - server.start_server(); - } catch (error) { - console.log(error); - } - })(); + (async () => { + try { + const server = await create_server(); + server.start_server(); + } catch (error) { + console.log(error); + } + })(); } const loading_html = `
@@ -142,4 +140,4 @@ h1 {