deepin優雅地使用堅果雲攻略


1. 前言

堅果雲是一款多平台同步軟件,能夠實時備份同步工作和學習中很多重要的腳本,配置等文件。

本篇主要介紹一些在deepin操作系統(最新版本deepin V20.2.3)上使用堅果雲的經驗,供有同樣需求的朋友參考。

注:博客中涉及到的部分代碼的修改在很久之前完成,因為能正常實現個人需求,就沒有復核,能用就行。以后有興致再優化。

2. deepin安裝堅果雲

deepin安裝堅果雲很簡單,只需三步即可完成。

建議按照以下三個步驟安裝,不要從商店安裝堅果雲

1.瀏覽器訪問堅果雲官方網站下載地址:https://www.jianguoyun.com/s/downloads,下載Linux版本的堅果雲deb包

當前Linux版本的堅果雲安裝包最新版本5.1.2

2.deepin打開終端,執行:sudo apt install libnotify-dev安裝相關依賴

3.找到下載的堅果雲deb包,雙擊安裝,輸入密碼,即可完成堅果雲的安裝

3. 配置堅果雲的同步目錄

3.1 重新配置默認放置目錄

堅果雲默認在當前用戶的home目錄下創建一個NutStore Files的目錄用來放置同步的內容。

但是對於deepin文件管理器來說,在home目錄下顯示一個NutStore Files有些怪怪的。相比於堅果雲,安裝的微信就很老實,乖乖地躺在文檔目錄下。

所以對於如何修改堅果雲的放置目錄,放文件目錄看起來盡然有續,歸檔自然?

答案是:在首次啟動和登陸堅果雲時配置同步目錄。

意思就是:你要選擇本地的哪個目錄,來作為你存放在堅果雲雲端文件的目錄。

所以先提前創建好一個目錄:

  • 方式1,使用文件管理器,在“文檔“下面創建”堅果雲“
  • 方式2,使用終端,執行:mkdir ”~/Documents/NutStore Files“

上面兩個方式均可,目的只是重新配置堅果雲默放置的目錄。目錄到底是中文還是英文,就看個人喜好了。

然后點擊登陸堅果雲,在以下這個界面修改配置即可。

3.2 徹底解決在home下創建NutStore Files問題

上面的步驟能夠修改堅果雲默認的放置目錄,但是不能夠解決每次登陸堅果雲以后,它在用戶的home目錄下創建NutStore Files目錄的問題。

以下過程就是通過修改堅果雲核心工作腳本,來徹底解決這個問題。

終端執行:vim ~/.nutstore/dist/bin/nutstore-pydaemon.py,修改內容如下:

第一處修改:

from indicator_menus import is_java_client_running, open_window
from resource_manage import PicturesManage
from log_utils import get_logger
from network_util import execute_cmd, Command

# 以下這幾行是要添加的函數,函數的目的就是刪除用戶home目錄下的NutStore Files目錄
def remove_home_file():
    file = "/home/替換為你的帳號/Nutstore Files"
    if os.path.exists(file):
        shutil.rmtree(file)

def get_dist_dir():
    """Get the nutstore distribution install directory by the path to the python script"""
    path = os.path.dirname(sys.argv[0])
    abs_path = os.path.abspath(path)
    if os.path.basename(abs_path) != 'bin':

第二處修改:

class JavaAppWatchDog(threading.Thread):
    def __init__(self):
        remove_home_file()  #這里插入上面的函數
        # invoke the super class's constructor, if it has
        fun = getattr(threading.Thread, "__init__", lambda x: None)
        fun(self)
        self.daemon = True
        # It should only be set when the java app is restarted to migrate to another nutstore home
        self.__new_nutstore_home = None
        # It should only be set when the java app is restarted by adding more ignore path
        self.__ignore_path_list = None
        # How many times the java app has been restarted
        self.__restart_num = 0
        # It should only be set when the java app is restarted by switch account
        self.__switch_account = None
        # flag to indicate whether the watch dog thread should quit
        self.__exit = False
        # debug settings
        self.__cli_args = ' '.join(sys.argv[1:])
        self.__lock = threading.RLock()

    def set_new_nutstore_home(self, new_home_dir):
        remove_home_file() #這里插入上面的函數
        self.__lock.acquire()
        try:
            self.__new_nutstore_home = new_home_dir
        finally:
            self.__lock.release()

    def get_new_nutstore_home(self):
        remove_home_file() #這里插入上面的函數
        self.__lock.acquire()
        try:
            return self.__new_nutstore_home
        finally:

第三處修改:

def main_loop():
    watchDog = JavaAppWatchDog()
    watchDog.start()

    listen = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    listen.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    listen.bind(('localhost', LOCAL_PORT))

    while True:
        listen.listen(16)
        (conn, addr) = listen.accept()

        file = None
        try:
            # NS-4828 set mode='rw' cause python3 can't write without 'w'
            file = conn.makefile(mode='rw')
            remove_home_file() # 這里摻入上面的函數
            lines = []
            while True:
                line = file.readline().rstrip('\r\n')
                lines.append(line)
                if line == 'done' or line == '':
                    break

第四處修改:

if __name__ == '__main__':
    signal.signal(signal.SIGINT, sigint_handler)
    if is_java_client_running():
        remove_home_file() #這里插入上面的函數
        has_file_by_lightapp, path = parse_file_to_open_in_lightapp()
        if has_file_by_lightapp:
            if path: open_file_in_lightapp(path)
            else: open_wizard_in_lightapp()
        else:
        open_window()

上面修改完成后,保存退出即可。

再也不會應為啟動堅果雲,home目錄下出現NutStore Fiels目錄了,它會被自動刪除。

4. 剪裁堅果雲

4.1 卸載堅果雲輕應用

堅果雲的安裝,會附帶安裝一些輕應用,使用時,一些默認格式的文件會從輕應用打開。

如果不喜歡使用堅果雲輕應用,可以在deepin啟動器,找到“堅果雲輕應用”快捷方式,右鍵卸載即可

4.2 目錄瘦身

雖然能夠卸載輕應用,但是實際上輕應用的可執行文件等,還是存在本地的。

一個快捷的驗證就是:

終端執行:du -sh ~/.nutstore/,會發現該目錄很大。而造成這么大的原因,就是~/.nutstore/apps這個目錄

如果只是單純刪除這個目錄,堅果雲會自動修復(即自動下載生成這個目錄),保證其功能的可用性。

為了解決這個問題,就需要修改堅果雲的核心工作腳本了:~/.nutstore/dist/bin/nutstore-pydaemon.py

解決方案,vim 編輯~/.nutstore/dist/bin/nutstore-pydaemon.py,修改內容如下,保存退出即可。

if __name__ == '__main__':
    signal.signal(signal.SIGINT, sigint_handler)
    if is_java_client_running():
        remove_home_file()
        #has_file_by_lightapp, path = parse_file_to_open_in_lightapp()
        #if has_file_by_lightapp:
            #if path: open_file_in_lightapp(path)
            #else: open_wizard_in_lightapp()
        #else:
        open_window() #注意要調整這一行的縮進,保持與remove_home_file()同級縮進
    ....#其他代碼

然后就可以痛快地刪除~/.nutstore/apps/lightapp/1.0.1/下的內容了。
千萬注意:需要保留1.0.1的版本目錄,否則會自動創建

5. 修復安裝堅果雲后產生的問題

場景1:安裝了堅果雲以后,創建的Markdown文件,即以.md為文件格式顯示為白色,mime圖標丟失

解決方式:

終端執行:rm -rf ~/.local/share/mime。即刪除該目錄即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM