Skip to content

Commit

Permalink
screenshot, image editor
Browse files Browse the repository at this point in the history
  • Loading branch information
git committed Sep 21, 2024
1 parent cc8379a commit b3f1383
Show file tree
Hide file tree
Showing 42 changed files with 9,041 additions and 101 deletions.
5 changes: 5 additions & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ npm run dev
## License

GPL-3.0

## 本程序中使用到了以下开源项目,特此感谢

- [scrcpy](https://github.com/Genymobile/scrcpy)
- [image-beautifier](https://github.com/CH563/image-beautifier)
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ npm run dev
## License

GPL-3.0

## Thanks

- [scrcpy](https://github.com/Genymobile/scrcpy)
- [image-beautifier](https://github.com/CH563/image-beautifier)
38 changes: 19 additions & 19 deletions electron/config/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ const ready = () => {
],
})
}
menuTemplate.push({
label: t("帮助"),
role: "help",
submenu: [
// {
// label: t("教程帮助"),
// click: () => {
// createHelpWindow();
// },
// },
// {type: "separator"},
{
label: t("关于"),
click: () => {
PageAbout.create()
},
},
],
})
// menuTemplate.push({
// label: t("帮助"),
// role: "help",
// submenu: [
// // {
// // label: t("教程帮助"),
// // click: () => {
// // createHelpWindow();
// // },
// // },
// // {type: "separator"},
// // {
// // label: t("关于"),
// // click: () => {
// // PageAbout.open().then()
// // },
// // },
// ],
// })
const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
}
Expand Down
17 changes: 11 additions & 6 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {app, BrowserWindow, shell} from 'electron'
import {app, BrowserWindow, desktopCapturer, session, shell} from 'electron'
import {optimizer} from '@electron-toolkit/utils'
import path from 'node:path'
import os from 'node:os'
Expand All @@ -14,11 +14,11 @@ import {AppConfig} from "../../src/config";

import {buildResolve} from "../util/path";
import Log from "../mapi/log";
import Event from "../mapi/event";
import {ConfigMenu} from "../config/menu";
import {ConfigLang} from "../config/lang";
import {ConfigContextMenu} from "../config/contextMenu";
import {MAIN_DIST, RENDERER_DIST, VITE_DEV_SERVER_URL} from "../util/path-main";
import {Page} from "../page";

export const logoPath = buildResolve('logo.png')
export const icoLogoPath = buildResolve('logo.ico')
Expand Down Expand Up @@ -143,20 +143,25 @@ function createWindow() {
}
}, 1000);
}
Event.send('APP_READY', AppEnv)
Page.ready('main')
})

// Make all links open with the browser, not with the application
AppRuntime.mainWindow.webContents.setWindowOpenHandler(({url}) => {
if (url.startsWith('https:')) shell.openExternal(url)
return {action: 'deny'}
})
// AppRuntime.mainWindow.webContents.on('will-navigate', (event, url) => { }) #344
}

app.disableHardwareAcceleration();

app.whenReady()
.then(() => {
session.defaultSession.setDisplayMediaRequestHandler((request, callback) => {
desktopCapturer.getSources({types: ['screen']}).then((sources) => {
// Grant access to the first screen found.
callback({video: sources[0], audio: 'loopback'})
})
})
})
.then(ConfigLang.readyAsync)
.then(() => {
MAPI.ready()
Expand Down
19 changes: 0 additions & 19 deletions electron/mapi/event/index.ts

This file was deleted.

63 changes: 63 additions & 0 deletions electron/mapi/event/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {AppRuntime} from "../env";
import {ipcMain} from "electron";
import {StrUtil} from "../../lib/util";

const init = () => {

}

type NameType = 'main' | string
type EventType = 'APP_READY' | 'CUSTOM'

const send = (name: NameType, type: EventType, data: any = {}, id?: string): boolean => {
id = id || StrUtil.randomString(32)
const payload = {id, type, data}
if (name === 'main') {
if (!AppRuntime.mainWindow) {
return false
}
AppRuntime.mainWindow?.webContents.send('MAIN_PROCESS_MESSAGE', payload)
} else {
if (!AppRuntime.windows[name]) {
return false
}
AppRuntime.windows[name]?.webContents.send('MAIN_PROCESS_MESSAGE', payload)
}
return true
}

ipcMain.handle('event:send', async (_, name: NameType, type: EventType, data: any) => {
send(name, type, data)
})

ipcMain.handle('event:callCustom', async (_, name: string, type: string, data: any, option: any) => {
option = Object.assign({timeout: 10}, option)
return new Promise((resolve, reject) => {
const id = StrUtil.randomString(32)
const timer = setTimeout(() => {
ipcMain.removeListener(listenerKey, listener)
resolve({code: -1, msg: 'timeout'})
}, option.timeout * 1000)
const listener = (_, result) => {
clearTimeout(timer)
resolve(result)
return true
}
const listenerKey = 'event:callCustom:' + id
ipcMain.once(listenerKey, listener)
if (!send(name, 'CUSTOM', {type, data}, id)) {
clearTimeout(timer)
ipcMain.removeListener(listenerKey, listener)
resolve({code: -1, msg: 'send failed'})
}
})
})

export default {
init,
send
}

export const Events = {
send
}
14 changes: 13 additions & 1 deletion electron/mapi/event/render.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import {ipcRenderer} from "electron";

const init = () => {

}

const send = (name: string, type: string, data: any = {}) => {
ipcRenderer.invoke('event:send', name, type, data).then()
}

const callCustom = async (name: string, customType: string, data: any, option: any) => {
return ipcRenderer.invoke('event:callCustom', name, customType, data, option)
}

export default {
init
init,
send,
callCustom
}
4 changes: 3 additions & 1 deletion electron/mapi/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import log from "./log";
import app from "./app";
import storage from "./storage";
import file from "./file/main";
import event from "./event";
import event from "./event/main";
import ui from "./ui";
import keys from "./keys/main";
import page from "./page/main";

const $mapi = {
app,
Expand All @@ -16,6 +17,7 @@ const $mapi = {
event,
ui,
keys,
page,
}

export const MAPI = {
Expand Down
14 changes: 14 additions & 0 deletions electron/mapi/page/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {ipcMain} from "electron";
import {Page} from "../../page";

const open = async (name: string, option: any) => {
return await Page.open(name, option)
}

ipcMain.handle('page:open', async (event, name: string, option: any) => {
return open(name, option)
})

export default {
open
}
10 changes: 10 additions & 0 deletions electron/mapi/page/render.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {ipcRenderer} from "electron";


const open = async (name: string, option: any) => {
return ipcRenderer.invoke('page:open', name, option)
}

export default {
open
}
2 changes: 2 additions & 0 deletions electron/mapi/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ui from "./ui/render";
import updater from "./updater/render";
import statistics from "./statistics/render";
import lang from "./lang/render";
import page from "./page/render";
import adb from "./adb/render";
import scrcpy from "./scrcpy/render";

Expand All @@ -28,6 +29,7 @@ export const MAPI = {
ui,
updater,
statistics,
page,
lang,
adb,
scrcpy,
Expand Down
21 changes: 17 additions & 4 deletions electron/mapi/ui/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const initLoaders = () => {
align-items: center;
justify-content: center;
background: #f1f5f9;
z-index: 9;
z-index: 10000;
}
`
const oStyle = document.createElement('style')
Expand All @@ -88,10 +88,23 @@ const initLoaders = () => {
}

const {appendLoading, removeLoading} = useLoading()
domReady().then(appendLoading)

window.onmessage = (ev) => {
ev.data.payload === 'removeLoading' && removeLoading()
const isMain = () => {
let l = window.location.href
if (l.indexOf('app.asar/dist/index.html') > 0) {
return true
}
if (l.indexOf('localhost') > 0 && l.indexOf('.html') === -1) {
return true
}
return false
}

if (isMain()) {
domReady().then(appendLoading)
window.onmessage = (ev) => {
ev.data.payload === 'removeLoading' && removeLoading()
}
}

setTimeout(removeLoading, 4999)
Expand Down
27 changes: 10 additions & 17 deletions electron/page/about.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import {BrowserWindow} from "electron";
import {preloadDefault, rendererPath} from "../util/path-main";
import {preloadDefault} from "../util/path-main";
import {AppRuntime} from "../mapi/env";

import {t} from "../config/lang";
import {Page} from "./index";

export const PageAbout = {
create() {
NAME: 'about',
open: async (option: any) => {
const win = new BrowserWindow({
minWidth: 600,
title: t('关于'),
parent: AppRuntime.mainWindow,
minWidth: 800,
minHeight: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
Expand All @@ -17,18 +22,6 @@ export const PageAbout = {
frame: false,
transparent: false,
});

rendererPath(win, "page/about.html");

// await win.webContents.session.setProxy(store.get("代理"));

// win.webContents.openDevTools();

win.webContents.on("did-finish-load", () => {
// win.webContents.setZoomFactor(store.get("全局.缩放") || 1.0);
// win.webContents.send("about", about);
});

AppRuntime.windows['about'] = win;
return Page.openWindow(PageAbout.NAME, win, "page/about.html");
}
}
41 changes: 41 additions & 0 deletions electron/page/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {Events} from "../mapi/event/main";
import {AppEnv, AppRuntime} from "../mapi/env";
import {PageThirdPartyImageBeautifier} from "./thirdPartyImageBeautifier";
import {BrowserWindow, shell} from "electron";
import {rendererPath} from "../util/path-main";

const Pages = {
'thirdPartyImageBeautifier': PageThirdPartyImageBeautifier,
}

export const Page = {
ready(name: string) {
Events.send(name, 'APP_READY', {
name,
AppEnv
})
},
openWindow: (name: string, win: BrowserWindow, fileName: string) => {
rendererPath(win, fileName);
AppRuntime.windows[name] = win
win.webContents.setWindowOpenHandler(({url}) => {
if (url.startsWith('https:') || url.startsWith('http:')) {
shell.openExternal(url).then()
}
return {action: 'deny'}
})
win.on('close', () => {
delete AppRuntime.windows[name]
})
return new Promise((resolve, reject) => {
win.webContents.on("did-finish-load", () => {
Page.ready(name);
resolve(undefined);
});
});
},
open: async (name: string, option: any) => {
return Pages[name].open(option)
}
}

Loading

0 comments on commit b3f1383

Please sign in to comment.