This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
appcat
/
sonist
Archived
1
0
Fork 0

修复一个奇葩的DPI问题

2.x
宇天 2019-01-26 01:48:42 +08:00
parent 53c62fd3f6
commit b42d7ae19a
6 changed files with 44 additions and 63 deletions

View File

@ -7,7 +7,10 @@
"start": "electron .",
"pack": "electron-builder"
},
"author": { "name": "yutent", "email": "yutent@doui.cc" },
"author": {
"name": "yutent",
"email": "yutent@doui.cc"
},
"homepage": "https://yutent.me",
"license": "MIT",
"dependencies": {
@ -15,7 +18,7 @@
"iofs": "^1.1.0"
},
"devDependencies": {
"electron": "^4.0.0",
"electron": "^4.0.2",
"electron-builder": "^20.38.5"
},
"build": {
@ -26,7 +29,11 @@
"buildResources": "icons",
"output": "build"
},
"files": ["src/**/*", "node_modules/iofs/*", "node_modules/crypto.js/*"],
"files": [
"src/**/*",
"node_modules/iofs/*",
"node_modules/crypto.js/*"
],
"mac": {
"category": "public.app-category.music",
"target": "dmg",

View File

@ -4,7 +4,6 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<link href="lib/css/reset-basic.css" rel="stylesheet">
<link href="lib/css/elem-ui.css" rel="stylesheet">
<style>
.do-fn-drag {-webkit-app-region:drag;user-select: none;}

View File

@ -2,7 +2,6 @@
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<link href="lib/css/reset-basic.css" rel="stylesheet">
<link href="lib/css/elem-ui.css" rel="stylesheet">
<link href="css/common.css" rel="stylesheet">

View File

@ -27,7 +27,8 @@ export const createDesktopLrcWindow = function(screen) {
show: false
})
win.loadURL('http://127.0.0.1:10240/desktop-lrc.html')
// win.loadURL('http://127.0.0.1:10240/desktop-lrc.html')
win.loadURL('app://local/desktop-lrc.html')
return win
}
@ -46,6 +47,7 @@ export const createMiniWindow = function(screen, pwin) {
show: false
})
win.loadURL('http://127.0.0.1:10240/mini-win.html')
// win.loadURL('http://127.0.0.1:10240/mini-win.html')
win.loadURL('app://local/mini-win.html')
return win
}

View File

@ -5,15 +5,25 @@
*/
'use strict'
const { app, BrowserWindow, session } = require('electron')
const { app, BrowserWindow, session, protocol } = require('electron')
const path = require('path')
const fs = require('iofs')
const { exec } = require('child_process')
const log = console.log
const MIME_TYPES = {
'.js': 'text/javascript',
'.html': 'text/html',
'.htm': 'text/plain',
'.css': 'text/css',
'.jpg': 'image/jpg',
'.png': 'image/png',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.ico': 'image/ico'
}
const createTray = require('./tools/tray')
const createMenu = require('./tools/menu')
const createServer = require('./tools/server')
/* ******************************* */
/* **********修复环境变量*********** */
@ -36,7 +46,7 @@ app.commandLine.appendSwitch('--lang', 'zh-CN')
app.commandLine.appendSwitch('--autoplay-policy', 'no-user-gesture-required')
app.setPath('appData', path.resolve(HOME, '.sonist/'))
// protocol.registerStandardSchemes(['app'], { secure: true })
protocol.registerStandardSchemes(['app'], { secure: true })
let appPath = app.getPath('appData')
if (!fs.exists(appPath)) {
@ -48,14 +58,9 @@ if (!fs.exists(appPath)) {
}
/* ----------------------------------------------------- */
createServer(ROOT)
// throw new Error('hee')
let win = null
function createWindow() {
// 创建浏览器窗口
win = new BrowserWindow({
let win = new BrowserWindow({
title: 'sonist',
width: 1024,
height: 640,
@ -70,10 +75,15 @@ function createWindow() {
})
// 然后加载应用的 index.html。
// win.loadURL('https://yutent.me')
win.loadURL(`http://127.0.0.1:10240/index.html`)
// win.loadURL('app://sonist/index.html')
win.loadURL('app://local/index.html')
win.on('ready-to-show', _ => {
win.show()
win.openDevTools()
})
return win
}
/* ****************************************** */
/* ************* init ******************* */
@ -81,21 +91,22 @@ function createWindow() {
// 创建窗口
app.once('ready', () => {
protocol.registerBufferProtocol('app', (req, cb) => {
let file = req.url.replace(/^app:\/\/local\//, '')
let ext = path.extname(req.url)
let buff = fs.cat(path.resolve(ROOT, file))
cb({ data: buff, mimeType: MIME_TYPES[ext] })
})
exec('which ffprobe', (err, res) => {
if (res) {
session.defaultSession.setUserAgent(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
)
createWindow()
let win = createWindow()
createTray(win)
createMenu(win)
win.on('ready-to-show', _ => {
win.show()
})
win.openDevTools()
} else {
win = new BrowserWindow({
width: 600,
@ -107,7 +118,7 @@ app.once('ready', () => {
titleBarStyle: 'hiddenInset'
})
win.setMenuBarVisibility(false)
win.loadURL('http://127.0.0.1:10240/depends.html')
win.loadURL('app://local/depends.html')
win.on('closed', _ => {
app.exit()
})

View File

@ -1,37 +0,0 @@
/**
* 内置HTTP静态服务
* @author yutent<yutent@doui.cc>
* @date 2019/01/23 02:43:03
*/
'use strict'
const http = require('http')
const path = require('path')
const fs = require('iofs')
const MIME_TYPES = {
'.js': 'text/javascript; charset=utf-8',
'.html': 'text/html; charset=utf-8',
'.htm': 'text/plain; charset=utf-8',
'.css': 'text/css; charset=utf-8',
'.jpg': 'image/jpg',
'.png': 'image/png',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.ico': 'image/ico'
}
module.exports = function(root) {
http
.createServer((req, res) => {
let { ext } = path.parse(req.url)
let file = path.resolve(root, req.url.slice(1))
let buff = fs.cat(file)
res.writeHead(200, {
'Content-Type': MIME_TYPES[ext] || MIME_TYPES['.html']
})
res.end(buff)
})
.listen(10240)
}