Skip to content

Commit

Permalink
Update workflow version
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 21, 2024
1 parent 8c2319b commit 8a0f7e7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
3 changes: 2 additions & 1 deletion surge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

1. brew install node
2. 开启Surge API支持
3. 注意如果是连接的本地Surge 127.0.0.1服务,需要skip-proxy中配置127.0.0.1

## 如何开启Surge API支持

Expand All @@ -46,7 +47,7 @@ Surge Mac 4.0.0、Surge iOS 4.4.0开始提供HTTP API, 即该版本之前的均



[![](https://img.shields.io/badge/version-v1.26-green?style=for-the-badge)](https://img.shields.io/badge/version-v1.26-green?style=for-the-badge)
[![](https://img.shields.io/badge/version-v1.27-green?style=for-the-badge)](https://img.shields.io/badge/version-v1.27-green?style=for-the-badge)
[![](https://img.shields.io/badge/download-click-blue?style=for-the-badge)](https://github.com/alanhe421/alfred-workflows/raw/master/surge/Surge.alfredworkflow)


Expand Down
6 changes: 4 additions & 2 deletions surge/src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1327,9 +1327,10 @@
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<integer>0</integer>
<key>script</key>
<string>node ./toggle-rule.js '{query}'
echo -n '{query}'</string>
<key>scriptargtype</key>
<integer>0</integer>
Expand Down Expand Up @@ -1437,6 +1438,7 @@ echo -n '{query}'</string>
1. brew install node
2. 开启Surge API支持
3. 注意如果是连接的本地Surge 127.0.0.1服务,需要skip-proxy中配置127.0.0.1
## 如何开启Surge API支持
Expand Down Expand Up @@ -1755,7 +1757,7 @@ Surge Mac 4.0.0、Surge iOS 4.4.0开始提供HTTP API, 即该版本之前的均
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.26</string>
<string>1.27</string>
<key>webaddress</key>
<string>https://github.com/alanhg/alfred-workflows/tree/master/surge</string>
</dict>
Expand Down
18 changes: 11 additions & 7 deletions surge/src/rules.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const [, , query] = process.argv;
const {utils, Workflow,} = require('@stacker/alfred-utils');
const {escapeRegexMeta, readConfFromLocal} = require("./utils");

const { utils, Workflow, } = require('@stacker/alfred-utils');
const { escapeRegexMeta, readConfFromLocal } = require("./utils");
const instance = require('./axios').createHttpClient(process.env.HTTP_API);
const wf = new Workflow();

Expand All @@ -19,15 +18,20 @@ async function main() {
const profileName = await instance
.get('/v1/profiles/current')
.then((res) => res.data.name);
let {content} = await readConfFromLocal(profileName + '.conf');
let { content } = await readConfFromLocal(profileName + '.conf');
cnfContent = content;
}
rules.forEach((item) => {
const isSelected = isSelectedRule(item, cnfContent);
wf.addWorkflowItem({
item: {
uid: item,
title: item,
subtitle: (isSelectedRule(item, cnfContent) ? utils.emoji.checked : '') + item,
subtitle: (isSelected ? utils.emoji.checked : '') + item,
arg: item,
variables: {
isSelected,
},
text: {
copy: item, largetype: item
}
Expand All @@ -36,8 +40,8 @@ async function main() {
});
wf.filterWorkflowItemsBy(query, ['title', 'subtitle']);
wf.run({
variables:{
keyword:query
variables: {
keyword: query
}
});
}
Expand Down
17 changes: 10 additions & 7 deletions surge/src/toggle-rule.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
const [, , rule] = process.argv;
const {writeFileSync} = require('fs');
const { writeFileSync } = require('fs');
const path = require('path');
const {escapeRegexMeta, readConfFromLocal} = require("./utils");
const { escapeRegexMeta, readConfFromLocal } = require("./utils");

const instance = require('./axios').createHttpClient(process.env.HTTP_API);


/**
*
*/
async function main() {
const isSelected = process.env.isSelected == '1';
const profileName = await instance
.get('/v1/profiles/current')
.then((res) => res.data.name);
let {content, name} = await readConfFromLocal(profileName + '.conf')
content = content.replace(new RegExp(`#? *${escapeRegexMeta(rule)}([^\\n]*)`), (match, p1) => {
return match.startsWith('#') ? rule + p1 : '# ' + rule + p1;
});
writeFileSync(path.join(process.env.CONF_FILE_LOCATION, name), content, {encoding: 'utf8'});
let { content, name } = await readConfFromLocal(`${profileName}.conf`);
content = content.replace(new RegExp(`${isSelected ? '' : '#\\s*'}${escapeRegexMeta(rule)}`), `${isSelected ? '# ' : ''}${rule}`);
writeFileSync(path.join(process.env.CONF_FILE_LOCATION, name), content, { encoding: 'utf8' });
}

main();
10 changes: 5 additions & 5 deletions surge/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("path");
const {readFileSync} = require("fs");
const { readFileSync } = require("fs");

function escapeRegexMeta(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
Expand All @@ -11,14 +11,14 @@ function escapeRegexMeta(str) {
* @returns {Promise<string>}
*/
async function readConfFromLocal(profileName) {
const file = path.join(process.env.CONF_FILE_LOCATION, profileName);
let profileCnt = readFileSync(file, {encoding: 'utf8'});
let profileCnt = readFileSync(path.join(process.env.CONF_FILE_LOCATION, profileName), { encoding: 'utf8' });
let detachedRuleProfileName = profileCnt.match(/(?<=\[Rule]\n+#!include\s+).+/)?.[0];
if (detachedRuleProfileName) {
return readConfFromLocal(detachedRuleProfileName)
return readConfFromLocal(detachedRuleProfileName);
}
return {
name: profileName, content: profileCnt
name: profileName,
content: profileCnt
};
}

Expand Down

0 comments on commit 8a0f7e7

Please sign in to comment.