修复一个奇葩的DPI问题
parent
53c62fd3f6
commit
b42d7ae19a
13
package.json
13
package.json
|
@ -7,7 +7,10 @@
|
||||||
"start": "electron .",
|
"start": "electron .",
|
||||||
"pack": "electron-builder"
|
"pack": "electron-builder"
|
||||||
},
|
},
|
||||||
"author": { "name": "yutent", "email": "yutent@doui.cc" },
|
"author": {
|
||||||
|
"name": "yutent",
|
||||||
|
"email": "yutent@doui.cc"
|
||||||
|
},
|
||||||
"homepage": "https://yutent.me",
|
"homepage": "https://yutent.me",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -15,7 +18,7 @@
|
||||||
"iofs": "^1.1.0"
|
"iofs": "^1.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "^4.0.0",
|
"electron": "^4.0.2",
|
||||||
"electron-builder": "^20.38.5"
|
"electron-builder": "^20.38.5"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
|
@ -26,7 +29,11 @@
|
||||||
"buildResources": "icons",
|
"buildResources": "icons",
|
||||||
"output": "build"
|
"output": "build"
|
||||||
},
|
},
|
||||||
"files": ["src/**/*", "node_modules/iofs/*", "node_modules/crypto.js/*"],
|
"files": [
|
||||||
|
"src/**/*",
|
||||||
|
"node_modules/iofs/*",
|
||||||
|
"node_modules/crypto.js/*"
|
||||||
|
],
|
||||||
"mac": {
|
"mac": {
|
||||||
"category": "public.app-category.music",
|
"category": "public.app-category.music",
|
||||||
"target": "dmg",
|
"target": "dmg",
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
|
<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/reset-basic.css" rel="stylesheet">
|
||||||
<link href="lib/css/elem-ui.css" rel="stylesheet">
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
.do-fn-drag {-webkit-app-region:drag;user-select: none;}
|
.do-fn-drag {-webkit-app-region:drag;user-select: none;}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<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/reset-basic.css" rel="stylesheet">
|
||||||
<link href="lib/css/elem-ui.css" rel="stylesheet">
|
<link href="lib/css/elem-ui.css" rel="stylesheet">
|
||||||
<link href="css/common.css" rel="stylesheet">
|
<link href="css/common.css" rel="stylesheet">
|
||||||
|
|
|
@ -27,7 +27,8 @@ export const createDesktopLrcWindow = function(screen) {
|
||||||
show: false
|
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
|
return win
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ export const createMiniWindow = function(screen, pwin) {
|
||||||
show: false
|
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
|
return win
|
||||||
}
|
}
|
||||||
|
|
49
src/main.js
49
src/main.js
|
@ -5,15 +5,25 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
const { app, BrowserWindow, session } = require('electron')
|
const { app, BrowserWindow, session, protocol } = require('electron')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('iofs')
|
const fs = require('iofs')
|
||||||
const { exec } = require('child_process')
|
const { exec } = require('child_process')
|
||||||
const log = console.log
|
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 createTray = require('./tools/tray')
|
||||||
const createMenu = require('./tools/menu')
|
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.commandLine.appendSwitch('--autoplay-policy', 'no-user-gesture-required')
|
||||||
|
|
||||||
app.setPath('appData', path.resolve(HOME, '.sonist/'))
|
app.setPath('appData', path.resolve(HOME, '.sonist/'))
|
||||||
// protocol.registerStandardSchemes(['app'], { secure: true })
|
protocol.registerStandardSchemes(['app'], { secure: true })
|
||||||
|
|
||||||
let appPath = app.getPath('appData')
|
let appPath = app.getPath('appData')
|
||||||
if (!fs.exists(appPath)) {
|
if (!fs.exists(appPath)) {
|
||||||
|
@ -48,14 +58,9 @@ if (!fs.exists(appPath)) {
|
||||||
}
|
}
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
|
|
||||||
createServer(ROOT)
|
|
||||||
|
|
||||||
// throw new Error('hee')
|
|
||||||
let win = null
|
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
// 创建浏览器窗口
|
// 创建浏览器窗口
|
||||||
win = new BrowserWindow({
|
let win = new BrowserWindow({
|
||||||
title: 'sonist',
|
title: 'sonist',
|
||||||
width: 1024,
|
width: 1024,
|
||||||
height: 640,
|
height: 640,
|
||||||
|
@ -70,10 +75,15 @@ function createWindow() {
|
||||||
})
|
})
|
||||||
|
|
||||||
// 然后加载应用的 index.html。
|
// 然后加载应用的 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 ******************* */
|
/* ************* init ******************* */
|
||||||
|
@ -81,21 +91,22 @@ function createWindow() {
|
||||||
|
|
||||||
// 创建窗口
|
// 创建窗口
|
||||||
app.once('ready', () => {
|
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) => {
|
exec('which ffprobe', (err, res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
session.defaultSession.setUserAgent(
|
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'
|
'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)
|
createTray(win)
|
||||||
createMenu(win)
|
createMenu(win)
|
||||||
|
|
||||||
win.on('ready-to-show', _ => {
|
|
||||||
win.show()
|
|
||||||
})
|
|
||||||
win.openDevTools()
|
|
||||||
} else {
|
} else {
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
width: 600,
|
width: 600,
|
||||||
|
@ -107,7 +118,7 @@ app.once('ready', () => {
|
||||||
titleBarStyle: 'hiddenInset'
|
titleBarStyle: 'hiddenInset'
|
||||||
})
|
})
|
||||||
win.setMenuBarVisibility(false)
|
win.setMenuBarVisibility(false)
|
||||||
win.loadURL('http://127.0.0.1:10240/depends.html')
|
win.loadURL('app://local/depends.html')
|
||||||
win.on('closed', _ => {
|
win.on('closed', _ => {
|
||||||
app.exit()
|
app.exit()
|
||||||
})
|
})
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
Reference in New Issue