mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-08 01:01:13 +08:00
🔨 Refactor(custom): refactor private to sharp in es6
This commit is contained in:
@@ -10,22 +10,22 @@ import { BrowserWindow } from 'electron'
|
||||
import { IWindowList } from '#/types/enum'
|
||||
|
||||
class WindowManager implements IWindowManager {
|
||||
private windowMap: Map<IWindowList | string, BrowserWindow> = new Map()
|
||||
private windowIdMap: Map<number, IWindowList | string> = new Map()
|
||||
#windowMap: Map<IWindowList | string, BrowserWindow> = new Map()
|
||||
#windowIdMap: Map<number, IWindowList | string> = new Map()
|
||||
create (name: IWindowList) {
|
||||
const windowConfig: IWindowListItem = windowList.get(name)!
|
||||
if (windowConfig.isValid) {
|
||||
if (!windowConfig.multiple) {
|
||||
if (this.has(name)) return this.windowMap.get(name)!
|
||||
if (this.has(name)) return this.#windowMap.get(name)!
|
||||
}
|
||||
const window = new BrowserWindow(windowConfig.options())
|
||||
const id = window.id
|
||||
if (windowConfig.multiple) {
|
||||
this.windowMap.set(`${name}_${window.id}`, window)
|
||||
this.windowIdMap.set(window.id, `${name}_${window.id}`)
|
||||
this.#windowMap.set(`${name}_${window.id}`, window)
|
||||
this.#windowIdMap.set(window.id, `${name}_${window.id}`)
|
||||
} else {
|
||||
this.windowMap.set(name, window)
|
||||
this.windowIdMap.set(window.id, name)
|
||||
this.#windowMap.set(name, window)
|
||||
this.#windowIdMap.set(window.id, name)
|
||||
}
|
||||
windowConfig.callback(window, this)
|
||||
window.on('close', () => {
|
||||
@@ -39,7 +39,7 @@ class WindowManager implements IWindowManager {
|
||||
|
||||
get (name: IWindowList) {
|
||||
if (this.has(name)) {
|
||||
return this.windowMap.get(name)!
|
||||
return this.#windowMap.get(name)!
|
||||
} else {
|
||||
const window = this.create(name)
|
||||
return window
|
||||
@@ -47,24 +47,24 @@ class WindowManager implements IWindowManager {
|
||||
}
|
||||
|
||||
has (name: IWindowList) {
|
||||
return this.windowMap.has(name)
|
||||
return this.#windowMap.has(name)
|
||||
}
|
||||
|
||||
deleteById = (id: number) => {
|
||||
const name = this.windowIdMap.get(id)
|
||||
const name = this.#windowIdMap.get(id)
|
||||
if (name) {
|
||||
this.windowMap.delete(name)
|
||||
this.windowIdMap.delete(id)
|
||||
this.#windowMap.delete(name)
|
||||
this.#windowIdMap.delete(id)
|
||||
}
|
||||
}
|
||||
|
||||
getAvailableWindow (isSkipMiniWindow = false) {
|
||||
const miniWindow = this.windowMap.get(IWindowList.MINI_WINDOW)
|
||||
const miniWindow = this.#windowMap.get(IWindowList.MINI_WINDOW)
|
||||
if (miniWindow && miniWindow.isVisible() && !isSkipMiniWindow) {
|
||||
return miniWindow
|
||||
} else {
|
||||
const settingWindow = this.windowMap.get(IWindowList.SETTING_WINDOW)
|
||||
const trayWindow = this.windowMap.get(IWindowList.TRAY_WINDOW)
|
||||
const settingWindow = this.#windowMap.get(IWindowList.SETTING_WINDOW)
|
||||
const trayWindow = this.#windowMap.get(IWindowList.TRAY_WINDOW)
|
||||
return settingWindow || trayWindow || this.create(IWindowList.SETTING_WINDOW)!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ const CONFIG_PATH: string = dbPathChecker()
|
||||
export const DB_PATH: string = getGalleryDBPath().dbPath
|
||||
|
||||
class ConfigStore {
|
||||
private db: JSONStore
|
||||
#db: JSONStore
|
||||
constructor () {
|
||||
this.db = new JSONStore(CONFIG_PATH)
|
||||
this.#db = new JSONStore(CONFIG_PATH)
|
||||
|
||||
if (!this.db.has('picBed')) {
|
||||
this.db.set('picBed', {
|
||||
if (!this.#db.has('picBed')) {
|
||||
this.#db.set('picBed', {
|
||||
current: 'smms', // deprecated
|
||||
uploader: 'smms',
|
||||
smms: {
|
||||
@@ -38,8 +38,8 @@ class ConfigStore {
|
||||
})
|
||||
}
|
||||
|
||||
if (!this.db.has(configPaths.settings.shortKey._path)) {
|
||||
this.db.set(configPaths.settings.shortKey['picgo:upload'], {
|
||||
if (!this.#db.has(configPaths.settings.shortKey._path)) {
|
||||
this.#db.set(configPaths.settings.shortKey['picgo:upload'], {
|
||||
enable: true,
|
||||
key: 'CommandOrControl+Shift+P',
|
||||
name: 'upload',
|
||||
@@ -50,31 +50,31 @@ class ConfigStore {
|
||||
}
|
||||
|
||||
flush () {
|
||||
this.db = new JSONStore(CONFIG_PATH)
|
||||
this.#db = new JSONStore(CONFIG_PATH)
|
||||
}
|
||||
|
||||
read () {
|
||||
this.db.read()
|
||||
return this.db
|
||||
this.#db.read()
|
||||
return this.#db
|
||||
}
|
||||
|
||||
get (key = ''): any {
|
||||
if (key === '') {
|
||||
return this.db.read()
|
||||
return this.#db.read()
|
||||
}
|
||||
return this.db.get(key)
|
||||
return this.#db.get(key)
|
||||
}
|
||||
|
||||
set (key: string, value: any): void {
|
||||
return this.db.set(key, value)
|
||||
return this.#db.set(key, value)
|
||||
}
|
||||
|
||||
has (key: string) {
|
||||
return this.db.has(key)
|
||||
return this.#db.has(key)
|
||||
}
|
||||
|
||||
unset (key: string, value: any): boolean {
|
||||
return this.db.unset(key, value)
|
||||
return this.#db.unset(key, value)
|
||||
}
|
||||
|
||||
getConfigPath () {
|
||||
@@ -88,16 +88,16 @@ export default db
|
||||
|
||||
// v2.3.0 add gallery db
|
||||
class GalleryDB {
|
||||
private static instance: DBStore
|
||||
static #instance: DBStore
|
||||
private constructor () {
|
||||
console.log('init gallery db')
|
||||
}
|
||||
|
||||
public static getInstance (): DBStore {
|
||||
if (!GalleryDB.instance) {
|
||||
GalleryDB.instance = new DBStore(DB_PATH, 'gallery')
|
||||
static getInstance (): DBStore {
|
||||
if (!GalleryDB.#instance) {
|
||||
GalleryDB.#instance = new DBStore(DB_PATH, 'gallery')
|
||||
}
|
||||
return GalleryDB.instance
|
||||
return GalleryDB.#instance
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class GuiApi implements IGuiApi {
|
||||
console.log('init guiapi')
|
||||
}
|
||||
|
||||
public static getInstance (): GuiApi {
|
||||
static getInstance (): GuiApi {
|
||||
if (!GuiApi.instance) {
|
||||
GuiApi.instance = new GuiApi()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user