0%

mac 下新版 GitKraken 不能打开私有仓库解决方案

本文只是说 mac 下的解决方案,其他系统可以依样画葫芦,毕竟用 electron 就是为了它的跨平台特性,各个平台代码基本上一样的。

觉得太长而且是 mac 的话,可以直接使用文末的脚本。

mac 下的破解方法

1
curl https://raw.githubusercontent.com/eleven26/blog/master/scripts/gitkraken.py | python

今天打开 GitKraken 的时候突然发现,提示我 The free version of GitKraken does not support opening private or self-hosted repositories.

GitKraken 是一个用 electron 开发的客户端应用,正好之前用 electron 写过一点东西,去看看源码有没有什么解决方法。

源码位于:/Applications/GitKraken.app/Contents/Resources

1
ls /Applications/GitKraken.app/Contents/Resources

我们会看到一个 app.asar 文件,这个其实就是应用的核心所在,我们可以看作类似与 zip 之类的东西,它把所有源码打包到了一个文件中,我们解压开来看看源码:

想了解 asar 是什么的可以看 https://www.electronjs.org/docs/tutorial/application-packaging

1
2
cd /Applications/GitKraken.app/Contents/Resources
asar e app.asar unpacked # 解压 app.asar 到 unpacked 文件夹中

asar 需要通过 npm 安装:

1
npm install -g asar

我们可以直接用 WebStorm 之类的 IDE 打开这个文件夹,我们可以看到一个 initializeGlobals.js 文件,在里面发现一行对于开发人员来说比较敏感的代码:

1
process.env.NODE_ENV = loadSettings.mode === 'development' ? 'development' : 'production';

一般开发中,我们常常定义 env 环境变量,然后在开发环境我们通常会少一些限制,想到此,可能修改为 development 模式会可以解决现在遇到的问题,然后找到定义的地方,在另外一个文件中:

clientType.js

1
module.exports = 'production';

我们把这一行修改为 module.exports = 'development'; 看看。

修改完之后,重新打包。

  1. 先把旧的文件备份:
1
cp /Applications/GitKraken.app/Contents/Resources/app.asar /Applications/GitKraken.app/Contents/Resources/app.asar.bak
  1. 打包之后,我们就可以将修改后的代码重新打包
1
2
cd /Applications/GitKraken.app/Contents/Resources
rm app.asar && asar pack unpacked app.asar

这里的 unpacked 就是刚刚上面解压出来的文件夹。

  1. 重启 GitKraken

重启之后,弹窗没有了,各项功能正常使用。应该没什么问题了,就先用着了。

py脚本

觉得上面太长不想看的可以执行下面的脚本:

保存为 gitkraken.py,然后运行 chmod +x gitkraken.py && ./gitkraken.py 即可破解。

下面的代码 Gitkraken 7.4.0 可用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

d = '/Applications/GitKraken.app/Contents/Resources'
if not os.path.isdir(d):
print("GitKraken 尚未安装")
exit(-1)

print("切换目录到 %s..." % d)
os.chdir(d)
if os.path.isdir(d + "/unpacked"):
os.system("rm -rf " + d + "/unpacked")

# 解压
print("解压 app.asar...")
os.system("cp app.asar app.asar.bak")
os.system("asar e app.asar unpacked")

# 替换文件
print("替换文件...")
f = open(d + "/unpacked/src/main/clientType.js", mode='wb')
content = """// This file is auto-generated by the set-client-type.js script
module.exports = 'development';
"""
f.write(bytes(content))
f.close()

f = open(d + "/unpacked/src/main/static/clientType.js", mode='wb')
content = """// This file is auto-generated by the set-client-type.js script
module.exports = 'development';
"""
f.write(bytes(content))
f.close()

f = open(d + "/unpacked/src/main/static/mode.js", mode='wb')
content = """// This file is auto-generated by the set-run-mode.js script
module.exports = 'development';
"""
f.write(bytes(content))
f.close()

# 重新打包
print("重新打包...")
os.system("rm app.asar && asar pack unpacked app.asar")

# 清理操作
os.system("rm -rf unpacked")

print("破解成功!")

# 打开 Gitkraken
script = """tell application "GitKraken"
activate
# set frontmost to true

try
set miniaturized of windows to false -- most apps
end try
end tell"""
os.system("osascript -e '%s'" % script)



参考链接:

  1. application-packaging