Browse Source

记住 dock icon 的隐藏/显示状态。

oldj 10 years ago
parent
commit
f6ae1e19e8

+ 1 - 0
.gitignore

@@ -16,3 +16,4 @@ src/configs.json
 
 node_modules
 UserInterfaceState.xcuserstate
+xcdebugger

+ 1 - 0
app/SH3/MacGap/AppDelegate.m

@@ -14,6 +14,7 @@
 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
 {
     // Insert code here to initialize your application
+    // [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
 
 }
 

+ 1 - 1
app/SH3/MacGap/SwitchHosts!-Info.plist

@@ -21,7 +21,7 @@
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
-	<string>2712</string>
+	<string>2729</string>
 	<key>LSApplicationCategoryType</key>
 	<string>public.app-category.developer-tools</string>
 	<key>LSMinimumSystemVersion</key>

BIN
app/SH3/SwitchHosts!.xcodeproj/project.xcworkspace/xcuserdata/wu.xcuserdatad/UserInterfaceState.xcuserstate


File diff suppressed because it is too large
+ 0 - 0
app/SH3/public/js/main.js


+ 31 - 0
app/src/agent.js

@@ -10,7 +10,9 @@
 var sys_host_path = '/etc/hosts';
 var work_path = MacGap.homePath + '/.SwitchHosts';
 var data_path = work_path + '/data.json';
+var preference_path = work_path + '/preference.json';
 var is_work_path_made;
+var _preference;
 
 //function copyObj(o) {
 //    var k;
@@ -161,6 +163,32 @@ function setData(data) {
     }
 }
 
+function getAllPreferences() {
+    if (!_preference) {
+        var c = MacGap.File.read(preference_path, 'string');
+        try {
+            c = JSON.parse(c);
+        } catch (e) {
+            c = {};
+        }
+        _preference = c;
+    }
+
+    return _preference;
+}
+
+function getPreference(key) {
+    var p = getAllPreferences();
+    return p[key];
+}
+
+function setPreference(key, value) {
+    var p = getAllPreferences();
+    p[key] = value;
+
+    MacGap.File.write(preference_path, JSON.stringify(p), 'string');
+}
+
 function getURL(url, data, success, fail) {
     if (!data._r) {
         data._r = Math.random();
@@ -202,6 +230,9 @@ module.exports = {
     setSysHosts: setSysHosts,
     getData: getData,
     setData: setData,
+    getAllPreferences: getAllPreferences,
+    getPreference: getPreference,
+    setPreference: setPreference,
     getURL: getURL,
     openURL: openURL,
     activate: activate,

+ 13 - 5
app/src/menu.js

@@ -6,18 +6,21 @@
 'use strict';
 
 var config = require('./config');
+var agent = require('./agent');
 var lang = require('./lang').getLang(navigator.language);
 
-var is_dock_icon_show = true;
+var key_name = 'is_dock_icon_hidden';
+var is_dock_icon_hidden = agent.getPreference(key_name);
 
 function toggleDockIcon() {
-    if (is_dock_icon_show) {
-        MacGap.Dock.hideIcon();
-    } else {
+    if (is_dock_icon_hidden) {
         MacGap.Dock.showIcon();
         MacGap.activate();
+    } else {
+        MacGap.Dock.hideIcon();
     }
-    is_dock_icon_show = !is_dock_icon_show;
+    is_dock_icon_hidden = !is_dock_icon_hidden;
+    agent.setPreference(key_name, is_dock_icon_hidden);
 }
 
 function initTray(app) {
@@ -105,6 +108,11 @@ function initMenu(app) {
         app.add();
     };
 
+    if (is_dock_icon_hidden) {
+        MacGap.Dock.hideIcon();
+    } else {
+        MacGap.Dock.showIcon();
+    }
 }
 
 exports.initMenu = initMenu;

Some files were not shown because too many files changed in this diff