提交 951cd909 编写于 作者: B baiy 提交者: ninecents

初步适配firefox #70 #8

上级 f44b8075
{ {
"name": "c-tool", "name": "c-tool",
"version": "1.7.7", "version": "1.7.10",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
...@@ -12643,17 +12643,17 @@ ...@@ -12643,17 +12643,17 @@
"from": "github:abdolence/x2js" "from": "github:abdolence/x2js"
}, },
"xml-formatter": { "xml-formatter": {
"version": "2.4.0", "version": "2.4.1",
"resolved": "https://registry.npmjs.org/xml-formatter/-/xml-formatter-2.4.0.tgz", "resolved": "https://registry.npmjs.org/xml-formatter/-/xml-formatter-2.4.1.tgz",
"integrity": "sha512-xTQ2IfbkCQKn0DGN5SD5KUgTgVohWiolyOXTLUHKJczIuSeGonN0BPduB9VQR5HOEuT1KOHQsOHSmTpU76zpUA==", "integrity": "sha512-UFnFRNum4BxicU9U4DPhIlHAQqHtT/vTdCvC6fiD78xlpug8YLgawW3MHmT1+eCAM7YomvMGZziiMz9AnExZgQ==",
"requires": { "requires": {
"xml-parser-xo": "^3.1.1" "xml-parser-xo": "^3.1.2"
} }
}, },
"xml-parser-xo": { "xml-parser-xo": {
"version": "3.1.1", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/xml-parser-xo/-/xml-parser-xo-3.1.1.tgz", "resolved": "https://registry.npmjs.org/xml-parser-xo/-/xml-parser-xo-3.1.2.tgz",
"integrity": "sha512-gq1nDlJxjKQpPPZUhLbJ52pghtlB4Rz6LAQULm3SF6xzOYVnUloBglNhJR9vtZB3vIxMN/R3nZTf3qmun+6GCg==" "integrity": "sha512-Qyttmiy305unyg1ONpArT4FPDL3J+ohXWpMI1ecopClGMw53lCRHJ4FV/fVYHFU6qfEzMV0frqSlNaLo2dw15Q=="
}, },
"xtend": { "xtend": {
"version": "4.0.2", "version": "4.0.2",
......
{ {
"name": "c-tool", "name": "c-tool",
"version": "1.7.9", "version": "1.7.10",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve --port 8081", "serve": "vue-cli-service serve --port 8081",
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
"vue-codemirror": "^4.0.6", "vue-codemirror": "^4.0.6",
"vue-router": "^3.5.2", "vue-router": "^3.5.2",
"x2js": "github:abdolence/x2js", "x2js": "github:abdolence/x2js",
"xml-formatter": "^2.4.0" "xml-formatter": "^2.4.1"
}, },
"devDependencies": { "devDependencies": {
"@vue/cli-plugin-babel": "^3.12.1", "@vue/cli-plugin-babel": "^3.12.1",
......
let windowId = null; let windowId = null;
// 打开独立窗口 // 打开独立窗口
const panel = { const panel = {
create() { create() {
browser.windows.create({ browser.windows.create({
...@@ -46,6 +47,6 @@ browser.commands.onCommand.addListener((command) => { ...@@ -46,6 +47,6 @@ browser.commands.onCommand.addListener((command) => {
}) })
// 窗口关闭事件 // 窗口关闭事件
browser.windows.onRemoved.addListener((id) => { chrome.windows.onRemoved.addListener((id) => {
panel.onRemoved(id); panel.onRemoved(id);
}) })
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
"version": "##version##", "version": "##version##",
"author": "wo@baiy.org", "author": "wo@baiy.org",
"homepage_url": "https://github.com/baiy/Ctool", "homepage_url": "https://github.com/baiy/Ctool",
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"manifest_version": 2, "manifest_version": 2,
"browser_action": { "browser_action": {
"default_icon": "img/icon_chrome.png", "default_icon": "img/icon_chrome.png",
......
import {v4 as uuidV4} from 'uuid'; import {v4 as uuidV4} from 'uuid';
import {openUrl as chromiumOpenUrl} from './adapter/chromium/helper'; import {openUrl as chromiumOpenUrl} from './adapter/chromium/helper';
import {openUrl as utoolsOpenUrl} from './adapter/utools/helper'; import {openUrl as utoolsOpenUrl} from './adapter/utools/helper';
import {openUrl as firefoxOpenUrl} from './adapter/firefox/helper';
export const env = (key) => { export const env = (key) => {
return process['ctool'][key] ? process['ctool'][key] : ""; return process['ctool'][key] ? process['ctool'][key] : "";
...@@ -8,6 +9,7 @@ export const env = (key) => { ...@@ -8,6 +9,7 @@ export const env = (key) => {
export const isChrome = !!env('isChrome') export const isChrome = !!env('isChrome')
export const isEdge = !!env('isEdge') export const isEdge = !!env('isEdge')
export const isFirefox = !!env('isFirefox')
export const isChromium = !!env('isChromium') export const isChromium = !!env('isChromium')
export const isWeb = !!env('isWeb') export const isWeb = !!env('isWeb')
export const isUtools = !!env('isUtools') export const isUtools = !!env('isUtools')
...@@ -23,6 +25,9 @@ export const openUrl = (url) => { ...@@ -23,6 +25,9 @@ export const openUrl = (url) => {
if (isUtools) { if (isUtools) {
return utoolsOpenUrl(url) return utoolsOpenUrl(url)
} }
if (isFirefox) {
return firefoxOpenUrl(url)
}
return window.open(url); return window.open(url);
}; };
......
/* 黑暗模式简单实现 */ /* 黑暗模式简单实现 */
html {
background-color: #fff;
}
/* 强制黑暗模 */ /* 强制黑暗模 */
html[theme-mode='dark'] { html[theme-mode='dark'] {
......
...@@ -3,10 +3,11 @@ const _ = require('lodash'); ...@@ -3,10 +3,11 @@ const _ = require('lodash');
const fs = require('fs'); const fs = require('fs');
// 运行平台适配 // 运行平台适配
let platform = process.env.hasOwnProperty('npm_config_adapter') ? process.env.npm_config_adapter : ""; let platform = process.env.hasOwnProperty('npm_config_adapter') ? process.env.npm_config_adapter : "";
platform = ["chrome", 'utools', 'edge'].includes(platform) ? platform : "web" platform = ["chrome", 'utools', 'edge', 'firefox'].includes(platform) ? platform : "web"
const IS_CHROME = "chrome" === platform const IS_CHROME = "chrome" === platform
const IS_EDGE = "edge" === platform const IS_EDGE = "edge" === platform
const IS_FIREFOX = "firefox" === platform
const IS_UTOOLS = "utools" === platform const IS_UTOOLS = "utools" === platform
const IS_CHROMIUM = ['chrome', 'edge'].includes(platform) const IS_CHROMIUM = ['chrome', 'edge'].includes(platform)
const IS_WEB = "web" === platform const IS_WEB = "web" === platform
...@@ -51,10 +52,28 @@ const edgeConfigWrite = () => { ...@@ -51,10 +52,28 @@ const edgeConfigWrite = () => {
const chromiumConfigWrite = () => { const chromiumConfigWrite = () => {
// 移除环境配置文件 // 移除环境配置文件
removeFile(path.join(__dirname, '../../public/manifest.json')); removeFile(path.join(__dirname, '../../public/manifest.json'));
let backgroundPath = path.join(__dirname, '../../public/background.js'); removeFile(path.join(__dirname, '../../public/background.js'));
removeFile(backgroundPath);
if (IS_CHROMIUM) { if (IS_CHROMIUM) {
fs.copyFileSync(path.join(__dirname, "../adapter/chromium/background.js"), backgroundPath); fs.copyFileSync(
path.join(__dirname, "../adapter/chromium/background.js"),
path.join(__dirname, '../../public/background.js')
);
}
}
const firefoxConfigWrite = () => {
// 移除环境配置文件
removeFile(path.join(__dirname, '../../public/manifest.json'));
removeFile(path.join(__dirname, '../../public/background.js'));
if (IS_FIREFOX) {
fs.copyFileSync(
path.join(__dirname, "../adapter/firefox/background.js"),
path.join(__dirname, '../../public/background.js')
);
fs.writeFileSync(
path.join(__dirname, '../../public/manifest.json'),
fs.readFileSync(path.join(__dirname, "../adapter/firefox/manifest.json")).toString().replace(/##version##/g, process.env.npm_package_version)
);
} }
} }
...@@ -141,6 +160,7 @@ module.exports = { ...@@ -141,6 +160,7 @@ module.exports = {
platform: platform, platform: platform,
isChrome: IS_CHROME, isChrome: IS_CHROME,
isChromium: IS_CHROMIUM, isChromium: IS_CHROMIUM,
isFirefox: IS_FIREFOX,
isEdge: IS_EDGE, isEdge: IS_EDGE,
isWeb: IS_WEB, isWeb: IS_WEB,
isUtools: IS_UTOOLS, isUtools: IS_UTOOLS,
...@@ -148,6 +168,7 @@ module.exports = { ...@@ -148,6 +168,7 @@ module.exports = {
chromiumConfigWrite(); chromiumConfigWrite();
chromeConfigWrite(); chromeConfigWrite();
edgeConfigWrite(); edgeConfigWrite();
firefoxConfigWrite();
utoolsConfigWrite(); utoolsConfigWrite();
} }
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div> <div>
<CellGroup @on-click="open"> <CellGroup @on-click="open">
<Cell title="常用工具设置" name="setting"/> <Cell title="常用工具设置" name="setting"/>
<Cell v-if="is_chromium" title="快捷键设置" name="shortcuts"/> <Cell v-if="is_chromium || is_firefox" title="快捷键设置" name="shortcuts"/>
<Cell title="外观显示"> <Cell title="外观显示">
<Select v-model="display_mode" slot="extra" transfer> <Select v-model="display_mode" slot="extra" transfer>
<Option v-for="item in display_mode_list" :value="item.v" :key="item.v">{{ item.n }}</Option> <Option v-for="item in display_mode_list" :value="item.v" :key="item.v">{{ item.n }}</Option>
...@@ -29,9 +29,8 @@ ...@@ -29,9 +29,8 @@
</template> </template>
<script> <script>
import {isChromium, isUtools, openUrl} from '../../helper' import {isChromium, isFirefox, isUtools, openUrl, setDisplayMode} from '../../helper'
import setting from '../../tool/setting' import setting from '../../tool/setting'
import {setDisplayMode} from '../../helper'
import settingBlock from './setting' import settingBlock from './setting'
export default { export default {
...@@ -47,6 +46,7 @@ export default { ...@@ -47,6 +46,7 @@ export default {
auto_read_copy_filter: false, auto_read_copy_filter: false,
is_chromium: isChromium, is_chromium: isChromium,
is_utools: isUtools, is_utools: isUtools,
is_firefox: isFirefox,
display_mode_list: [ display_mode_list: [
{n: "浅色", v: "light"}, {n: "浅色", v: "light"},
{n: "深色", v: "dark"}, {n: "深色", v: "dark"},
...@@ -54,8 +54,8 @@ export default { ...@@ -54,8 +54,8 @@ export default {
] ]
} }
}, },
watch:{ watch: {
display_mode(value){ display_mode(value) {
setDisplayMode(value) setDisplayMode(value)
} }
}, },
...@@ -75,6 +75,22 @@ export default { ...@@ -75,6 +75,22 @@ export default {
open(name) { open(name) {
switch (name) { switch (name) {
case 'shortcuts': case 'shortcuts':
if (this.is_firefox) {
return this.$Notice.success({
title: '请手动设置快捷键',
render: h => {
return h('span', [
'请打开附加组件管理器(about:addons),点击“管理扩展程序”右侧的设置按钮,选择“管理扩展快捷键”来修改这些快捷键。',
h('a', {
attrs: {
href: 'https://jingyan.baidu.com/article/3ea51489f1d0a713e61bbaff.html',
target: '_blank'
}
}, '操作方法'),
])
}
});
}
openUrl('chrome://extensions/shortcuts') openUrl('chrome://extensions/shortcuts')
break break
case 'setting': case 'setting':
......
...@@ -16,6 +16,7 @@ const config = { ...@@ -16,6 +16,7 @@ const config = {
updateTime: Date.parse((new Date()).toString()) / 1000, updateTime: Date.parse((new Date()).toString()) / 1000,
platform: adapter.platform, platform: adapter.platform,
isChrome: adapter.isChrome, isChrome: adapter.isChrome,
isFirefox: adapter.isFirefox,
isEdge: adapter.isEdge, isEdge: adapter.isEdge,
isChromium: adapter.isChromium, isChromium: adapter.isChromium,
isWeb: adapter.isWeb, isWeb: adapter.isWeb,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册