-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
304 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// @ts-check | ||
import { join, dirname } from 'path'; | ||
import { inspect } from 'util'; | ||
import { existsSync, mkdirSync, appendFileSync } from 'fs'; | ||
|
||
function formatDate() { | ||
const date = new Date(); | ||
return [ | ||
date.getFullYear(), | ||
String(date.getMonth() + 1).padStart(2, '0'), | ||
date.getDate().toString().padStart(2, '0') | ||
].join('-'); | ||
} | ||
|
||
/** | ||
* 日志对象 | ||
* ```js | ||
* const l = new LoggerCore(app.getPath("logs"), true, 'test') // create `${logs}/YYYY-MM-DD/test.log` | ||
* const l2 = new LoggerCore(app.getPath("logs"), true,'project','error','1') // create `${logs}/YYYY-MM-DD/project/error/1.log` | ||
* ``` | ||
*/ | ||
export class LoggerCore { | ||
basePath | ||
withConsole | ||
dest | ||
constructor(basePath: string, withConsole = true, ...name: string[]) { | ||
this.basePath = basePath; | ||
this.withConsole = withConsole; | ||
this.dest = join(this.basePath, '/', formatDate(), '/', name.join('/') + '.log'); | ||
} | ||
|
||
log = (...msg: any[]) => this._log(this.dest, '信息', ...msg) | ||
info = (...msg: any[]) => this._log(this.dest, '信息', ...msg) | ||
error = (...msg: any[]) => this._log(this.dest, '错误', ...msg) | ||
debug = (...msg: any[]) => this._log(this.dest, '调试', ...msg) | ||
warn = (...msg: any[]) => this._log(this.dest, '警告', ...msg) | ||
|
||
_log(dest: string, level: string, ...msg: string[]) { | ||
const data = msg | ||
.map((s) => { | ||
if (typeof s === 'object' || typeof s === 'function') { | ||
s = inspect(s); | ||
} | ||
return s; | ||
}) | ||
.join(' '); | ||
const txt = `[${level}] ${new Date().toLocaleString()} \t ` + data; | ||
|
||
if (this.withConsole) { | ||
console.log(txt); | ||
} | ||
|
||
return new Promise<void>((resolve) => { | ||
if (!existsSync(dirname(dest))) { | ||
mkdirSync(dirname(dest), { recursive: true }); | ||
} | ||
appendFileSync(dest, txt + '\n'); | ||
resolve(); | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// @ts-check | ||
import { LoggerCore } from './logger.core'; | ||
import { app } from 'electron'; | ||
|
||
export function Logger(...name: any[]) { | ||
return new LoggerCore(app.getPath('logs'), true, ...name); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// @ts-check | ||
import { BrowserWindow, app, shell } from 'electron'; | ||
import path from 'path'; | ||
|
||
app.disableHardwareAcceleration(); | ||
|
||
export function createWindow() { | ||
const win = new BrowserWindow({ | ||
title: 'ocs', | ||
icon: path.resolve('./public/favicon.ico'), | ||
|
||
minHeight: 500, | ||
minWidth: 800, | ||
center: true, | ||
frame: false, | ||
show: false, | ||
backgroundColor: '#fff', | ||
hasShadow: true, | ||
|
||
webPreferences: { | ||
// 关闭拼写矫正 | ||
spellcheck: false, | ||
webSecurity: true, | ||
// 开启node | ||
nodeIntegration: true, | ||
contextIsolation: false | ||
} | ||
}); | ||
|
||
win.on('new-window-for-tab', (event: any, url: any) => { | ||
event.preventDefault(); | ||
shell.openExternal(url); | ||
}); | ||
|
||
win.webContents.setWindowOpenHandler((detail) => { | ||
shell.openExternal(detail.url); | ||
return { | ||
action: 'deny' | ||
}; | ||
}); | ||
|
||
return win; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { app } from 'electron'; | ||
import path from 'path'; | ||
import { getValidBrowsers } from '@ocsjs/common'; | ||
import { UserScripts } from '../types'; | ||
|
||
export const appStore = { | ||
name: app.getName(), | ||
version: app.getVersion(), | ||
'user-data-path': app.getPath('userData'), | ||
'exe-path': app.getPath('exe'), | ||
'logs-path': app.getPath('logs'), | ||
'config-path': path.resolve(app.getPath('userData'), './config.json'), | ||
workspace: path.resolve(app.getPath('userData'), './workspace'), | ||
'auto-launch': false, | ||
alwaysOnTop: false, | ||
notify: [] as any[], | ||
/** 脚本启动设置 */ | ||
script: {} as any, | ||
/** 脚本默认设置 */ | ||
setting: { | ||
answererWrappers: [] | ||
}, | ||
/** 用户脚本列表 */ | ||
userScripts: [] as UserScripts[], | ||
/** 可以浏览器 */ | ||
validBrowsers: getValidBrowsers() | ||
}; |
8 changes: 3 additions & 5 deletions
8
packages/app/src/tasks/auto.launch.js → packages/app/src/tasks/auto.launch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
const { app } = require('electron'); | ||
const Store = require('electron-store'); | ||
import { app } from 'electron'; | ||
import Store from 'electron-store'; | ||
|
||
/** 配置自动启动 */ | ||
function autoLaunch () { | ||
export function autoLaunch() { | ||
if (app.isPackaged) { | ||
const store = new Store(); | ||
app.setLoginItemSettings({ | ||
openAtLogin: Boolean(store.get('auto-launch') || false) | ||
}); | ||
} | ||
} | ||
|
||
exports.autoLaunch = autoLaunch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.